Bug #17183 closed
Float round working weirdly
Added by agustincornu (Agustin Cornu) over 4 years ago.
Updated over 3 years ago.
Description
I encountered this issue when casting a specific float with a especific round argument.
0.5.round(15)
=> 0.5
0.5.round(16)
=> 0.5000000000000001
0.5.round(17)
=> 0.5
This is a known issue and not a bug. My bad. I cannot delete the ticket
Is duplicate of Bug #14635 : Float#round(n) returns a wrong result when n is big added
Is duplicate of deleted (Bug #14635 : Float#round(n) returns a wrong result when n is big )
Related to Bug #14635 : Float#round(n) returns a wrong result when n is big added
I think that's a bug. Looks different but maybe related to #14365 .
Status changed from Open to Closed
Applied in changeset git|d16b68cb2204eeb5af8bd39149202b630374c67f .
Use Rational for Float#round with ndigits > 14
ndigits higher than 14 can result in values that are slightly too
large due to floating point limitations. Converting to rational
for the calculation and then back to float fixes these issues.
Fixes [Bug #14635 ]
Fixes [Bug #17183 ]
Co-authored by: Yusuke Endoh mame@ruby-lang.org
Also available in: Atom
PDF
Like 0
Like 0 Like 0 Like 0 Like 0 Like 0 Like 0 Like 0 Like 0