Expand num009 to test more values, and add mingw32 output
[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 = [0, pi, pi/2, pi/3, 1e10, 1e20] :: [Double]
11 f = [0, pi, pi/2, pi/3, 1e10, 1e20] :: [Float]
12 mapM_ (test "sind" sind sin) d
13 mapM_ (test "sinf" sinf sin) f
14 mapM_ (test "cosd" cosd cos) d
15 mapM_ (test "cosf" cosf cos) f
16 mapM_ (test "tand" tand tan) d
17 mapM_ (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 ++ ' ':show x)
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