Commit 1d4b441d authored by qrczak's avatar qrczak
Browse files

[project @ 2001-02-22 16:48:24 by qrczak]

Since fromInt was degraded to a function, do the same with toInt.
parent c5e33ef8
% -----------------------------------------------------------------------------
% $Id: CPUTime.lhs,v 1.28 2001/02/22 13:17:58 simonpj Exp $
% $Id: CPUTime.lhs,v 1.29 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1995-2000
%
......@@ -24,7 +24,6 @@ import PrelGHC ( indexIntArray# )
import PrelBase ( Int(..) )
import PrelByteArr ( ByteArray(..), newIntArray )
import PrelArrExtra ( unsafeFreezeByteArray )
import PrelNum ( fromInt )
import PrelIOBase ( IOException(..),
IOErrorType( UnsupportedOperation ),
unsafePerformIO, stToIO, ioException )
......
% -----------------------------------------------------------------------------
% $Id: Numeric.lhs,v 1.11 2001/02/22 13:17:58 simonpj Exp $
% $Id: Numeric.lhs,v 1.12 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1997-2000
%
......@@ -332,6 +332,6 @@ floatToDigits base x =
else
let bk = expt base (-k)
in gen [] (r * bk) s (mUp * bk) (mDn * bk)
in (map toInt (reverse rds), k)
in (map fromIntegral (reverse rds), k)
\end{code}
#endif
% -----------------------------------------------------------------------------
% $Id: PrelByteArr.lhs,v 1.12 2001/02/22 13:17:58 simonpj Exp $
% $Id: PrelByteArr.lhs,v 1.13 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1994-2000
%
......@@ -19,7 +19,6 @@ import PrelArr
import PrelFloat
import PrelST
import PrelBase
import PrelNum ( fromInt )
\end{code}
%*********************************************************
......
% -----------------------------------------------------------------------------
% $Id: PrelCTypes.lhs,v 1.2 2001/02/22 13:17:58 simonpj Exp $
% $Id: PrelCTypes.lhs,v 1.3 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The FFI task force, 2000
%
......@@ -24,7 +24,6 @@ module PrelCTypes
\begin{code}
import PrelBase ( unsafeCoerce# )
import PrelReal ( Integral(toInt) )
import PrelBits ( Bits(..) )
import PrelInt ( Int8, Int16, Int32, Int64 )
import PrelWord ( Word8, Word16, Word32, Word64 )
......
% -----------------------------------------------------------------------------
% $Id: PrelCTypesISO.lhs,v 1.4 2001/02/22 13:17:58 simonpj Exp $
% $Id: PrelCTypesISO.lhs,v 1.5 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The FFI task force, 2000
%
......@@ -25,7 +25,6 @@ module PrelCTypesISO
\begin{code}
import PrelBase ( unsafeCoerce# )
import PrelReal ( Integral(toInt) )
import PrelBits ( Bits(..) )
import PrelInt ( Int8, Int16, Int32, Int64 )
import PrelWord ( Word8, Word16, Word32, Word64 )
......
......@@ -234,7 +234,6 @@ instance Integral Int8 where
a@(I8# _) `quotRem` b@(I8# _) = (a `quotInt8` b, a `remInt8` b)
toInteger i8 = toInteger (int8ToInt i8)
toInt i8 = int8ToInt i8
remInt8, quotInt8 :: Int8 -> Int8 -> Int8
......@@ -257,7 +256,7 @@ instance Enum Int8 where
| otherwise = i-1
toEnum x
| x >= toInt (minBound::Int8) && x <= toInt (maxBound::Int8)
| x >= fromIntegral (minBound::Int8) && x <= fromIntegral (maxBound::Int8)
= intToInt8 x
| otherwise
= toEnumError "Int8" x (minBound::Int8,maxBound::Int8)
......@@ -378,7 +377,6 @@ instance Integral Int16 where
a@(I16# _) `quotRem` b@(I16# _) = (a `quotInt16` b, a `remInt16` b)
toInteger i16 = toInteger (int16ToInt i16)
toInt i16 = int16ToInt i16
remInt16, quotInt16 :: Int16 -> Int16 -> Int16
remInt16 (I16# x) (I16# y) = I16# (intToInt16# ((i16ToInt# x) `remInt#` (i16ToInt# y)))
......@@ -401,7 +399,7 @@ instance Enum Int16 where
| otherwise = i-1
toEnum x
| x >= toInt (minBound::Int16) && x <= toInt (maxBound::Int16)
| x >= fromIntegral (minBound::Int16) && x <= fromIntegral (maxBound::Int16)
= intToInt16 x
| otherwise
= toEnumError "Int16" x (minBound::Int16, maxBound::Int16)
......@@ -529,7 +527,6 @@ instance Integral Int32 where
a@(I32# _) `quotRem` b@(I32# _) = (a `quotInt32` b, a `remInt32` b)
toInteger i32 = toInteger (int32ToInt i32)
toInt i32 = int32ToInt i32
remInt32, quotInt32 :: Int32 -> Int32 -> Int32
remInt32 (I32# x) (I32# y) = I32# (intToInt32# ((i32ToInt# x) `remInt#` (i32ToInt# y)))
......@@ -554,7 +551,7 @@ instance Enum Int32 where
toEnum x
-- with Int having the same range as Int32, the following test
-- shouldn't fail. However, having it here
| x >= toInt (minBound::Int32) && x <= toInt (maxBound::Int32)
| x >= fromIntegral (minBound::Int32) && x <= fromIntegral (maxBound::Int32)
= intToInt32 x
| otherwise
= toEnumError "Int32" x (minBound::Int32, maxBound::Int32)
......@@ -663,7 +660,6 @@ instance Integral Int64 where
a@(I64# _) `quotRem` b@(I64# _) = (a `quotInt64` b, a `remInt64` b)
toInteger (I64# i#) = toInteger (I# i#)
toInt (I64# i#) = I# i#
remInt64 (I64# x) (I64# y) = I64# (x `remInt#` y)
quotInt64 (I64# x) (I64# y) = I64# (x `quotInt#` y)
......@@ -743,7 +739,6 @@ instance Integral Int64 where
a@(I64# _) `quotRem` b@(I64# _) = (a `quotInt64` b, a `remInt64` b)
toInteger i = int64ToInteger i
toInt i = int64ToInt i
remInt64, quotInt64 :: Int64 -> Int64 -> Int64
remInt64 (I64# x) (I64# y) = I64# (x `remInt64#` y)
......
% ------------------------------------------------------------------------------
% $Id: PrelNum.lhs,v 1.35 2001/02/22 13:17:59 simonpj Exp $
% $Id: PrelNum.lhs,v 1.36 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1994-2000
%
......@@ -61,8 +61,8 @@ subtract :: (Num a) => a -> a -> a
{-# INLINE subtract #-}
subtract x y = y - x
ord_0 :: Num a => a
ord_0 = fromInt (ord '0')
ord_0 :: Int
ord_0 = ord '0'
\end{code}
......
% ------------------------------------------------------------------------------
% $Id: PrelReal.lhs,v 1.8 2001/02/22 13:17:59 simonpj Exp $
% $Id: PrelReal.lhs,v 1.9 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1994-2000
%
......@@ -89,7 +89,6 @@ class (Real a, Enum a) => Integral a where
quot, rem, div, mod :: a -> a -> a
quotRem, divMod :: a -> a -> (a,a)
toInteger :: a -> Integer
toInt :: a -> Int -- partain: Glasgow extension
n `quot` d = q where (q,_) = quotRem n d
n `rem` d = r where (_,r) = quotRem n d
......@@ -98,6 +97,10 @@ class (Real a, Enum a) => Integral a where
divMod n d = if signum r == negate (signum d) then (q-1, r+d) else qr
where qr@(q,r) = quotRem n d
toInt :: Integral a => a -> Int
-- For backward compatibility
toInt i = fromInteger (toInteger i)
class (Num a) => Fractional a where
(/) :: a -> a -> a
recip :: a -> a
......@@ -161,7 +164,6 @@ instance Real Int where
instance Integral Int where
toInteger i = int2Integer i -- give back a full-blown Integer
toInt x = x
-- Following chks for zero divisor are non-standard (WDP)
a `quot` b = if b /= 0
......@@ -191,7 +193,6 @@ instance Real Integer where
instance Integral Integer where
toInteger n = n
toInt n = integer2Int n
n `quot` d = n `quotInteger` d
n `rem` d = n `remInteger` d
......
% ------------------------------------------------------------------------------
% $Id: PrelST.lhs,v 1.19 2001/02/22 13:17:59 simonpj Exp $
% $Id: PrelST.lhs,v 1.20 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1992-2000
%
......@@ -11,10 +11,9 @@
module PrelST where
import PrelNum -- To get fromInt etc, needed because of -fno-implicit-prelude
import PrelShow
import PrelBase
import PrelNum () -- So that we get the .hi file for system imports
import PrelShow
import PrelNum
default ()
\end{code}
......
......@@ -280,7 +280,6 @@ instance Integral Word8 where
divMod (W8# x) (W8# y) = (W8# (x `quotWord#` y), W8# (x `remWord#` y))
toInteger = toInteger . toInt
toInt = word8ToInt
instance Ix Word8 where
range (m,n) = [m..n]
......@@ -298,7 +297,7 @@ instance Enum Word8 where
| otherwise = w-1
toEnum i@(I# i#)
| i >= toInt (minBound::Word8) && i <= toInt (maxBound::Word8)
| i >= fromIntegral (minBound::Word8) && i <= fromIntegral (maxBound::Word8)
= W8# (intToWord8# i#)
| otherwise
= toEnumError "Word8" i (minBound::Word8,maxBound::Word8)
......@@ -441,8 +440,7 @@ instance Integral Word16 where
quotRem (W16# x) (W16# y) = (W16# (x `quotWord#` y), W16# (x `remWord#` y))
divMod (W16# x) (W16# y) = (W16# (x `quotWord#` y), W16# (x `remWord#` y))
toInteger = toInteger . toInt
toInt = word16ToInt
toInteger = toInteger . word16ToInt
instance Ix Word16 where
range (m,n) = [m..n]
......@@ -460,7 +458,7 @@ instance Enum Word16 where
| otherwise = w-1
toEnum i@(I# i#)
| i >= toInt (minBound::Word16) && i <= toInt (maxBound::Word16)
| i >= fromIntegral (minBound::Word16) && i <= fromIntegral (maxBound::Word16)
= W16# (intToWord16# i#)
| otherwise
= toEnumError "Word16" i (minBound::Word16,maxBound::Word16)
......@@ -602,7 +600,6 @@ instance Integral Word32 where
divMod x y = quotRem x y
toInteger = word32ToInteger
toInt = word32ToInt
{-# INLINE quotWord32 #-}
......@@ -796,7 +793,6 @@ instance Integral Word64 where
divMod (W64# x) (W64# y) = (W64# (x `quotWord#` y), W64# (x `remWord#` y))
toInteger (W64# x) = word2Integer# x
toInt x = word64ToInt x
#else /* WORD_SIZE_IN_BYTES < 8 */
......@@ -815,9 +811,7 @@ word64ToWord16 (W64# w#) = W16# ((word64ToWord# w#) `and#` (int2Word# 0xffff#))
word64ToInteger (W64# w#) =
case word64ToInteger# w# of
(# s#, p# #) -> J# s# p#
word64ToInt w =
case w `quotRem` 0x100000000 of
(_,l) -> toInt (word64ToWord32 l)
word64ToInt (W64# w#) = I# (word2Int# (word64ToWord# w#))
intToWord64# :: Int# -> Word64#
intToWord64# i# = wordToWord64# (int2Word# i#)
......@@ -867,7 +861,6 @@ instance Integral Word64 where
quotRem (W64# x) (W64# y) = (W64# (x `quotWord64#` y), W64# (x `remWord64#` y))
divMod (W64# x) (W64# y) = (W64# (x `quotWord64#` y), W64# (x `remWord64#` y))
toInteger w64 = word64ToInteger w64
toInt x = word64ToInt x
compareWord64# :: Word64# -> Word64# -> Ordering
compareWord64# i# j#
......
% ------------------------------------------------------------------------------
% $Id: Prelude.lhs,v 1.23 2001/02/22 13:17:59 simonpj Exp $
% $Id: Prelude.lhs,v 1.24 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1992-2000
%
......@@ -51,10 +51,9 @@ module Prelude (
Ord(..),
Enum(..),
Bounded(..),
Num((+), (-), (*), negate, abs, signum, fromInteger),
Num(..),
Real(..),
Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
-- The toInt method is exposed only by GlaExts
Integral(..),
Fractional(..),
Floating(..),
RealFrac(..),
......
% ------------------------------------------------------------------------------
% $Id: Random.lhs,v 1.22 2001/02/22 13:17:59 simonpj Exp $
% $Id: Random.lhs,v 1.23 2001/02/22 16:48:24 qrczak Exp $
%
% (c) The University of Glasgow, 1995-2000
%
......@@ -37,7 +37,6 @@ import PrelShow ( showSignedInt, showSpace )
import PrelRead ( readDec )
import PrelIOBase ( unsafePerformIO, stToIO )
import PrelArr ( STRef, newSTRef, readSTRef, writeSTRef )
import PrelReal ( toInt )
import PrelFloat ( float2Double, double2Float )
import Time ( getClockTime, ClockTime(..) )
#else
......@@ -115,7 +114,7 @@ mkStdGen s
createStdGen :: Integer -> StdGen
createStdGen s
| s < 0 = createStdGen (-s)
| otherwise = StdGen (toInt (s1+1)) (toInt (s2+1))
| otherwise = StdGen (fromInteger (s1+1)) (fromInteger (s2+1))
where
(q, s1) = s `divMod` 2147483562
s2 = q `mod` 2147483398
......
/* -----------------------------------------------------------------------------
* $Id: CTypes.h,v 1.3 2001/02/22 13:17:59 simonpj Exp $
* $Id: CTypes.h,v 1.4 2001/02/22 16:48:24 qrczak Exp $
*
* Dirty CPP hackery for CTypes/CTypesISO
*
......@@ -90,8 +90,7 @@ instance Integral T where { \
(T i) `mod` (T j) = T (i `mod` j) ; \
(T i) `quotRem` (T j) = let (q,r) = i `quotRem` j in (T q, T r) ; \
(T i) `divMod` (T j) = let (d,m) = i `divMod` j in (T d, T m) ; \
toInteger (T i) = toInteger i ; \
toInt (T i) = toInt i }
toInteger (T i) = toInteger i }
#define INSTANCE_BITS(T) \
instance Bits T where { \
......@@ -260,8 +259,7 @@ instance Integral T where { \
mod = unsafeCoerce# (mod:: B -> B -> B); \
quotRem = unsafeCoerce# (quotRem:: B -> B -> (B,B)); \
divMod = unsafeCoerce# (divMod:: B -> B -> (B,B)); \
toInteger = unsafeCoerce# (toInteger:: B -> Integer); \
toInt = unsafeCoerce# (toInt:: B -> Int); }
toInteger = unsafeCoerce# (toInteger:: B -> Integer); }
#define INSTANCE_BITS(T,B) \
instance Bits T where { \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment