goldfirere / units

The home of the units Haskell package
94 stars 19 forks source link

Subtract |-| implementation is wrong for quantities based on Ratio Natural #69

Closed 21it closed 2 years ago

21it commented 2 years ago

In example https://github.com/21it/src/blob/76f6bc3d1660b9fb02a66f6b48efd39368a232a2/bitfinex-client/src/BitfinexClient/Data/Metro.hs#L72-L73

Every expression like (x :: MoneyBase') |-| (y :: MoneyBase') will cause runtime exception of arithmetic underflow regardless x and y values. I guess implementation details of |-| themselves do cause exception:

(|-|) :: (d1 @~ d2, Num n) => Qu d1 l n -> Qu d2 l n -> Qu d1 l n
a |-| b = a |+| qNegate b                                        
goldfirere commented 2 years ago

Thanks for the report! Fixed now. Will release after CI is green.

goldfirere commented 2 years ago

Released the fix.

21it commented 2 years ago

Super cool! Thanks a lot for the fix!