Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

abs of SFixed does not saturate. #114

Open
ra1u opened this issue Jun 27, 2017 · 3 comments
Open

abs of SFixed does not saturate. #114

ra1u opened this issue Jun 27, 2017 · 3 comments

Comments

@ra1u
Copy link

ra1u commented Jun 27, 2017

for example

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

where expecting maxBound that is 15.75

@leonschoorl
Copy link
Member

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

@postoroniy
Copy link

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.

@leonschoorl
Copy link
Member

leonschoorl commented Aug 8, 2018

@christiaanb: should we add:

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants