@@ -75,7 +75,7 @@ import Data.SBV.Core.SizedFloats
7575
7676import Data.Ratio
7777
78- import Data.SBV.Utils.Numeric (RoundingMode (.. ), {- fp2fp,-} fpIsEqualObjectH , fpIsNormalizedH , fpMaxH , fpMinH , fpRemH , fpRoundToIntegralH , floatToWord , doubleToWord , wordToFloat , wordToDouble )
78+ import Data.SBV.Utils.Numeric (RoundingMode (.. ), divEucl , modEucl , {- fp2fp,-} fpIsEqualObjectH , fpIsNormalizedH , fpMaxH , fpMinH , fpRemH , fpRoundToIntegralH , floatToWord , doubleToWord , wordToFloat , wordToDouble )
7979
8080import LibBF
8181
@@ -238,11 +238,15 @@ svSignum a
238238 z = SVal k $ Left $ mkConstCV k (0 :: Integer )
239239 i = SVal k $ Left $ mkConstCV k (1 :: Integer )
240240
241- -- | Division.
241+ -- | Division. For integers, this behaves like 'svQuot', except that this
242+ -- ensures @'svQuot' a 0 = a@.
242243svDivide :: SVal -> SVal -> SVal
243- svDivide = liftSym2 (mkSymOp Quot ) [rationalCheck] (/) idiv (/) (/) (/) (/)
244- where idiv x 0 = x
245- idiv x y = x `quot` y
244+ svDivide x y = liftSym2 (mkSymOp Quot ) [rationalCheck] (/) idiv (/) (/) (/) (/) x y
245+ where isInteger = kindOf x == KUnbounded
246+
247+ idiv a 0 = a
248+ idiv a b | isInteger = a `divEucl` b
249+ | True = a `quot` b
246250
247251-- | Divides predicate
248252svDivides :: Integer -> SVal -> SVal
@@ -333,7 +337,7 @@ svQuot x y
333337 where
334338 isInteger = kindOf x == KUnbounded
335339
336- quot' a b | isInteger = div a ( abs b) * signum b
340+ quot' a b | isInteger = divEucl a b
337341 | True = quot a b
338342
339343-- | Remainder: Overloaded operation whose meaning depends on the kind at which
@@ -360,7 +364,7 @@ svRem x y
360364 where
361365 isInteger = kindOf x == KUnbounded
362366
363- rem' a b | isInteger = mod a ( abs b)
367+ rem' a b | isInteger = modEucl a b
364368 | True = rem a b
365369
366370-- | Combination of 'svQuot' and 'svRem'
0 commit comments