Project

General

Profile

Actions

Bug #19321

closed

BigDecimal multiplication giving different result since Ruby 3.1

Added by alexandruanca (Alexandru Anca) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:111708]

Description

I have this math operation 120.to_d * 0.07 and I noticed that since upgrading to Ruby 3.1 I get different results. I would expect to get the same result as in previous versions.

rbenv local 3.0.3
➜  irb
require 'bigdecimal/util.rb'
(120.to_d * 0.07).to_s('F')
=> "8.4000000000000012"
rbenv local 3.1.3
✗ irb
require 'bigdecimal/util.rb'
(120.to_d * 0.07).to_s('F')
=> "8.4"

It looks like the change has been introduced in Ruby 3.1. I tested Ruby 2.7.0 and I get the same result as in 3.0 ("8.4000000000000012")
I saw in the release notes that there were changes to bigdecimal so I am not sure if this is expected or it's a bug

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

The newer result seems arithmetically correct.

Updated by jeremyevans0 (Jeremy Evans) over 1 year ago

  • Status changed from Open to Closed

The old result was incorrect. The new, correct result is due to a bug fix. I'm going to close this. If you can find a result that is incorrect in Ruby 3.1 or 3.2, please post it.

Updated by alexandruanca (Alexandru Anca) over 1 year ago

The old result was incorrect. The new, correct result is due to a bug fix. I'm going to close this. If you can find a result that is incorrect in Ruby 3.1 or 3.2, please post it.

I see, makes sence. Thanks for the explanation

Actions

Also available in: Atom PDF

Like0
Like0Like0Like1Like0