bcalc

cli bitcoin unit calculator
git clone git://jb55.com/bcalc
Log | Files | Refs | README | LICENSE

commit b86522cd77660d653d3c2f1aec5b5b2f2439bfcb
parent 59bc9ca26904e241b58af988d4114f3de10b51e6
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 19 Dec 2017 14:17:49 -0800

fix: chain multiply

Diffstat:
Mparser.y | 8++++----
Mtest/run | 2+-
Mtest/tests.csv | 1+
3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/parser.y b/parser.y @@ -50,12 +50,12 @@ number: T_INT { num_init_int(&$$, $1, UNIT_NONE); } | T_FLOAT { num_init_float(&$$, $1, UNIT_NONE); } ; -mul_expr: number T_MULTIPLY unit_number { num_mul(&$$, &$3, &$1); } - | unit_number T_MULTIPLY number { num_mul(&$$, &$1, &$3); } +mul_expr: number T_MULTIPLY expr { num_mul(&$$, &$3, &$1); } + | expr T_MULTIPLY number { num_mul(&$$, &$1, &$3); } ; -div_expr: number T_DIVIDE unit_number { num_div(&$$, &$3, &$1); } - | unit_number T_DIVIDE number { num_div(&$$, &$1, &$3); } +div_expr: number T_DIVIDE expr { num_div(&$$, &$3, &$1); } + | expr T_DIVIDE number { num_div(&$$, &$1, &$3); } ; expr: unit_number diff --git a/test/run b/test/run @@ -8,7 +8,7 @@ printf "1..%d\n" "$c" while IFS=, read -r description args input expected do - output=$(../bcalc $args <<<"$input") + output=$(../bcalc $args <<<"$input" 2>&1) if [ "$description" == "" ] || [ "$output" != "$expected" ]; then printf "not ok %d - %s\n" "$n" "$description" printf "#\n# got '%s', expected '%s'\n#\n" "$output" "$expected" diff --git a/test/tests.csv b/test/tests.csv @@ -2,3 +2,4 @@ scalar division,--btc -p,1 BTC / 10,0.1 BTC scalar multiplication,--btc,10 * 1 BTC,10 multiply 1 BTC to the smallest unit,-pm,1 BTC * 0.00000000001,1 msat lots of msats,-B,2 msat * 100000000000,2 +chained multiply,-B,2100 btc * 0.1 * 0.1,21