Project

General

Profile

Actions

Bug #13754

closed

bigdecimal with lower precision that Float

Added by lionel_perrin (Lionel PERRIN) over 7 years ago. Updated almost 3 years ago.

Status:
Third Party's Issue
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]
[ruby-core:82107]
Tags:

Description

Hello,

I'm not sure if I've misunderstood the bigdecimal class but in the following example, I only get 12 significant digits using bigdecimal while using Float, I get a correct value with 17 significant digits.

# using floats
101/0.9163472602589686 # 110.22022368622177 (OK: floating point computation)

# using bigdecimal
a = BigDecimal('101'); a.precs # [9, 18] 
b = BigDecimal('0.9163472602589686'); b.precs # [18, 27]
c = a/b; c.precs # [18, 36]              (OK: I understand that c is computed with 18 significant digits)
c.to_s # "0.110220223686e3"              (Mmm: I see only 12 significant digits)
c - BigDecimal('0.110220223686e3') # 0.0 (Looks like c only stores 12 significant digits and not 18)

Using the Rational class, I've seen that the value I'm expecting is about:

BigDecimal.new(Rational(101/Rational('0.9163472602589686')), 25) # 0.1102202236862217746799312e3

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #8826: BigDecimal#div and #quo different behavior and inconsistenciesThird Party's Issuemrkn (Kenta Murata)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0