diff options
author | Ian Lynagh <igloo@earth.li> | 2012-02-23 22:10:27 +0000 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2012-02-23 22:12:12 +0000 |
commit | 042461c4b0e4d4479e9d2eba60c04027e27b77b9 (patch) | |
tree | 475a0f16ccaa67759f10426317e7ccbe0fcfda93 /testsuite/tests/numeric | |
parent | 51fbbbb2b25cb477fe22215e5484e208ab616c98 (diff) | |
download | haskell-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.hs | 26 | ||||
-rw-r--r-- | testsuite/tests/numeric/should_run/add2.stdout | 15 | ||||
-rw-r--r-- | testsuite/tests/numeric/should_run/all.T | 3 |
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, ['']) + |