Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SatSymmetric Signed computations include minBound as a result #1460

Open
DigitalBrains1 opened this issue Jul 21, 2020 · 0 comments
Open

SatSymmetric Signed computations include minBound as a result #1460

DigitalBrains1 opened this issue Jul 21, 2020 · 0 comments

Comments

@DigitalBrains1
Copy link
Member

SaturatingNum's SatSymmetric computations on signed integers only saturate to the symmetric lower bound on overflow of the computation, but not if the result is minBound. One would expect SatSymmetric computations to not have a bias, but the computations do have a slight bias this way.

Clash.Prelude P> P.map (\n -> satSub SatSymmetric n 1 :: Signed 4) [(-8) .. (-5)]
[-7,-8,-7,-6]
Clash.Prelude P> P.map (\n -> satAdd SatSymmetric n (-1) :: Signed 4) [(-8) .. (-5)]
[-7,-8,-7,-6]
Clash.Prelude P> satMul SatSymmetric 2 (-4) :: Signed 4
-8
Clash.Prelude P> satAdd SatSymmetric 0 (-1) :: Signed 1
-1

Since it is fundamentally valid to use the value minBound as input to these computations, which also introduces bias, perhaps the correct solution is to introduce a new datatype that only represents values within symmetric bounds.

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

No branches or pull requests

1 participant