Project

General

Profile

Actions

Bug #12805

closed

MRI BigDecimal#div produces grossly wrong result

Added by felixvf (Felix von Ferey) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
[ruby-core:77475]

Description

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
Actions #1

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Status changed from Open to Closed

Applied in changeset r56336.


bigdecimal.c: more precision

  • ext/bigdecimal/bigdecimal.c (BigDecimal_div2): need more room
    for precision to round. [ruby-core:77475] [Bug #12805]
Actions

Also available in: Atom PDF

Like0
Like0