5 ms·
JS has BigInt now. You can kinda fake BigDecimal with it, but none of the built-in operators will work.
by dfabulich 5y ago
JS has BigInt now. You can kinda fake BigDecimal with it, but none of the built-in operators will work.
- runarberg 5y agoHow do you fake BigDecimal with BigInt? My immediate intuition would have a 3-tuple (a, b, c) which would construct the decimal with a representing the numbers before the decimal separator, b the number of zeroes immediately after the decimal separator, and c the numbers after the zeroes. e.g. 1.000054 would be represented as `[1n, 4n, 54n]` and 3.14159 as `[3n, 0n, 14159n]`. Is there a better way?
- lbussell 5y agoWhat about a 2-tuple with two numbers, one being the BigInt and one being the exponent. So 1.000054 would be (1000054, -6) = 1000054*10^(-6). Yours is probably more space efficient though.