Re:Stage 3 Proposal: Array.prototype.at
by dfabulich on Wednesday June 02, 2021 @01:33PM
(#27371576)
JS has BigInt now. You can kinda fake BigDecimal with it, but none of the built-in operators will work.
[ Parent
| on HN ]
Re:Stage 3 Proposal: Array.prototype.at
by runarberg on Wednesday June 02, 2021 @03:22PM
(#27372867)
How 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?
What 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.
This is basically floating-point.
IEEE 754, BTW, allows for 10-based floats, but IDK if anybody uses it.