clash-prelude
clash-prelude copied to clipboard
abs of SFixed does not saturate.
for example
*Main> a = minBound :: SFixed 5 2
*Main> abs a
-16.0
where expecting maxBound that is 15.75
While surprising, it is at least consistent with other types in Haskell:
Prelude> b = minBound :: Int
Prelude> abs b
-9223372036854775808
Prelude> b == abs b
True
BTW the same is for C. And not the same for matlab :) where it makes sense quite a lot and I'd be happy to have abs as @ra1u expected.
@christiaanb: should we add:
class (Bounded a, Num a) => SaturatingNum a where
-- ...
satAbs :: SaturationMode -> a -> a
satNegate :: SaturationMode -> a -> a