Bug #13331
closedInconsistent conversion of Float into Decimal
Description
One would reasonably expect the equality 1.to_d * f == f.t_d to hold for every Float value f, i.e. multiplying by DigDecimal's unit can be viewed as an alternative way of casting Float into Decimal; or simply one could expect that BigDecimal#* should always invoke Float#to_d on it's argument. Yet for some Floats (e.g. 64.4) the results differ, as showed in the provided script. This can cause a bug in some application contexts.
Originally I asked about that on Stackoverflow:
http://stackoverflow.com/questions/40472933/inconsistent-conversion-of-float-into-decimal-in-ruby/40473007
See the comprehensive answer by Stefan who points out that it is due to different precisions being used in Float#to_d and BigDecimal#*.
Files
Updated by msatkiewicz (Maciej Satkiewicz) over 7 years ago
- Description updated (diff)
Updated by mrkn (Kenta Murata) over 7 years ago
- Status changed from Open to Assigned
- Assignee set to mrkn (Kenta Murata)
Continue this in https://github.com/ruby/bigdecimal/issues/70
Updated by Anonymous almost 4 years ago
- Status changed from Assigned to Closed
Applied in changeset git|e1424c35012ccf1f3822c9046081b225aef4142e.
[bigdecimal] Fix the default precision of Float#to_d
Fix https://github.com/ruby/bigdecimal/issues/70
[Bug #13331]