From: felix+bugs.ruby-lang.org@... Date: 2016-10-03T13:23:44+00:00 Subject: [ruby-core:77475] [Ruby trunk Bug#12805] MRI BigDecimal#div produces grossly wrong result Issue #12805 has been reported by Felix von Ferey. ---------------------------------------- Bug #12805: MRI BigDecimal#div produces grossly wrong result https://bugs.ruby-lang.org/issues/12805 * Author: Felix von Ferey * Status: Open * Priority: Normal * Assignee: * ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- ### Expected (It works in JRuby-9.1.5.0) ~~~ # ruby -e 'require "bigdecimal"; (1...50).each do |i| puts (BigDecimal.new("1").div(BigDecimal.new("0.22E0"),i)).to_s; end' 0.5E1 0.45E1 0.455E1 0.4545E1 0.45455E1 0.454545E1 0.4545455E1 0.45454545E1 0.454545455E1 0.4545454545E1 0.45454545455E1 0.454545454545E1 0.4545454545455E1 0.45454545454545E1 0.454545454545455E1 0.4545454545454545E1 0.45454545454545455E1 0.454545454545454545E1 0.4545454545454545455E1 0.45454545454545454545E1 0.454545454545454545455E1 0.4545454545454545454545E1 0.45454545454545454545455E1 0.454545454545454545454545E1 0.4545454545454545454545455E1 0.45454545454545454545454545E1 0.454545454545454545454545455E1 0.4545454545454545454545454545E1 0.45454545454545454545454545455E1 0.454545454545454545454545454545E1 0.4545454545454545454545454545455E1 0.45454545454545454545454545454545E1 0.454545454545454545454545454545455E1 0.4545454545454545454545454545454545E1 0.45454545454545454545454545454545455E1 0.454545454545454545454545454545454545E1 0.4545454545454545454545454545454545455E1 0.45454545454545454545454545454545454545E1 0.454545454545454545454545454545454545455E1 0.4545454545454545454545454545454545454545E1 0.45454545454545454545454545454545454545455E1 0.454545454545454545454545454545454545454545E1 0.4545454545454545454545454545454545454545455E1 0.45454545454545454545454545454545454545454545E1 0.454545454545454545454545454545454545454545455E1 0.4545454545454545454545454545454545454545454545E1 0.45454545454545454545454545454545454545454545455E1 0.454545454545454545454545454545454545454545454545E1 0.4545454545454545454545454545454545454545454545455E1 ~~~ ### Actual (It does not work in MRI-2.3.1p112) ~~~ # ruby -e 'require "bigdecimal"; (1...50).each do |i| puts (BigDecimal.new("1").div(BigDecimal.new("0.22E0"),i)).to_s; end' 0.4E1 0.4E1 0.4E1 0.4E1 0.4E1 0.4E1 0.4E1 0.4E1 0.4E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454E1 0.4545454545454545454545454545454545454545454545E1 0.4545454545454545454545454545454545454545454545E1 0.4545454545454545454545454545454545454545454545E1 0.4545454545454545454545454545454545454545454545E1 ~~~ ### Additional observations Note that dividing by "0.22" shows the bug, but dividing by "2.2" does not show the bug: ~~~ # ruby -e 'require "bigdecimal"; (1...50).each do |i| puts (BigDecimal.new("1").div(BigDecimal.new("0.22E1"),i)).to_s; end' 0.5E0 0.45E0 0.455E0 0.4545E0 0.45455E0 0.454545E0 0.4545455E0 0.45454545E0 0.454545454E0 0.4545454545E0 0.45454545455E0 0.454545454545E0 0.4545454545455E0 0.45454545454545E0 0.454545454545455E0 0.4545454545454545E0 0.45454545454545455E0 0.454545454545454545E0 0.4545454545454545455E0 0.45454545454545454545E0 0.454545454545454545455E0 0.4545454545454545454545E0 0.45454545454545454545455E0 0.454545454545454545454545E0 0.4545454545454545454545455E0 0.45454545454545454545454545E0 0.454545454545454545454545454E0 0.4545454545454545454545454545E0 0.45454545454545454545454545455E0 0.454545454545454545454545454545E0 0.4545454545454545454545454545455E0 0.45454545454545454545454545454545E0 0.454545454545454545454545454545455E0 0.4545454545454545454545454545454545E0 0.45454545454545454545454545454545455E0 0.454545454545454545454545454545454545E0 0.4545454545454545454545454545454545455E0 0.45454545454545454545454545454545454545E0 0.454545454545454545454545454545454545455E0 0.4545454545454545454545454545454545454545E0 0.45454545454545454545454545454545454545455E0 0.454545454545454545454545454545454545454545E0 0.4545454545454545454545454545454545454545455E0 0.45454545454545454545454545454545454545454545E0 0.454545454545454545454545454545454545454545454E0 0.4545454545454545454545454545454545454545454545E0 0.45454545454545454545454545454545454545454545455E0 0.454545454545454545454545454545454545454545454545E0 0.4545454545454545454545454545454545454545454545455E0 ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: