Backport #5272
closedFloat#round doesn't round big values
Description
For large enough values (outside of Fixnum range), Float#round does not round at all but simply truncates:
2.999999999999999e20.round(-20) # => 200000000000000000000
Fixed in trunk, but would be nice to backport for Ruby 1.9.3.
Files
Updated by marcandre (Marc-Andre Lafortune) over 13 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r33186.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- numeric.c (flo_round): Make Float#round round big values [bug #5272]
Updated by marcandre (Marc-Andre Lafortune) over 13 years ago
- Status changed from Closed to Open
Opening the backport request. Note: dependent on r33185 and r33183
Updated by nagachika (Tomoyuki Chikanaga) over 13 years ago
I've found that TestFloat#test_round fails after r33186 on i686-linux.
For (4294967295.8).round, 32bit version ruby returns 4294967295, while 64bit version(x86_64-linux) returns correctly 4294967296. It seems that when result value is Bignum Float#round works like floor().
Updated by nagachika (Tomoyuki Chikanaga) over 13 years ago
- File numeric.c.patch numeric.c.patch added
Attach a tiny patch. It works for me with make test-all.
Updated by marcandre (Marc-Andre Lafortune) over 13 years ago
Tomoyuki Chikanaga wrote:
Attach a tiny patch. It works for me with make test-all.
Thanks! You patch works, but the bug was actually in dbl2ival. See r33199 / #5276
Updated by naruse (Yui NARUSE) over 13 years ago
- Tracker changed from Backport to Bug
- Status changed from Open to Assigned
- Assignee set to marcandre (Marc-Andre Lafortune)
Updated by naruse (Yui NARUSE) over 13 years ago
- ruby -v set to ruby 1.9.4dev (2011-08-05 trunk 32856) [x86_64-darwin11.0.0]
This issue still happends:
Float("2.5e-22").round(22) #=> 2.0e-22aaaaaa
Updated by naruse (Yui NARUSE) over 13 years ago
- ruby -v changed from ruby 1.9.4dev (2011-08-05 trunk 32856) [x86_64-darwin11.0.0] to ruby 1.9.4dev (2011-09-06 trunk 33199) [x86_64-darwin11.1.0]
Updated by marcandre (Marc-Andre Lafortune) over 13 years ago
- Category set to core
- Status changed from Assigned to Open
- Assignee deleted (
marcandre (Marc-Andre Lafortune))
Yui NARUSE wrote:
This issue still happends:
Float("2.5e-22").round(22) #=> 2.0e-22
This is a different issue, caused by calculation error. I opened issue #5273 to deal with boundary cases like this one. This present issue was not due to approximation but by truncation of any values.
Moving back to backport request
Updated by marcandre (Marc-Andre Lafortune) over 13 years ago
- Tracker changed from Bug to Backport
Updated by kosaki (Motohiro KOSAKI) over 13 years ago
If I parsed this thread correctly, this bug is not a regression. therefore it isn't 1.9.3p0 material. I think.
Updated by marcandre (Marc-Andre Lafortune) over 13 years ago
See my comment on #5276
Updated by naruse (Yui NARUSE) about 13 years ago
- Target version deleted (
1.9.3)
Updated by naruse (Yui NARUSE) about 13 years ago
- Status changed from Open to Closed
This issue was solved with changeset r33898.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 33158,33185,33186:
* numeric.c (flo_round): substitute machine dependent magic number.
* numeric.c (flo_round): Make Float#round round big values [bug
#5272]