goldfirere/units

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

Closed this issue · 3 comments

21it commented

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                                        

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

Released the fix.

21it commented

Super cool! Thanks a lot for the fix!