From cd9d822eb7de16759f737c384583cd482c8f2aa5 Mon Sep 17 00:00:00 2001 From: simonmar <unknown> Date: Tue, 29 Feb 2000 12:08:55 +0000 Subject: [PATCH] [project @ 2000-02-29 12:08:55 by simonmar] Fix boundary cases for quotInteger, remInteger & a few others. These changes somehow escaped 4.06 and have been sitting in my tree for a while. --- ghc/lib/std/PrelNum.lhs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/ghc/lib/std/PrelNum.lhs b/ghc/lib/std/PrelNum.lhs index 5e18a0b3ce61..be3abc831f10 100644 --- a/ghc/lib/std/PrelNum.lhs +++ b/ghc/lib/std/PrelNum.lhs @@ -144,9 +144,9 @@ toBig i@(J# _ _) = i \begin{code} quotRemInteger :: Integer -> Integer -> (Integer, Integer) -quotRemInteger i1@(S# i) i2@(S# j) - | i ==# -2147483648# = quotRemInteger (toBig i1) i2 - | otherwise = case quotRemInt (I# i) (I# j) of ( I# i, I# j ) -> ( S# i, S# j ) +quotRemInteger a@(S# (-2147483648#)) b = quotRemInteger (toBig a) b +quotRemInteger (S# i) (S# j) + = case quotRemInt (I# i) (I# j) of ( I# i, I# j ) -> ( S# i, S# j ) quotRemInteger i1@(J# _ _) i2@(S# _) = quotRemInteger i1 (toBig i2) quotRemInteger i1@(S# _) i2@(J# _ _) = quotRemInteger (toBig i1) i2 quotRemInteger (J# s1 d1) (J# s2 d2) @@ -154,9 +154,9 @@ quotRemInteger (J# s1 d1) (J# s2 d2) (# s3, d3, s4, d4 #) -> (J# s3 d3, J# s4 d4) -divModInteger i1@(S# i) i2@(S# j) - | i ==# -2147483648# = divModInteger (toBig i1) i2 - | otherwise = case divModInt (I# i) (I# j) of ( I# i, I# j ) -> ( S# i, S# j) +divModInteger a@(S# (-2147483648#)) b = divModInteger (toBig a) b +divModInteger (S# i) (S# j) + = case divModInt (I# i) (I# j) of ( I# i, I# j ) -> ( S# i, S# j) divModInteger i1@(J# _ _) i2@(S# _) = divModInteger i1 (toBig i2) divModInteger i1@(S# _) i2@(J# _ _) = divModInteger (toBig i1) i2 divModInteger (J# s1 d1) (J# s2 d2) @@ -167,9 +167,8 @@ divModInteger (J# s1 d1) (J# s2 d2) remInteger :: Integer -> Integer -> Integer remInteger ia 0 = error "Prelude.Integral.rem{Integer}: divide by 0" -remInteger ia@(S# a) ib@(S# b) - | a ==# -2147483648# = remInteger (toBig ia) ib - | otherwise = S# (remInt# a b) +remInteger a@(S# (-2147483648#)) b = remInteger (toBig a) b +remInteger (S# a) (S# b) = S# (remInt# a b) remInteger ia@(S# a) (J# sb b) | sb ==# 1# = S# (remInt# a (word2Int# (integer2Word# sb b))) | sb ==# -1# = S# (remInt# a (0# -# (word2Int# (integer2Word# sb b)))) @@ -185,9 +184,8 @@ remInteger (J# sa a) (J# sb b) quotInteger :: Integer -> Integer -> Integer quotInteger ia 0 = error "Prelude.Integral.quot{Integer}: divide by 0" -quotInteger ia@(S# a) ib@(S# b) - | a ==# -2147483648# = quotInteger (toBig ia) ib - | otherwise = S# (quotInt# a b) +quotInteger a@(S# (-2147483648#)) b = quotInteger (toBig a) b +quotInteger (S# a) (S# b) = S# (quotInt# a b) quotInteger (S# a) (J# sb b) | sb ==# 1# = S# (quotInt# a (word2Int# (integer2Word# sb b))) | sb ==# -1# = S# (quotInt# a (0# -# (word2Int# (integer2Word# sb b)))) @@ -203,9 +201,9 @@ quotInteger (J# sa a) (J# sb b) \begin{code} gcdInteger :: Integer -> Integer -> Integer -gcdInteger ia@(S# a) ib@(S# b) - | a ==# -2147483648# = gcdInteger (toBig ia) ib - | otherwise = S# (gcdInt# a b) +gcdInteger a@(S# (-2147483648#)) b = gcdInteger (toBig a) b +gcdInteger a b@(S# (-2147483648#)) = gcdInteger a (toBig b) +gcdInteger (S# a) (S# b) = S# (gcdInt# a b) gcdInteger ia@(S# a) ib@(J# sb b) | a ==# 0# = abs ib | sb ==# 0# = abs ia @@ -228,9 +226,8 @@ lcmInteger a b ab = abs b divExact :: Integer -> Integer -> Integer -divExact ia@(S# a) ib@(S# b) - | a ==# -2147483648# = divExact (toBig ia) ib - | otherwise = S# (quotInt# a b) +divExact a@(S# (-2147483648#)) b = divExact (toBig a) b +divExact (S# a) (S# b) = S# (quotInt# a b) divExact (S# a) (J# sb b) = S# (quotInt# a (sb *# (word2Int# (integer2Word# sb b)))) divExact (J# sa a) (S# b) -- GitLab