summaryrefslogtreecommitdiff
path: root/testsuite/tests/numeric
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2012-02-23 22:10:27 +0000
committerIan Lynagh <igloo@earth.li>2012-02-23 22:12:12 +0000
commit042461c4b0e4d4479e9d2eba60c04027e27b77b9 (patch)
tree475a0f16ccaa67759f10426317e7ccbe0fcfda93 /testsuite/tests/numeric
parent51fbbbb2b25cb477fe22215e5484e208ab616c98 (diff)
downloadhaskell-042461c4b0e4d4479e9d2eba60c04027e27b77b9.tar.gz
Add a test for add-with-carry
Diffstat (limited to 'testsuite/tests/numeric')
-rw-r--r--testsuite/tests/numeric/should_run/add2.hs26
-rw-r--r--testsuite/tests/numeric/should_run/add2.stdout15
-rw-r--r--testsuite/tests/numeric/should_run/all.T3
3 files changed, 44 insertions, 0 deletions
diff --git a/testsuite/tests/numeric/should_run/add2.hs b/testsuite/tests/numeric/should_run/add2.hs
new file mode 100644
index 0000000000..5990f4fa83
--- /dev/null
+++ b/testsuite/tests/numeric/should_run/add2.hs
@@ -0,0 +1,26 @@
+
+{-# 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))
+
diff --git a/testsuite/tests/numeric/should_run/add2.stdout b/testsuite/tests/numeric/should_run/add2.stdout
new file mode 100644
index 0000000000..bdeff7290a
--- /dev/null
+++ b/testsuite/tests/numeric/should_run/add2.stdout
@@ -0,0 +1,15 @@
+-----
+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
diff --git a/testsuite/tests/numeric/should_run/all.T b/testsuite/tests/numeric/should_run/all.T
index af46ec12e0..252d1afab9 100644
--- a/testsuite/tests/numeric/should_run/all.T
+++ b/testsuite/tests/numeric/should_run/all.T
@@ -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, [''])
+