title: Inconsistent conversion of Float into Decimal in Ruby
body: <p>First, take a specific float <code>f</code>:</p>
  
  <pre><code>f = [64.4, 73.60, 77.90, 87.40, 95.40].sample # take any one of these special Floats
  f.to_d.class == (1.to_d * f).class # =&gt; true (BigDecimal)
  </code></pre>
  
  <p>So multiplying by <code>BigDecimal</code> casts <code>f</code> to <code>BigDecimal</code>. Therefore <code>1.to_d * f</code> (or <code>f * 1.to_d</code>) can be seen as a (poor, but still) form of converting <code>f</code> to <code>BigDecimal</code>. And yet for these specific values we have:</p>
  
  <pre><code>f.to_d == 1.to_d * f # =&gt; false (?!)
  </code></pre>
  
  <p>Isn't this a bug? I'd assume that while multiplying by <code>1.to_d</code> Ruby should invoke <code>f.to_d</code> internally. But the results differ, i.e. for  <code>f = 64.4</code>:</p>
  
  <pre><code>f.to_d # =&gt; #&lt;BigDecimal:7f8202038280,'0.644E2',18(36)&gt;
  1.to_d * f # =&gt; #&lt;BigDecimal:7f82019c1208,'0.6440000000 000001E2',27(45)&gt;
  </code></pre>
  
  <p>I cannot see why floating-point representation error should be an excuse here, yet it's obviously a cause, somehow. So why is this happening?</p>
  
  <p>PS. I wrote a snippet of code playing around with this issue:</p>
  
  <p><a href="https://github.com/Swarzkopf314/ruby_wtf/blob/master/multiplication_by_unit.rb" rel="nofollow noreferrer">https://github.com/Swarzkopf314/ruby_wtf/blob/master/multiplication_by_unit.rb</a></p>