Zero has special encoding as IEEE754 floating point number with a 0
value for exponent. This encoding requires special handling in
current Float.round implementation.
I mostly used the
test "foo/x" do
# ...
end
convention instead of using "foo" as the test title. In some cases I added some
descriptive string to make the test more self-explanatory.
The previous implementations for ceil, floor and round were
not formalized and were likely prone to multiple roundings
as we performed multiplication and division by a power of
10 on the given float.
The new implementation correctly converts the float to an
exact integer representation and perform all operations using
arbitrary precision integers. The only float operation occurs
when converting the ratio back to a float.
The current implementation is more expensive due to its reliance
on big integers. Faster implementations are available in literature
where the latest one seems to be Errol:
https://cseweb.ucsd.edu/~lerner/papers/fp-printing-popl16.pdf
This change also introduces Float.ratio/1 which receives a
float and returns a pair of integers whose ratio is exactly equal
to the original float and with a positive denominator.
Closes#3400
This commit clarifies the documentation for `Float.parse/1` as well as
adds test assertions to demonstrate the limits enforced by erlang/IEEE
754-1985 double precision floats. See #3862 for more context.