Project

General

Profile

Backport #5272

Float#round doesn't round big values

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

Status:
Closed
Priority:
Normal
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

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

Associated revisions

Revision 75c42535
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 33186
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

Revision 33186
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

Revision 33186
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

Revision 33186
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

Revision 33186
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

Revision 33186
Added by marcandre (Marc-Andre Lafortune) about 8 years ago

  • numeric.c (flo_round): Make Float#round round big values [bug #5272]

Revision 68336beb
Added by naruse (Yui NARUSE) almost 8 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@33898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 33898
Added by naruse (Yui NARUSE) almost 8 years ago

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]

History

#1

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

  • Status changed from Closed to Open

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

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

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

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

#6

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

#10

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

  • Tracker changed from Bug to Backport
#11

Updated by kosaki (Motohiro KOSAKI) about 8 years ago

If I parsed this thread correctly, this bug is not a regression. therefore it isn't 1.9.3p0 material. I think.

#13

Updated by naruse (Yui NARUSE) about 8 years ago

  • Target version deleted (1.9.3)
#14

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

Also available in: Atom PDF