[commit: integer-gmp] master: Define mkInteger (30dd199)
Ian Lynagh
igloo at earth.li
Sun Sep 18 00:27:51 CEST 2011
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 <igloo at earth.li>
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
More information about the Cvs-libraries
mailing list