Commit 82cd258f authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Add tests for new internal GMP primitives

See [ce8ec963/integer-gmp] and [97c101b7/integer-gmp] for more details
parent ba3ae9c6
......@@ -853,6 +853,7 @@ tests/lib/integer/integerBits
tests/lib/integer/integerConstantFolding
tests/lib/integer/integerConstantFolding.simpl
tests/lib/integer/integerConversions
tests/lib/integer/integerGmpInternals
tests/lib/libposix/po003.out
tests/lib/libposix/posix002
tests/lib/libposix/posix003
......
test('integerBits', normal, compile_and_run, [''])
test('integerConversions', normal, compile_and_run, [''])
test('integerGmpInternals', reqlib('integer-gmp'), compile_and_run, [''])
test('integerConstantFolding',
extra_clean(['integerConstantFolding.simpl']),
run_command,
......
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Main (main) where
import GHC.Base
import GHC.Integer
import GHC.Integer.GMP.Internals
gcdExtInteger' :: Integer -> Integer -> (Integer, Integer)
gcdExtInteger' a b = case gcdExtInteger a b of (# a, b #) -> (a,b)
powInteger' :: Integer -> Word -> Integer
powInteger' b (W# w#) = powInteger b w#
{- Reference implementation for 'powModInteger'
powModIntegerHs :: Integer -> Integer -> Integer -> Integer
powModIntegerHs b0 e0 m
| e0 >= 0 = go b0 e0 1
| otherwise = error "non-neg exponent required"
where
go !b e !r
| odd e = go b' e' (r*b `mod` m)
| e == 0 = r
| otherwise = go b' e' r
where
b' = b*b `mod` m
e' = e `unsafeShiftR` 1 -- slightly faster than "e `div` 2"
-}
main :: IO ()
main = do
print $ powModInteger b e m
print $ gcdExtInteger' b e
print $ gcdExtInteger' e b
print $ gcdExtInteger' x y
print $ gcdExtInteger' y x
print $ powInteger' 12345 0
print $ powInteger' 12345 1
print $ powInteger' 12345 30
print $ [ (x,i) | x <- [0..71], let i = recipModInteger x (2*3*11*11*17*17), i /= 0 ]
return ()
where
b = 2988348162058574136915891421498819466320163312926952423791023078876139
e = 2351399303373464486466122544523690094744975233415544072992656881240319
m = 10^(40::Int)
x = 5328841272400314897981163497728751426
y = 32052182750761975518649228050096851724
1527229998585248450016808958343740453059
(1,-238164827888328100873319793437342927637138278785737103723156342382925)
(1,302679100340807588460107986194035692812415103244388831792688023418704)
(92889294,115110207004456909698806038261)
(92889294,-19137667681784054624628973533)
1
12345
555562377826831043419246079513769804614412256811161773362797946971665712715296306339052301636736176350153982639312744140625
[(1,1),(5,41963),(7,59947),(13,177535),(19,143557),(23,182447),(25,134281),(29,7235),(31,33841),(35,95915),(37,113413),(41,61409),(43,24397),(47,174101),(49,158431),(53,193979),(59,188477),(61,185737),(65,35507),(67,118999),(71,186173)]
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