Actions
Bug #17183
closedFloat round working weirdly
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
Updated by agustincornu (Agustin Cornu) about 4 years ago
This is a known issue and not a bug. My bad. I cannot delete the ticket
Updated by marcandre (Marc-Andre Lafortune) about 4 years ago
- Is duplicate of Bug #14635: Float#round(n) returns a wrong result when n is big added
Updated by marcandre (Marc-Andre Lafortune) about 4 years ago
- Is duplicate of deleted (Bug #14635: Float#round(n) returns a wrong result when n is big)
Updated by marcandre (Marc-Andre Lafortune) about 4 years ago
- Related to Bug #14635: Float#round(n) returns a wrong result when n is big added
Updated by marcandre (Marc-Andre Lafortune) about 4 years ago
I think that's a bug. Looks different but maybe related to #14365.
Updated by shyouhei (Shyouhei Urabe) about 4 years ago
Agreed to @marcandre (Marc-Andre Lafortune) . This sounds like a real bug.
Updated by jeremyevans (Jeremy Evans) over 3 years ago
- 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
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0