This project is closed and read-only.
Backport #5272
closedFloat#round doesn't round big values
Added by marcandre (Marc-Andre Lafortune) about 15 years ago. Updated almost 15 years ago.
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
| numeric.c.patch (328 Bytes) numeric.c.patch | nagachika (Tomoyuki Chikanaga), 09/05/2011 05:11 PM |
Updated by marcandre (Marc-Andre Lafortune) about 15 years ago
Actions
#1
- 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) about 15 years ago
Actions
#2
[ruby-core:39265]
- Status changed from Closed to Open
Opening the backport request. Note: dependent on r33185 and r33183
Updated by nagachika (Tomoyuki Chikanaga) about 15 years ago
Actions
#3
[ruby-core:39277]
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) about 15 years ago
Actions
#4
[ruby-core:39278]
- 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) about 15 years ago
Actions
#5
[ruby-core:39288]
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) about 15 years ago
Actions
#6
- Tracker changed from Backport to Bug
- Status changed from Open to Assigned
- Assignee set to marcandre (Marc-Andre Lafortune)
Updated by naruse (Yui NARUSE) about 15 years ago
Actions
#7
[ruby-core:39294]
- 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) about 15 years ago
Actions
#8
[ruby-core:39295]
- 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) about 15 years ago
Actions
#9
[ruby-core:39296]
- 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) about 15 years ago
Actions
#10
- Tracker changed from Bug to Backport
Updated by kosaki (Motohiro KOSAKI) about 15 years ago
Actions
#11
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) about 15 years ago
Actions
#12
[ruby-core:39319]
See my comment on #5276
Updated by naruse (Yui NARUSE) almost 15 years ago
Actions
#13
- Target version deleted (
1.9.3)
Updated by naruse (Yui NARUSE) almost 15 years ago
Actions
#14
- 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: