commit aac0d8bb64e58c16fd5edc2d63bea9975e0e464b parent 14380b5587eac94aa58114177f93f330326a2376 Author: Ed van Bruggen <edvb@uw.edu> Date: Mon, 29 Oct 2018 00:26:01 -0700 Add basic scientific notation support for doubles Diffstat:
tisp.c | | | 15 | +++++++++++++-- |
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tisp.c b/tisp.c @@ -403,7 +403,18 @@ read_int(Str str) return ret; } -Val +static Val +read_sci(Str str, double val) { + if (tolower(*str->d++) != 'e') + return mk_dub(val); + + double sign = read_sign(str) == 1 ? 10.0 : 0.1; + for (int expo = read_int(str); expo--; val *= sign) ; + + return mk_dub(val); +} + +static Val read_num(Str str) { int sign = read_sign(str); @@ -422,7 +433,7 @@ read_num(Str str) free(s); while (size--) d /= 10.0; - return mk_dub(sign * (num+d)); + return read_sci(str, sign * (num+d)); default: return mk_int(sign * num); }