All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2 v3] commit.rc: Add helper for math operation using bc
@ 2011-09-23 14:15 Lukas Czerner
  2011-09-23 14:15 ` [PATCH 2/2] Add test 257: Check proper FITRIM argument handling Lukas Czerner
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Lukas Czerner @ 2011-09-23 14:15 UTC (permalink / raw)
  To: xfs; +Cc: Lukas Czerner, aelder

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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-09-26 21:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-23 14:15 [PATCH 1/2 v3] commit.rc: Add helper for math operation using bc Lukas Czerner
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

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.