Repository : ssh://darcs.haskell.org//srv/darcs/packages/integer-gmp

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/30dd1991ae505b01481f561d063afcf8a2c4abec

>---------------------------------------------------------------

commit 30dd1991ae505b01481f561d063afcf8a2c4abec
Author: Ian Lynagh <[email protected]>
Date:   Sat Sep 17 18:20:41 2011 +0100

    Define mkInteger
    
    Now used by GHC to generate Integer literals.

>---------------------------------------------------------------

 GHC/Integer.lhs      |    2 +-
 GHC/Integer/Type.lhs |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/GHC/Integer.lhs b/GHC/Integer.lhs
index 392d3de..bc61d03 100644
--- a/GHC/Integer.lhs
+++ b/GHC/Integer.lhs
@@ -18,7 +18,7 @@
 #include "MachDeps.h"
 
 module GHC.Integer (
-    Integer,
+    Integer, mkInteger,
     smallInteger, wordToInteger, integerToWord, integerToInt,
 #if WORD_SIZE_IN_BITS < 64
     integerToWord64, word64ToInteger,
diff --git a/GHC/Integer/Type.lhs b/GHC/Integer/Type.lhs
index eef256b..401544d 100644
--- a/GHC/Integer/Type.lhs
+++ b/GHC/Integer/Type.lhs
@@ -72,6 +72,16 @@ data Integer
    = S# Int#                            -- small integers
    | J# Int# ByteArray#                 -- large integers
 
+mkInteger :: Bool   -- non-negative?
+          -> [Int]  -- absolute value in 31 bit chunks, least significant first
+                    -- ideally these would be Words rather than Ints, but
+                    -- we don't have Word available at the moment.
+          -> Integer
+mkInteger nonNegative is = let abs = f is
+                           in if nonNegative then abs else negateInteger abs
+    where f [] = S# 0#
+          f (I# i : is') = S# i `orInteger` shiftLInteger (f is') 31#
+
 {-# NOINLINE smallInteger #-}
 smallInteger :: Int# -> Integer
 smallInteger i = S# i



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to