Data.Float.Text
Float to text and back: the shortest decimal that reads back as the same
Float, and the correctly rounded Float nearest a decimal.
Both directions are exact arithmetic on a multiprecision decimal, shifted by powers of two. That works because 2 divides 10: a binary fraction always has a finite decimal expansion, so every value and every rounding boundary involved can be held exactly, and the one rounding decision is made on exact digits rather than on an approximation of them. There is no table of powers of ten and no 128-bit product, which the faster algorithms (Ryu, Schubfach, Eisel-Lemire) all need; the price is time, not correctness.
Parsing has one shortcut in front, and it is exact too: see fastPath.
The shortest decimal that reads back as x, as Show Float prints it:
fixed notation when the decimal exponent is in -4..15, otherwise one digit,
a point, the rest and a signed exponent of at least two digits. Either way
there is a fractional part, .0 if nothing else, so finite output lexes as
a Float literal and not an Int one.
[+-]? digits (. digits)? ([eE] [+-]? digits)? with at least one of the
fraction and the exponent, the whole string -- the literal syntax without
its _ separators, plus a sign -- or one of NaN, Infinity, -Infinity,
which have no literal and so can only be written down this way. None for
anything else. The result is the Float nearest the exact decimal value,
ties to even; out of range is an infinity or a zero of the right sign.