All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: xfs@oss.sgi.com
Cc: Lukas Czerner <lczerner@redhat.com>, aelder@sgi.com
Subject: [PATCH 1/2 v3] commit.rc: Add helper for math operation using bc
Date: Fri, 23 Sep 2011 16:15:10 +0200	[thread overview]
Message-ID: <1316787311-23428-1-git-send-email-lczerner@redhat.com> (raw)

Sometimes using bash $(()) math might not be enough due to some
limitation (big numbers), so add helper using 'bc' program. For
now the results are only in perfect numbers (as in bash) since this is
all I need for now.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
v3: Nothing has changed

 common.rc |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/common.rc b/common.rc
index 35f782b..b0e0c6a 100644
--- a/common.rc
+++ b/common.rc
@@ -20,6 +20,20 @@
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
+BC=$(which bc 2> /dev/null) || BC=
+
+_math() {
+	if [ $# -le 0 ]; then
+		return
+	fi
+	if [ "$BC" ]; then
+		result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
+	else
+		result=$(($@))
+	fi
+	echo "$result"
+}
+
 dd()
 {
    if [ "$HOSTOS" == "Linux" ]
-- 
1.7.4.4

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2011-09-23 14:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-23 14:15 Lukas Czerner [this message]
2011-09-23 14:15 ` [PATCH 2/2] Add test 257: Check proper FITRIM argument handling Lukas Czerner
2011-09-23 15:00   ` Alex Elder
2011-09-23 16:06     ` Lukas Czerner
2011-09-23 23:04   ` Michael Monnerie
2011-09-26  6:15     ` Lukas Czerner
2011-09-26  7:14   ` [PATCH] " Lukas Czerner
2011-09-26 11:42     ` Lukas Czerner
2011-09-26 12:47     ` Alex Elder
2011-09-26 13:52       ` Lukas Czerner
2011-09-26 15:47         ` Alex Elder
2011-09-23 15:00 ` [PATCH 1/2 v3] commit.rc: Add helper for math operation using bc Alex Elder
2011-09-26 18:45 ` [PATCH v4] " Lukas Czerner
2011-09-26 21:32   ` Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316787311-23428-1-git-send-email-lczerner@redhat.com \
    --to=lczerner@redhat.com \
    --cc=aelder@sgi.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.