ruby-units icon indicating copy to clipboard operation
ruby-units copied to clipboard

Make percentage units work like a unitless scalar.

Open ahacking opened this issue 11 years ago • 2 comments

The following percentage based calculations now work as shown: Unit('50 %') * Unit('50 %) == Unit('25 %') Unit('50 m') * Unit('10 %) == Unit('5 m') Unit('10 %') * Unit('50 m) == Unit('5 m') Unit('50 m') / Unit('10 %) == Unit('500 m') Unit('50 %') / Unit('10 m) == Unit('1/20 m') Unit('50 %') / Unit('50 %) == Unit(1) Unit('50 %').divmod Unit('50 %) == [1,0] Unit('15 m').divmod Unit('6 %) == [Unit('250 m'), Unit('0 m')]

A side effect of this enhancement is divmod now also works correctly with the same unit support as regular division: Unit('15 m').divmod Unit('6') == [Unit('2 m'), Unit('3 m')] Unit('15 m').divmod Unit('6 cm') == [Unit('2 m/cm'), Unit('3 m/cm')]

ahacking avatar Sep 09 '14 16:09 ahacking

ping @olbrich

ahacking avatar Jan 06 '15 04:01 ahacking

this is pretty cool !

mathieujobin avatar Jan 15 '20 10:01 mathieujobin