From: muraken@... Date: 2017-03-29T14:16:00+00:00 Subject: [ruby-core:80481] [Ruby trunk Bug#13331][Assigned] Inconsistent conversion of Float into Decimal Issue #13331 has been updated by mrkn (Kenta Murata). Status changed from Open to Assigned Assignee set to mrkn (Kenta Murata) Continue this in https://github.com/ruby/bigdecimal/issues/70 ---------------------------------------- Bug #13331: Inconsistent conversion of Float into Decimal https://bugs.ruby-lang.org/issues/13331#change-63980 * Author: msatkiewicz (Maciej Satkiewicz) * Status: Assigned * Priority: Normal * Assignee: mrkn (Kenta Murata) * Target version: * ruby -v: ruby 2.4.0 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- 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-------------------------------- multiplication_by_unit.rb (1.9 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: