Commit 042461c4 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Add a test for add-with-carry

parent 51fbbbb2
{-# LANGUAGE MagicHash, UnboxedTuples #-}
import GHC.Prim
import GHC.Word
import Data.Bits
main :: IO ()
main = do f 5 6
f maxBound 23
f maxBound maxBound
f :: Word -> Word -> IO ()
f wx@(W# x) wy@(W# y)
= do putStrLn "-----"
putStrLn ("Doing " ++ show wx ++ " + " ++ show wy)
case x `plusWord2#` y of
(# h, l #) ->
do let wh = W# h
wl = W# l
r = shiftL (fromIntegral wh) (bitSize wh)
+ fromIntegral wl
putStrLn ("High: " ++ show wh)
putStrLn ("Low: " ++ show wl)
putStrLn ("Result: " ++ show (r :: Integer))
-----
Doing 5 + 6
High: 0
Low: 11
Result: 11
-----
Doing 18446744073709551615 + 23
High: 1
Low: 22
Result: 18446744073709551638
-----
Doing 18446744073709551615 + 18446744073709551615
High: 1
Low: 18446744073709551614
Result: 36893488147419103230
......@@ -53,3 +53,6 @@ test('1603', skip, compile_and_run, [''])
test('3676', expect_broken(3676), compile_and_run, [''])
test('4381', normal, compile_and_run, [''])
test('4383', normal, compile_and_run, [''])
test('add2', normal, compile_and_run, [''])
Supports Markdown
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