Project

General

Profile

Bug #13928

Calling Integer.fdiv with BigDecimal returns unexpected result

Added by calle.vander@gmail.com (Carl Vander) about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.4.2p198
[ruby-core:82924]

Description

After upgrading a Rails project from 2.3.1 to 2.4.2 I ran into a number of failing tests. Seems like to behaviour of fdiv and conjuction with bigdecimal is wrong.

Reproduce by running:

irb(main):001:0> require 'bigdecimal'
=> true
irb(main):002:0> 1.fdiv(1-BigDecimal.new("0"))
=> 2.1296133346e-314

Ruby version: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]

I would expect the calculation to return 1, which is correctly done if converting the big decimal to a float first:

irb(main):006:0> 1.fdiv(1-BigDecimal.new("0").to_f)
=> 1.0

Using ruby 2.3.1p112, it also looks OK:

irb(main):001:0> require 'bigdecimal'
=> true
irb(main):002:0> 1.fdiv(1-BigDecimal.new("0"))
=> #<BigDecimal:7fb6b8949690,'0.1E1',9(36)>
irb(main):003:0> 1.fdiv(1-BigDecimal.new("0")).to_i
=> 1


Related issues

Related to Ruby master - Bug #13986: Integer#fdiv with Complex returns unexpected valueClosedActions

Associated revisions

Revision 24ef8ad1
Added by nobu (Nobuyoshi Nakada) about 2 years ago

numeric.c: use NUM2DBL

  • numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use NUM2DBL on unknown object. RFLOAT_VALUE is only appliicable to T_FLOAT object. [ruby-core:82924] [Bug #13928]

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

Revision 59986
Added by nobu (Nobuyoshi Nakada) about 2 years ago

numeric.c: use NUM2DBL

  • numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use NUM2DBL on unknown object. RFLOAT_VALUE is only appliicable to T_FLOAT object. [ruby-core:82924] [Bug #13928]

Revision 59986
Added by nobu (Nobuyoshi Nakada) about 2 years ago

numeric.c: use NUM2DBL

  • numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use NUM2DBL on unknown object. RFLOAT_VALUE is only appliicable to T_FLOAT object. [ruby-core:82924] [Bug #13928]

Revision 59986
Added by nobu (Nobuyoshi Nakada) about 2 years ago

numeric.c: use NUM2DBL

  • numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use NUM2DBL on unknown object. RFLOAT_VALUE is only appliicable to T_FLOAT object. [ruby-core:82924] [Bug #13928]

Revision 05ba9938
Added by nagachika (Tomoyuki Chikanaga) almost 2 years ago

merge revision(s) 59986: [Backport #13928]

    numeric.c: use NUM2DBL

    * numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use
      NUM2DBL on unknown object.  RFLOAT_VALUE is only appliicable to
      T_FLOAT object.  [ruby-core:82924] [Bug #13928]

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

Revision 62171
Added by nagachika (Tomoyuki Chikanaga) almost 2 years ago

merge revision(s) 59986: [Backport #13928]

numeric.c: use NUM2DBL

* numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use
  NUM2DBL on unknown object.  RFLOAT_VALUE is only appliicable to
  T_FLOAT object.  [ruby-core:82924] [Bug #13928]

History

#1

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED
#2

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59986.


numeric.c: use NUM2DBL

  • numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use NUM2DBL on unknown object. RFLOAT_VALUE is only applicable to T_FLOAT object. [ruby-core:82924] [Bug #13928]
#3

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Description updated (diff)
#4

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Related to Bug #13986: Integer#fdiv with Complex returns unexpected value added

Updated by nagachika (Tomoyuki Chikanaga) almost 2 years ago

  • Backport changed from 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE

ruby_2_4 r62171 merged revision(s) 59986.

Also available in: Atom PDF