Make percentage units work like a unitless scalar. #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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')]