bcalc

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

commit 584da45e235096bb7801db09a5e3182351f45f77
parent b9f1574c76ed31dfaf4a3faa4ea1cab0a4f6760f
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 23 Dec 2017 15:00:43 -0800

div: temp disable one division case

Not sure how to fix this yet...

Diffstat:
Mnum.c | 17++++++++++++++---
Mparser.y | 4++--
Mtest/tests.csv | 2++
3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/num.c b/num.c @@ -127,11 +127,22 @@ num_mul(struct num *dst, struct num *a, struct num *b) { void num_div(struct num *dst, struct num *a, struct num *b) { - assert(b->unit == UNIT_NONE); dst->type = TYPE_INT; dst->unit = UNIT_MSATOSHI; - dst->intval = num_to_msat(a) / (b->type == TYPE_FLOAT? b->floatval - : b->intval); + + if (b->unit == UNIT_NONE) { + dst->intval = num_to_msat(a) / (b->type == TYPE_FLOAT? b->floatval + : b->intval); + } else if (a->unit == UNIT_NONE) { + assert(!"not working yet"); + /* dst->type = TYPE_FLOAT; */ + /* dst->unit = b->unit; */ + /* double ad = a->type == TYPE_FLOAT? a->floatval : (double)a->intval; */ + /* int64_t bmsat = num_to_msat(b); */ + } + else { + assert(!"shouldnt happen"); + } } void diff --git a/parser.y b/parser.y @@ -54,8 +54,8 @@ mul_expr: number T_MULTIPLY expr { num_mul(&$$, &$3, &$1); } | expr T_MULTIPLY number { num_mul(&$$, &$1, &$3); } ; -div_expr: number T_DIVIDE expr { num_div(&$$, &$3, &$1); } - | expr T_DIVIDE number { num_div(&$$, &$1, &$3); } +div_expr: /* number T_DIVIDE expr { num_div(&$$, &$1, &$3); } */ + expr T_DIVIDE number { num_div(&$$, &$1, &$3); } ; expr: unit_number diff --git a/test/tests.csv b/test/tests.csv @@ -24,5 +24,7 @@ simple fiat test with bits,-p --price 15000 --bits,1 fiat,66.66666 bits 1 BTC is 10 usd,-p --price 10 --usd,1 btc,10 USD 1 BTC is 1000000 other,-p --price 1000000 --other,100 mbtc,100000 other 1 other @15k is 66.66666 bits,-p --price 15000 --bits,1 other,66.66666 bits +1 btc/2 should work,--btc,1 btc / 2,0.5 # failing +1/2 btc should work,--btc,1/2 btc,0.5 1 BTC is 15000 usd,-p --price 15000 --usd,1 btc,15000 USD