Project

General

Profile

Bug #13928

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

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 **Reproduce by running:
```ruby
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 **I would expect the calculation to return 1, which is correctly done if converting the big decimal to a float first:
```ruby
first:**

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


### Using **Using ruby 2.3.1p112, it also looks OK:
```ruby
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

Back