Inconsistent conversion of Float into Decimal
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:
See the comprehensive answer by Stefan who points out that it is due to different precisions being used in Float#to_d and BigDecimal#*.
Updated by Anonymous about 1 month ago
- Status changed from Assigned to Closed
Applied in changeset git|e1424c35012ccf1f3822c9046081b225aef4142e.
[bigdecimal] Fix the default precision of Float#to_d