clash-prelude icon indicating copy to clipboard operation
clash-prelude copied to clipboard

abs of SFixed does not saturate.

Open ra1u opened this issue 7 years ago • 3 comments

for example

*Main> a = minBound :: SFixed 5 2
*Main> abs a
-16.0

where expecting maxBound that is 15.75

ra1u avatar Jun 27 '17 18:06 ra1u

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

leonschoorl avatar Oct 26 '17 13:10 leonschoorl

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.

postoroniy avatar Jul 29 '18 04:07 postoroniy

@christiaanb: should we add:

class (Bounded a, Num a) => SaturatingNum a where
  -- ...
  satAbs    :: SaturationMode -> a -> a
  satNegate :: SaturationMode -> a -> a

leonschoorl avatar Aug 08 '18 14:08 leonschoorl