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. This commit also adds _require_math() helper which should be called by every test which uses _math() since it requires "bc" to be installed on the system. Signed-off-by: Lukas Czerner <lczerner@xxxxxxxxxx> --- v3: Nothing has changed v4: Add _require_math helper common.rc | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/common.rc b/common.rc index 35f782b..e948169 100644 --- a/common.rc +++ b/common.rc @@ -20,6 +20,26 @@ # Mountain View, CA 94043, USA, or: http://www.sgi.com #----------------------------------------------------------------------- +BC=$(which bc 2> /dev/null) || BC= + +_require_math() +{ + if [ -z "$BC" ]; then + _notrun "this test requires 'bc' tool for doing math operations" + fi +} + +_math() +{ + [ $# -le 0 ] && return + if [ "$BC" ]; then + result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null) + else + _notrun "this test requires 'bc' tool for doing math operations" + fi + echo "$result" +} + dd() { if [ "$HOSTOS" == "Linux" ] -- 1.7.4.4 _______________________________________________ xfs mailing list xfs@xxxxxxxxxxx http://oss.sgi.com/mailman/listinfo/xfs