bcalc

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

commit 74282472f6fe1ae53971d364c2dfac82d8b2695b
parent f86cdec91e099be1d3ebd305699888b99446e171
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 16 Dec 2017 23:02:13 -0800

mul/div: not right now until I figure out how to do this

Diffstat:
Mnum.c | 25++++++++++++-------------
Mparser.y | 12++----------
2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/num.c b/num.c @@ -68,6 +68,18 @@ num_sub(struct num *dst, struct num *a, struct num *b) { dst->intval = num_to_msat(a) - num_to_msat(b); } +int64_t +unit_msat_multiple(enum unit format) { + switch (format) { + case UNIT_MSATOSHI: return MSATOSHI; + case UNIT_SATOSHI: return SATOSHI; + case UNIT_FINNEY: return FINNEY; + case UNIT_BITS: return BITS; + case UNIT_MBTC: return MBTC; + case UNIT_BTC: return BTC; + } +} + void num_mul(struct num *dst, struct num *a, struct num *b) { dst->type = TYPE_INT; @@ -91,19 +103,6 @@ num_assign(struct num *dst, struct num *a) { *dst = num; } -int64_t -unit_msat_multiple(enum unit format) { - switch (format) { - case UNIT_MSATOSHI: return MSATOSHI; - case UNIT_SATOSHI: return SATOSHI; - case UNIT_FINNEY: return FINNEY; - case UNIT_BITS: return BITS; - case UNIT_MBTC: return MBTC; - case UNIT_BTC: return BTC; - } -} - - static void trim_zeros (char *s, int n) { diff --git a/parser.y b/parser.y @@ -51,18 +51,10 @@ expr: T_INT T_UNIT { num_init(&$$); $$.unit = $2; num_assign(&$$, &$$); } - /* | T_INT { num_init(&$$); */ - /* $$.intval = $1; */ - /* $$.type = TYPE_INT; */ - /* } */ - /* | T_FLOAT { num_init(&$$); */ - /* $$.floatval = $1; */ - /* $$.type = TYPE_FLOAT; */ - /* } */ | expr T_PLUS expr { num_add(&$$, &$1, &$3); } | expr T_MINUS expr { num_sub(&$$, &$1, &$3); } - | expr T_MULTIPLY expr { num_mul(&$$, &$1, &$3); } - | expr T_DIVIDE expr { num_div(&$$, &$1, &$3); } + /* | expr T_MULTIPLY expr { num_mul(&$$, &$1, &$3); } */ + /* | expr T_DIVIDE expr { num_div(&$$, &$1, &$3); } */ | T_LEFT expr T_RIGHT { num_init(&$$); num_assign(&$$, &$2); } ;