58ab586ba8885098bdeebf4e16e691235912ee6f
[packages/base.git] / tests / Numeric / num009.hs
1 -- trac #2059
2
3 {-# LANGUAGE ForeignFunctionInterface #-}
4
5 module Main(main) where
6
7 import Control.Monad
8 import Foreign.C
9
10 main = do let d = 1e20 :: Double
11 f = 1e20 :: Float
12 test "sind" sind sin d
13 test "sinf" sinf sin f
14 test "cosd" cosd cos d
15 test "cosf" cosf cos f
16 test "tand" tand tan d
17 test "tanf" tanf tan f
18 putStrLn "Done"
19
20 test :: (RealFloat a, Floating a, RealFloat b, Floating b, Show b)
21 => String -> (a -> a) -> (b -> b) -> b -> IO ()
22 test s f g x = do let y = realToFrac (f (realToFrac x))
23 z = g x
24 unless (y == z) $ do
25 putStrLn s
26 print y
27 print z
28 print $ decodeFloat y
29 print $ decodeFloat z
30
31 foreign import ccall "math.h sin" sind :: CDouble -> CDouble
32 foreign import ccall "math.h sinf" sinf :: CFloat -> CFloat
33
34 foreign import ccall "math.h cos" cosd :: CDouble -> CDouble
35 foreign import ccall "math.h cosf" cosf :: CFloat -> CFloat
36
37 foreign import ccall "math.h tan" tand :: CDouble -> CDouble
38 foreign import ccall "math.h tanf" tanf :: CFloat -> CFloat
39