olbrich/ruby-units — Issue #24: Incorrect units conversion with compound units 
Author: comtesacristain
Created: 2011-10-17 05:23:23+00:00
State: open

Currently I am trying to multiply an ore by its mineral grade to get the contained mineral

irb(main):001:0> ore='189 Mtonne'.u
=> 189 Mtonne
irb(main):002:0> grade='1189 g/tonne'.u
=> 1189 g/tonne
irb(main):003:0> mineral=ore*grade
=> 224721 g*Mtonne/tonne
irb(main):004:0> mineral.to('tonne')
=> 224.721 tonne

The correct answer is in fact '224721 tonne', which makes the out by a factor of one thousand. I seem to have pinned down where in the code this error occurs, lines 793-801 in Unit.rb, and after commenting it out, I get the right figures.

Essentially, the term 1000 is found in _numerator1, _denominator1 and _numerator2, but is only eliminated from _numerator1 in the second block of those lines.