summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/Numeric/num009.hs
diff options
context:
space:
mode:
authorDavid Terei <davidterei@gmail.com>2011-07-20 11:09:03 -0700
committerDavid Terei <davidterei@gmail.com>2011-07-20 11:26:35 -0700
commit16514f272fb42af6e9c7674a9bd6c9dce369231f (patch)
treee4f332b45fe65e2a7a2451be5674f887b42bf199 /testsuite/tests/lib/Numeric/num009.hs
parentebd422aed41048476aa61dd4c520d43becd78682 (diff)
downloadhaskell-16514f272fb42af6e9c7674a9bd6c9dce369231f.tar.gz
Move tests from tests/ghc-regress/* to just tests/*
Diffstat (limited to 'testsuite/tests/lib/Numeric/num009.hs')
-rw-r--r--testsuite/tests/lib/Numeric/num009.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/testsuite/tests/lib/Numeric/num009.hs b/testsuite/tests/lib/Numeric/num009.hs
new file mode 100644
index 0000000000..6910f2f840
--- /dev/null
+++ b/testsuite/tests/lib/Numeric/num009.hs
@@ -0,0 +1,39 @@
+-- trac #2059
+
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+module Main(main) where
+
+import Control.Monad
+import Foreign.C
+
+main = do let d = 1e20 :: Double
+ f = 1e20 :: Float
+ test "sind" sind sin d
+ test "sinf" sinf sin f
+ test "cosd" cosd cos d
+ test "cosf" cosf cos f
+ test "tand" tand tan d
+ test "tanf" tanf tan f
+ putStrLn "Done"
+
+test :: (RealFloat a, Floating a, RealFloat b, Floating b)
+ => String -> (a -> a) -> (b -> b) -> b -> IO ()
+test s f g x = do let y = realToFrac (f (realToFrac x))
+ z = g x
+ unless (y == z) $ do
+ putStrLn s
+ print y
+ print z
+ print $ decodeFloat y
+ print $ decodeFloat z
+
+foreign import ccall "math.h sin" sind :: CDouble -> CDouble
+foreign import ccall "math.h sinf" sinf :: CFloat -> CFloat
+
+foreign import ccall "math.h cos" cosd :: CDouble -> CDouble
+foreign import ccall "math.h cosf" cosf :: CFloat -> CFloat
+
+foreign import ccall "math.h tan" tand :: CDouble -> CDouble
+foreign import ccall "math.h tanf" tanf :: CFloat -> CFloat
+