Commit Graph
21 Commits
Author SHA1 Message Date
José Valim d3de9717df Fix rounding for subnormal floats (#8687)
Closes #8685
2019-01-25 08:39:41 +01:00
José Valim a9e189a588 Support subnormal floats in Float.ratio/1 (#8360) 2018-11-06 09:51:20 +01:00
Bryan Arendt 15e7d2eecd Run formatter on lib/elixir/test/elixir/float_test.exs (#6773) 2017-10-10 08:42:05 +02:00
Gal Tsubery 960511fc78 Improve Float ceil/round/floor error messages (#5820) 2017-02-28 16:08:53 +01:00
Gal Tsubery 8a1e1ba288 Fix ceil function with zero as input (#5594)
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.
2016-12-27 10:46:39 +01:00
Andrea Leopardi 73f7b582d7 Improve test names in a few modules
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.
2016-12-08 20:27:02 +01:00
José Valim f51db25de2 Introduce Float.ratio/1 and fix Float.{ceil/2, floor/2, round/2}
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
2016-10-07 18:46:33 +02:00
Aleksei Magusev a92b6ee4a5 Move doctests from central place to the modules they describe 2015-11-25 00:26:07 +01:00
Joshua Wood e2578654a1 Document limits of Float.parse/1.
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.
2015-10-13 08:37:05 -07:00
redpine50 67b8512a74 New test cases for exponent marker E and leading + 2015-09-09 23:52:36 +10:00
José Valim 2052a3b648 Convert test :atom into test string 2015-08-15 14:41:46 +02:00
jw2013 27521c128b fix floating point approximation error 2014-10-31 20:46:33 -07:00
José Valim 0fdb7f0259 Optimize and improve docs for Float operations 2014-07-12 14:05:18 +02:00
Johnny Winn 9327aa09e0 Add precision to Float.ceil/1 & Float.floor/1 2014-07-11 12:34:24 -04:00
Chas Lemley 94812b4242 fix error with float midpoint rounding
- remove midpoint rounding option from Float.round/2
- always midpoint round away from 0
2014-01-12 12:17:50 -05:00
Justin Jaffray 70d7a28a36 Fix Float.parse to handle numbers of the form "-0.x"
Since Float.parse uses Integer.parse, the -0 would be
parsed independently of what came after the decimal
point and would become 0
2013-12-25 10:35:24 -05:00
Paul Schoenfelder 38c60776f6 Add Float.round function
Float.round allows rounding floats to arbitrary precision, as well
as specifying how midpoint rounding is performed (up/down).
2013-12-13 09:24:59 -06:00
Paul Schoenfelder d624ceb72b Add floor and ceil functions to Float 2013-12-12 15:05:00 -06:00
José Valim 95e3fec729 Ensure Integer.parse and Float.parse do not accept double +, - and . 2013-10-20 10:54:11 +02:00
Carlos Brito Lage 8099754898 Added extra test coverage for float parsing 2013-10-19 15:13:28 -07:00
José Valim 429548ea75 Remove pid conversions from Kernel, clean up String conversions 2013-10-18 19:16:17 +02:00