Skip to content

Commit c07fa82

Browse files
even more vooodo!
1 parent 70f1e4f commit c07fa82

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/Constrained/NumOrd.hs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -730,24 +730,32 @@ instance {-# OVERLAPPABLE #-} (HasSpec a, MaybeBounded a, Integral a, TypeSpec a
730730
doDivide = div
731731

732732
divideSpec 0 _ = TrueSpec
733-
-- TODO This is all wrong and hence the tests are all wrong
734733
divideSpec a (NumSpecInterval (unionWithMaybe max lowerBound -> ml) (unionWithMaybe min upperBound -> mu)) = typeSpec ts
735734
where
736735
ts | a > 0 = NumSpecInterval ml' mu'
737736
| otherwise = NumSpecInterval mu' ml'
738737
ml' = adjustLowerBound <$> ml
739738
mu' = adjustUpperBound <$> mu
740-
adjustLowerBound l =
741-
let r = l `div` a in
742-
if r * a < l
743-
then r + signum a
744-
else r
745739

746-
adjustUpperBound u =
747-
let r = u `div` a in
748-
if r * a > u
749-
then r - signum a
750-
else r
740+
-- NOTE: negate has different overflow semantics than div, so that's why we use negate below...
741+
742+
adjustLowerBound l
743+
| a == 1 = l
744+
| a == -1 = negate l
745+
| otherwise =
746+
let r = l `div` a in
747+
if r * a < l
748+
then r + signum a
749+
else r
750+
751+
adjustUpperBound u
752+
| a == 1 = u
753+
| a == -1 = negate u
754+
| otherwise =
755+
let r = u `div` a in
756+
if r * a > u
757+
then r - signum a
758+
else r
751759

752760
instance HasDivision Float where
753761
doDivide = (/)

0 commit comments

Comments
 (0)