Say I’m parsing a decimal number into a Double
from a text file and the number happens to be something like
1234.56789e305
It’s quite trivial to separate it out into 123456789
(significand expressed as unsigned integer in base-10) and 300
(base-10 exponent), and it’s quite obvious it’s a representable Double
since the exponent does not exceed 308
.
From what I gather the current base
solution is roughly
fromRational (123456789 * (10 ^ (300 :: Integer)) % 1) :: Double
This obviously works correctly precision-wise, but constructing 10300 is quite overkill for an operation that shouldn’t require any big numbers whatsoever (since significand never needs more than 17 decimal digits for precision and exponent fits into a 16-bit number).
Am I missing a better solution (that does not include me implementing decimal to binary floating-point conversions) or is this currently all base
got?