Project

General

Profile

Actions

Backport #5272

closed

Float#round doesn't round big values

Added by marcandre (Marc-Andre Lafortune) about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
[ruby-core:39264]

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

Related issues 1 (0 open1 closed)

Related to Backport193 - Backport #5276: 4294967295.8.round is 4294967295 on 32bitClosed09/05/2011Actions
Actions #1

Updated by marcandre (Marc-Andre Lafortune) about 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) about 13 years ago

  • Status changed from Closed to Open

Opening the backport request. Note: dependent on r33185 and r33183

Updated by nagachika (Tomoyuki Chikanaga) about 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) about 13 years ago

Attach a tiny patch. It works for me with make test-all.

Updated by marcandre (Marc-Andre Lafortune) about 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

Actions #6

Updated by naruse (Yui NARUSE) about 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) about 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) about 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) about 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

Actions #10

Updated by marcandre (Marc-Andre Lafortune) about 13 years ago

  • Tracker changed from Bug to Backport
Actions #11

Updated by kosaki (Motohiro KOSAKI) about 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.

Actions #13

Updated by naruse (Yui NARUSE) about 13 years ago

  • Target version deleted (1.9.3)
Actions #14

Updated by naruse (Yui NARUSE) almost 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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0