Skip to content

Conversation

ahacking
Copy link

@ahacking ahacking commented Sep 9, 2014

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')]

 - A side effect of this enhancement is divmod now also works
   correctly with the same unit support as regular division.
@ahacking
Copy link
Author

ahacking commented Jan 6, 2015

ping @olbrich

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have a helper method called 'percent?'

@mathieujobin
Copy link

this is pretty cool !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants