[ruby-core:111708] [Ruby master Bug#19321] BigDecimal multiplication giving different result since Ruby 3.1

Issue #19321 has been reported by alexandruanca (Alexandru Anca). ---------------------------------------- Bug #19321: BigDecimal multiplication giving different result since Ruby 3.1 https://bugs.ruby-lang.org/issues/19321 * Author: alexandruanca (Alexandru Anca) * Status: Open * Priority: Normal * ruby -v: 3.1.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 -- https://bugs.ruby-lang.org/

Issue #19321 has been updated by nobu (Nobuyoshi Nakada). The newer result seems arithmetically correct. ---------------------------------------- Bug #19321: BigDecimal multiplication giving different result since Ruby 3.1 https://bugs.ruby-lang.org/issues/19321#change-101107 * Author: alexandruanca (Alexandru Anca) * Status: Open * Priority: Normal * ruby -v: 3.1.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 -- https://bugs.ruby-lang.org/

Issue #19321 has been updated by jeremyevans0 (Jeremy Evans). 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. ---------------------------------------- Bug #19321: BigDecimal multiplication giving different result since Ruby 3.1 https://bugs.ruby-lang.org/issues/19321#change-101108 * Author: alexandruanca (Alexandru Anca) * Status: Closed * Priority: Normal * ruby -v: 3.1.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 -- https://bugs.ruby-lang.org/

Issue #19321 has been updated by nobu (Nobuyoshi Nakada). JFI: it is https://github.com/ruby/bigdecimal/pull/180, which fixed https://github.com/ruby/bigdecimal/issues/70 and #13331. ---------------------------------------- Bug #19321: BigDecimal multiplication giving different result since Ruby 3.1 https://bugs.ruby-lang.org/issues/19321#change-101109 * Author: alexandruanca (Alexandru Anca) * Status: Closed * Priority: Normal * ruby -v: 3.1.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 -- https://bugs.ruby-lang.org/

Issue #19321 has been updated by alexandruanca (Alexandru Anca).
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 ---------------------------------------- Bug #19321: BigDecimal multiplication giving different result since Ruby 3.1 https://bugs.ruby-lang.org/issues/19321#change-101130 * Author: alexandruanca (Alexandru Anca) * Status: Closed * Priority: Normal * ruby -v: 3.1.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 -- https://bugs.ruby-lang.org/
participants (3)
-
alexandruanca (Alexandru Anca)
-
jeremyevans0 (Jeremy Evans)
-
nobu (Nobuyoshi Nakada)