cmath: Fix bad typo in atan2 and atan2f.
[altfloat.git] / Data / Floating / CMath.hs
blobce6090e77e363131605b2ea9326b93082ab3edaa
1 {-
2 - Copyright (C) 2009-2010 Nick Bowler.
4 - License BSD2: 2-clause BSD license. See LICENSE for full terms.
5 - This is free software: you are free to change and redistribute it.
6 - There is NO WARRANTY, to the extent permitted by law.
7 -}
9 -- | Bindings to the standard C math library.
10 {-# LANGUAGE ForeignFunctionInterface #-}
11 module Data.Floating.CMath (
12 -- * Trigonometric functions
13 c_acos, c_acosf, c_asin, c_asinf, c_atan, c_atanf, c_atan2, c_atan2f,
14 c_cos, c_cosf, c_sin, c_sinf, c_tan, c_tanf,
16 -- * Hyperbolic functions
17 c_acosh, c_acoshf, c_asinh, c_asinhf, c_atanh, c_atanhf, c_cosh, c_coshf,
18 c_sinh, c_sinhf, c_tanh, c_tanhf,
20 -- * Exponential and logarithmic functions
21 c_exp, c_expf, c_exp2, c_exp2f, c_expm1, c_expm1f, c_frexp, c_frexpf,
22 c_ilogb, c_ilogbf, c_ldexp, c_ldexpf, c_log, c_logf, c_log10, c_log10f,
23 c_log1p, c_log1pf, c_log2, c_log2f, c_logb, c_logbf, c_modf, c_modff,
24 c_scalbn, c_scalbnf, c_scalbln, c_scalblnf,
26 -- * Power and absolute-value functions
27 c_cbrt, c_cbrtf, c_fabs, c_fabsf, c_hypot, c_hypotf, c_pow, c_powf, c_sqrt,
28 c_sqrtf,
30 -- * Remainder functions
31 c_fmod, c_fmodf, c_remainder, c_remainderf, c_remquo, c_remquof,
33 -- * Manipulation functions
34 c_copysign, c_copysignf, c_nan, c_nanf, c_nextafter, c_nextafterf,
36 -- * Error and gamma functions
37 c_erf, c_erff, c_erfc, c_erfcf, c_lgamma, c_lgammaf, c_tgamma, c_tgammaf,
39 -- * Nearest integer functions
40 c_ceil, c_ceilf, c_floor, c_floorf, c_nearbyint, c_nearbyintf, c_rint,
41 c_rintf, c_lrint, c_lrintf, c_llrint, c_llrintf, c_round, c_roundf,
42 c_lround, c_lroundf, c_llround, c_llroundf, c_trunc, c_truncf,
44 -- * Maximum, minimum, and positive difference functions
45 c_fdim, c_fdimf, c_fmax, c_fmaxf, c_fmin, c_fminf,
47 -- * Floating multiply-add
48 c_fma, c_fmaf,
50 -- * Haskell wrappers
51 libmDouble, libmFloat, libmDouble2, libmFloat2, libmDouble3, libmFloat3
52 ) where
54 import Prelude hiding (Double, Float)
56 import Data.Floating.Types
57 import Foreign
58 import Foreign.C
60 libmDouble :: (CDouble -> CDouble) -> Double -> Double
61 libmDouble f a = toFloating $ f (toFloating a)
63 libmFloat :: (CFloat -> CFloat) -> Float -> Float
64 libmFloat f a = toFloating $ f (toFloating a)
66 libmDouble2 :: (CDouble -> CDouble -> CDouble) -> Double -> Double -> Double
67 libmDouble2 f a b = toFloating $ f (toFloating a) (toFloating b)
69 libmFloat2 :: (CFloat -> CFloat -> CFloat) -> Float -> Float -> Float
70 libmFloat2 f a b = toFloating $ f (toFloating a) (toFloating b)
72 libmDouble3 :: (CDouble -> CDouble -> CDouble -> CDouble)
73 -> Double -> Double -> Double -> Double
74 libmDouble3 f a b c = toFloating
75 $ f (toFloating a) (toFloating b) (toFloating c)
77 libmFloat3 :: (CFloat -> CFloat -> CFloat -> CFloat)
78 -> Float -> Float -> Float -> Float
79 libmFloat3 f a b c = toFloating
80 $ f (toFloating a) (toFloating b) (toFloating c)
82 -- 7.12.4 Trigonometric functions
83 foreign import ccall unsafe "acos"
84 c_acos :: CDouble -> CDouble
85 foreign import ccall unsafe "acosf"
86 c_acosf :: CFloat -> CFloat
87 foreign import ccall unsafe "asin"
88 c_asin :: CDouble -> CDouble
89 foreign import ccall unsafe "asinf"
90 c_asinf :: CFloat -> CFloat
91 foreign import ccall unsafe "atan"
92 c_atan :: CDouble -> CDouble
93 foreign import ccall unsafe "atanf"
94 c_atanf :: CFloat -> CFloat
95 foreign import ccall unsafe "atan2"
96 c_atan2 :: CDouble -> CDouble -> CDouble
97 foreign import ccall unsafe "atan2f"
98 c_atan2f :: CFloat -> CFloat -> CFloat
99 foreign import ccall unsafe "cos"
100 c_cos :: CDouble -> CDouble
101 foreign import ccall unsafe "cosf"
102 c_cosf :: CFloat -> CFloat
103 foreign import ccall unsafe "sin"
104 c_sin :: CDouble -> CDouble
105 foreign import ccall unsafe "sinf"
106 c_sinf :: CFloat -> CFloat
107 foreign import ccall unsafe "tan"
108 c_tan :: CDouble -> CDouble
109 foreign import ccall unsafe "tanf"
110 c_tanf :: CFloat -> CFloat
112 -- 7.12.5 Hyperbolic functions
113 foreign import ccall unsafe "acosh"
114 c_acosh :: CDouble -> CDouble
115 foreign import ccall unsafe "acoshf"
116 c_acoshf :: CFloat -> CFloat
117 foreign import ccall unsafe "asinh"
118 c_asinh :: CDouble -> CDouble
119 foreign import ccall unsafe "asinhf"
120 c_asinhf :: CFloat -> CFloat
121 foreign import ccall unsafe "atanh"
122 c_atanh :: CDouble -> CDouble
123 foreign import ccall unsafe "atanhf"
124 c_atanhf :: CFloat -> CFloat
125 foreign import ccall unsafe "cosh"
126 c_cosh :: CDouble -> CDouble
127 foreign import ccall unsafe "coshf"
128 c_coshf :: CFloat -> CFloat
129 foreign import ccall unsafe "sinh"
130 c_sinh :: CDouble -> CDouble
131 foreign import ccall unsafe "sinhf"
132 c_sinhf :: CFloat -> CFloat
133 foreign import ccall unsafe "tanh"
134 c_tanh :: CDouble -> CDouble
135 foreign import ccall unsafe "tanhf"
136 c_tanhf :: CFloat -> CFloat
138 -- 7.12.6 Exponential and logarithmic functions
139 foreign import ccall unsafe "exp"
140 c_exp :: CDouble -> CDouble
141 foreign import ccall unsafe "expf"
142 c_expf :: CFloat -> CFloat
143 foreign import ccall unsafe "exp2"
144 c_exp2 :: CDouble -> CDouble
145 foreign import ccall unsafe "exp2f"
146 c_exp2f :: CFloat -> CFloat
147 foreign import ccall unsafe "expm1"
148 c_expm1 :: CDouble -> CDouble
149 foreign import ccall unsafe "expm1f"
150 c_expm1f :: CFloat -> CFloat
151 foreign import ccall unsafe "frexp"
152 c_frexp :: CDouble -> Ptr CInt -> IO CDouble
153 foreign import ccall unsafe "frexpf"
154 c_frexpf :: CFloat -> Ptr CInt -> IO CFloat
155 foreign import ccall unsafe "ilogb"
156 c_ilogb :: CDouble -> CInt
157 foreign import ccall unsafe "ilogbf"
158 c_ilogbf :: CFloat -> CInt
159 foreign import ccall unsafe "ldexp"
160 c_ldexp :: CDouble -> CInt -> CDouble
161 foreign import ccall unsafe "ldexpf"
162 c_ldexpf :: CFloat -> CInt -> CFloat
163 foreign import ccall unsafe "log"
164 c_log :: CDouble -> CDouble
165 foreign import ccall unsafe "logf"
166 c_logf :: CFloat -> CFloat
167 foreign import ccall unsafe "log10"
168 c_log10 :: CDouble -> CDouble
169 foreign import ccall unsafe "log10f"
170 c_log10f :: CFloat -> CFloat
171 foreign import ccall unsafe "log1p"
172 c_log1p :: CDouble -> CDouble
173 foreign import ccall unsafe "log1pf"
174 c_log1pf :: CFloat -> CFloat
175 foreign import ccall unsafe "log2"
176 c_log2 :: CDouble -> CDouble
177 foreign import ccall unsafe "log2f"
178 c_log2f :: CFloat -> CFloat
179 foreign import ccall unsafe "logb"
180 c_logb :: CDouble -> CDouble
181 foreign import ccall unsafe "logbf"
182 c_logbf :: CFloat -> CFloat
183 foreign import ccall unsafe "modf"
184 c_modf :: CDouble -> Ptr CDouble -> IO CDouble
185 foreign import ccall unsafe "modff"
186 c_modff :: CFloat -> Ptr CFloat -> IO CFloat
187 foreign import ccall unsafe "scalbn"
188 c_scalbn :: CDouble -> CInt -> CDouble
189 foreign import ccall unsafe "scalbnf"
190 c_scalbnf :: CFloat -> CInt -> CFloat
191 foreign import ccall unsafe "scalbln"
192 c_scalbln :: CDouble -> CLong -> CDouble
193 foreign import ccall unsafe "scalblnf"
194 c_scalblnf :: CFloat -> CLong -> CFloat
196 -- 7.12.7 Power and absolute-value functions
197 foreign import ccall unsafe "cbrt"
198 c_cbrt :: CDouble -> CDouble
199 foreign import ccall unsafe "cbrtf"
200 c_cbrtf :: CFloat -> CFloat
201 foreign import ccall unsafe "fabs"
202 c_fabs :: CDouble -> CDouble
203 foreign import ccall unsafe "fabsf"
204 c_fabsf :: CFloat -> CFloat
205 foreign import ccall unsafe "hypot"
206 c_hypot :: CDouble -> CDouble -> CDouble
207 foreign import ccall unsafe "hypotf"
208 c_hypotf :: CFloat -> CFloat -> CFloat
209 foreign import ccall unsafe "pow"
210 c_pow :: CDouble -> CDouble -> CDouble
211 foreign import ccall unsafe "powf"
212 c_powf :: CFloat -> CFloat -> CFloat
213 foreign import ccall unsafe "sqrt"
214 c_sqrt :: CDouble -> CDouble
215 foreign import ccall unsafe "sqrtf"
216 c_sqrtf :: CFloat -> CFloat
218 -- 7.12.8 Error and gamma functions
219 foreign import ccall unsafe "erf"
220 c_erf :: CDouble -> CDouble
221 foreign import ccall unsafe "erff"
222 c_erff :: CFloat -> CFloat
223 foreign import ccall unsafe "erfc"
224 c_erfc :: CDouble -> CDouble
225 foreign import ccall unsafe "erfcf"
226 c_erfcf :: CFloat -> CFloat
227 foreign import ccall unsafe "lgamma"
228 c_lgamma :: CDouble -> CDouble
229 foreign import ccall unsafe "lgammaf"
230 c_lgammaf :: CFloat -> CFloat
231 foreign import ccall unsafe "tgamma"
232 c_tgamma :: CDouble -> CDouble
233 foreign import ccall unsafe "tgammaf"
234 c_tgammaf :: CFloat -> CFloat
236 -- 7.12.9 Nearest integer functions
237 foreign import ccall unsafe "ceil"
238 c_ceil :: CDouble -> CDouble
239 foreign import ccall unsafe "ceilf"
240 c_ceilf :: CFloat -> CFloat
241 foreign import ccall unsafe "floor"
242 c_floor :: CDouble -> CDouble
243 foreign import ccall unsafe "floorf"
244 c_floorf :: CFloat -> CFloat
245 foreign import ccall unsafe "nearbyint"
246 c_nearbyint :: CDouble -> CDouble
247 foreign import ccall unsafe "nearbyintf"
248 c_nearbyintf :: CFloat -> CFloat
249 foreign import ccall unsafe "rint"
250 c_rint :: CDouble -> CDouble
251 foreign import ccall unsafe "rintf"
252 c_rintf :: CFloat -> CFloat
253 foreign import ccall unsafe "lrint"
254 c_lrint :: CDouble -> CLong
255 foreign import ccall unsafe "lrintf"
256 c_lrintf :: CFloat -> CLong
257 foreign import ccall unsafe "llrint"
258 c_llrint :: CDouble -> CLLong
259 foreign import ccall unsafe "llrintf"
260 c_llrintf :: CFloat -> CLLong
261 foreign import ccall unsafe "round"
262 c_round :: CDouble -> CDouble
263 foreign import ccall unsafe "roundf"
264 c_roundf :: CFloat -> CFloat
265 foreign import ccall unsafe "lround"
266 c_lround :: CDouble -> CLong
267 foreign import ccall unsafe "lroundf"
268 c_lroundf :: CFloat -> CLong
269 foreign import ccall unsafe "llround"
270 c_llround :: CDouble -> CLLong
271 foreign import ccall unsafe "llroundf"
272 c_llroundf :: CFloat -> CLLong
273 foreign import ccall unsafe "trunc"
274 c_trunc :: CDouble -> CDouble
275 foreign import ccall unsafe "truncf"
276 c_truncf :: CFloat -> CFloat
278 -- 7.12.10 Remainder functions
279 foreign import ccall unsafe "fmod"
280 c_fmod :: CDouble -> CDouble -> CDouble
281 foreign import ccall unsafe "fmodf"
282 c_fmodf :: CFloat -> CFloat -> CFloat
283 foreign import ccall unsafe "remainder"
284 c_remainder :: CDouble -> CDouble -> CDouble
285 foreign import ccall unsafe "remainderf"
286 c_remainderf :: CFloat -> CFloat -> CFloat
287 foreign import ccall unsafe "remquo"
288 c_remquo :: CDouble -> CDouble -> Ptr CInt -> IO CDouble
289 foreign import ccall unsafe "remquof"
290 c_remquof :: CFloat -> CFloat -> Ptr CInt -> IO CFloat
292 -- 7.12.11 Manipulation functions
293 foreign import ccall unsafe "copysign"
294 c_copysign :: CDouble -> CDouble -> CDouble
295 foreign import ccall unsafe "copysignf"
296 c_copysignf :: CFloat -> CFloat -> CFloat
297 foreign import ccall unsafe "nan"
298 c_nan :: CString -> IO CDouble
299 foreign import ccall unsafe "nanf"
300 c_nanf :: CString -> IO CFloat
301 foreign import ccall unsafe "nextafter"
302 c_nextafter :: CDouble -> CDouble -> CDouble
303 foreign import ccall unsafe "nextafterf"
304 c_nextafterf :: CFloat -> CFloat -> CFloat
305 -- no nexttoward until we have a long double type.
307 -- 7.12.12 Maximum, minimum, and positive difference functions
308 foreign import ccall unsafe "fdim"
309 c_fdim :: CDouble -> CDouble -> CDouble
310 foreign import ccall unsafe "fdimf"
311 c_fdimf :: CFloat -> CFloat -> CFloat
312 foreign import ccall unsafe "fmax"
313 c_fmax :: CDouble -> CDouble -> CDouble
314 foreign import ccall unsafe "fmaxf"
315 c_fmaxf :: CFloat -> CFloat -> CFloat
316 foreign import ccall unsafe "fmin"
317 c_fmin :: CDouble -> CDouble -> CDouble
318 foreign import ccall unsafe "fminf"
319 c_fminf :: CFloat -> CFloat -> CFloat
321 -- 7.12.13 Floating multiply-add
322 foreign import ccall unsafe "fma"
323 c_fma :: CDouble -> CDouble -> CDouble -> CDouble
324 foreign import ccall unsafe "fmaf"
325 c_fmaf :: CFloat -> CFloat -> CFloat -> CFloat