FreeBSD and NetBSD both use derivates of Sun's math library. On FreeBSD,
[dragonfly.git] / include / math.h
1 /*      $NetBSD: math.h,v 1.40 2005/02/03 04:39:32 perry Exp $  */
2
3 /*
4  * ====================================================
5  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6  *
7  * Developed at SunPro, a Sun Microsystems, Inc. business.
8  * Permission to use, copy, modify, and distribute this
9  * software is freely granted, provided that this notice
10  * is preserved.
11  * ====================================================
12  *
13  * $NetBSD: math.h,v 1.40 2005/02/03 04:39:32 perry Exp $
14  * $DragonFly: src/include/math.h,v 1.5 2005/07/26 21:15:19 joerg Exp $
15  */
16
17 /*
18  * @(#)fdlibm.h 5.1 93/09/24
19  */
20
21 #ifndef _MATH_H_
22 #define _MATH_H_
23
24 #include <sys/cdefs.h>
25
26 union __float_u {
27         unsigned char __dummy[sizeof(float)];
28         float __val;
29 };
30
31 union __double_u {
32         unsigned char __dummy[sizeof(double)];
33         double __val;
34 };
35
36 union __long_double_u {
37         unsigned char __dummy[sizeof(long double)];
38         long double __val;
39 };
40
41 #include <machine/math.h>
42
43 #ifdef __HAVE_LONG_DOUBLE
44 #define __fpmacro_unary_floating(__name, __arg0)                        \
45         /* LINTED */                                                    \
46         ((sizeof (__arg0) == sizeof (float))                            \
47         ?       __ ## __name ## f (__arg0)                              \
48         : (sizeof (__arg0) == sizeof (double))                          \
49         ?       __ ## __name ## d (__arg0)                              \
50         :       __ ## __name ## l (__arg0))
51 #else
52 #define __fpmacro_unary_floating(__name, __arg0)                        \
53         /* LINTED */                                                    \
54         ((sizeof (__arg0) == sizeof (float))                            \
55         ?       __ ## __name ## f (__arg0)                              \
56         :       __ ## __name ## d (__arg0))
57 #endif /* __HAVE_LONG_DOUBLE */
58
59 /*
60  * ANSI/POSIX
61  */
62 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
63 extern __const union __double_u __infinity;
64 #define HUGE_VAL        __infinity.__val
65
66 /*
67  * ISO C99
68  */
69 #if __ISO_C_VISIBLE >= 1999
70 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
71 extern __const union __float_u __infinityf;
72 #define HUGE_VALF       __infinityf.__val
73
74 extern __const union __long_double_u __infinityl;
75 #define HUGE_VALL       __infinityl.__val
76
77 /* 7.12#4 INFINITY */
78 #ifdef __INFINITY
79 #define INFINITY        __INFINITY      /* float constant which overflows */
80 #else
81 #define INFINITY        HUGE_VALF       /* positive infinity */
82 #endif /* __INFINITY */
83
84 /* 7.12#5 NAN: a quiet NaN, if supported */
85 #ifdef __HAVE_NANF
86 extern __const union __float_u __nanf;
87 #define NAN             __nanf.__val
88 #endif /* __HAVE_NANF */
89
90 /* 7.12#6 number classification macros */
91 #define FP_INFINITE     0x00
92 #define FP_NAN          0x01
93 #define FP_NORMAL       0x02
94 #define FP_SUBNORMAL    0x03
95 #define FP_ZERO         0x04
96 /* NetBSD extensions */
97 #define _FP_LOMD        0x80            /* range for machine-specific classes */
98 #define _FP_HIMD        0xff
99
100 #endif /* ISO C99 */
101
102 /*
103  * XOPEN/SVID
104  */
105 #if __XSI_VISIBLE > 0
106 #define M_E             2.7182818284590452354   /* e */
107 #define M_LOG2E         1.4426950408889634074   /* log 2e */
108 #define M_LOG10E        0.43429448190325182765  /* log 10e */
109 #define M_LN2           0.69314718055994530942  /* log e2 */
110 #define M_LN10          2.30258509299404568402  /* log e10 */
111 #define M_PI            3.14159265358979323846  /* pi */
112 #define M_PI_2          1.57079632679489661923  /* pi/2 */
113 #define M_PI_4          0.78539816339744830962  /* pi/4 */
114 #define M_1_PI          0.31830988618379067154  /* 1/pi */
115 #define M_2_PI          0.63661977236758134308  /* 2/pi */
116 #define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi) */
117 #define M_SQRT2         1.41421356237309504880  /* sqrt(2) */
118 #define M_SQRT1_2       0.70710678118654752440  /* 1/sqrt(2) */
119
120 #define MAXFLOAT        ((float)3.40282346638528860e+38)
121 extern int signgam;
122 #endif /* _XSI_VISIBLE */
123
124 #if __DF_VISIBLE
125 #define HUGE            MAXFLOAT
126
127 /*
128  * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
129  * (one may replace the following line by "#include <values.h>")
130  */
131
132 #define X_TLOSS         1.41484755040568800000e+16
133
134 #define DOMAIN          1
135 #define SING            2
136 #define OVERFLOW        3
137 #define UNDERFLOW       4
138 #define TLOSS           5
139 #define PLOSS           6
140
141 #endif /* __DF_VISIBLE */
142
143 __BEGIN_DECLS
144 /*
145  * ANSI/POSIX
146  */
147 double  acos(double);
148 double  asin(double);
149 double  atan(double);
150 double  atan2(double, double);
151 double  cos(double);
152 double  sin(double);
153 double  tan(double);
154
155 double  cosh(double);
156 double  sinh(double);
157 double  tanh(double);
158
159 double  exp(double);
160 double  frexp(double, int *);
161 double  ldexp(double, int);
162 double  log(double);
163 double  log10(double);
164 double  modf(double, double *);
165
166 double  pow(double, double);
167 double  sqrt(double);
168
169 double  ceil(double);
170 double  fabs(double);
171 double  floor(double);
172 double  fmod(double, double);
173
174 #if __XSI_VISIBLE > 0
175 double  erf(double);
176 double  erfc(double);
177 double  gamma(double);
178 double  hypot(double, double);
179 int     finite(double);
180 double  j0(double);
181 double  j1(double);
182 double  jn(int, double);
183 double  lgamma(double);
184 double  y0(double);
185 double  y1(double);
186 double  yn(int, double);
187 #endif /* __XSI_VISIBLE */
188
189 #if __XSI_VISIBLE >= 500
190 double  acosh(double);
191 double  asinh(double);
192 double  atanh(double);
193 double  cbrt(double);
194 double  expm1(double);
195 int     ilogb(double);
196 double  log1p(double);
197 double  logb(double);
198 double  nextafter(double, double);
199 double  remainder(double, double);
200 double  rint(double);
201 double  scalb(double, double);
202 #endif /* __XSI_VISIBLE >= 500 */
203
204 /*
205  * ISO C99
206  */
207 #if __ISO_C_VISIBLE >= 1999
208 /* 7.12.3.1 int fpclassify(real-floating x) */
209 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
210
211 /* 7.12.3.2 int isfinite(real-floating x) */
212 #define isfinite(__x)   __fpmacro_unary_floating(isfinite, __x)
213
214 /* 7.12.3.5 int isnormal(real-floating x) */
215 #define isnormal(__x)   (fpclassify(__x) == FP_NORMAL)
216
217 /* 7.12.3.6 int signbit(real-floating x) */
218 #define signbit(__x)    __fpmacro_unary_floating(signbit, __x)
219
220 /* 7.12.4 trigonometric */
221
222 float   acosf(float);
223 float   asinf(float);
224 float   atanf(float);
225 float   atan2f(float, float);
226 float   cosf(float);
227 float   sinf(float);
228 float   tanf(float);
229
230 /* 7.12.5 hyperbolic */
231
232 float   acoshf(float);
233 float   asinhf(float);
234 float   atanhf(float);
235 float   coshf(float);
236 float   sinhf(float);
237 float   tanhf(float);
238
239 /* 7.12.6 exp / log */
240
241 float   expf(float);
242 float   expm1f(float);
243 float   frexpf(float, int *);
244 int     ilogbf(float);
245 float   ldexpf(float, int);
246 float   logf(float);
247 float   log10f(float);
248 float   log1pf(float);
249 float   logbf(float);
250 float   modff(float, float *);
251 float   scalbnf(float, int);
252
253 /* 7.12.7 power / absolute */
254
255 float   cbrtf(float);
256 float   fabsf(float);
257 float   hypotf(float, float);
258 float   powf(float, float);
259 float   sqrtf(float);
260
261 /* 7.12.8 error / gamma */
262
263 float   erff(float);
264 float   erfcf(float);
265 float   lgammaf(float);
266
267 /* 7.12.9 nearest integer */
268
269 float   ceilf(float);
270 float   floorf(float);
271 float   rintf(float);
272 double  round(double);
273 float   roundf(float);
274 long int        lrint(double);
275 long int        lrintf(float);
276 /* LONGLONG */
277 long long int   llrint(double);
278 /* LONGLONG */
279 long long int   llrintf(float);
280 long int        lround(double);
281 long int        lroundf(float);
282 /* LONGLONG */
283 long long int   llround(double);
284 /* LONGLONG */
285 long long int   llroundf(float);
286
287 /* 7.12.10 remainder */
288
289 float   fmodf(float, float);
290 float   remainderf(float, float);
291
292 /* 7.2.11 manipulation */
293
294 float   copysignf(float, float);
295 float   nextafterf(float, float);
296
297 #endif /* __ISO_C_VISIBLE >= 1999 */
298
299 #if __ISO_C_VISIBLE >= 1999
300 /* 7.12.3.3 int isinf(real-floating x) */
301 #ifdef __isinf
302 #define isinf(__x)      __isinf(__x)
303 #else
304 #define isinf(__x)      __fpmacro_unary_floating(isinf, __x)
305 #endif
306
307 /* 7.12.3.4 int isnan(real-floating x) */
308 #ifdef __isnan
309 #define isnan(__x)      __isnan(__x)
310 #else
311 #define isnan(__x)      __fpmacro_unary_floating(isnan, __x)
312 #endif
313 #endif /* __ISO_C_VISIBLE >= 1999 */
314
315 #if __DF_VISIBLE
316 /*
317  * IEEE Test Vector
318  */
319 double  significand(double);
320
321 /*
322  * Functions callable from C, intended to support IEEE arithmetic.
323  */
324 double  copysign(double, double);
325 double  scalbn(double, int);
326
327 /*
328  * BSD math library entry points
329  */
330 double  drem(double, double);
331
332 /*
333  * Reentrant version of gamma & lgamma; passes signgam back by reference
334  * as the second argument; user must allocate space for signgam.
335  */
336 double  gamma_r(double, int *);
337 double  lgamma_r(double, int *);
338 #endif /* __DF_VISIBLE */
339
340
341 #if __DF_VISIBLE
342
343 /* float versions of ANSI/POSIX functions */
344
345 float   gammaf(float);
346 int     isinff(float);
347 int     isnanf(float);
348 int     finitef(float);
349 float   j0f(float);
350 float   j1f(float);
351 float   jnf(int, float);
352 float   y0f(float);
353 float   y1f(float);
354 float   ynf(int, float);
355
356 float   scalbf(float, float);
357
358 /*
359  * float version of IEEE Test Vector
360  */
361 float   significandf(float);
362
363 /*
364  * float versions of BSD math library entry points
365  */
366 float   dremf(float, float);
367
368 /*
369  * Float versions of reentrant version of gamma & lgamma; passes
370  * signgam back by reference as the second argument; user must
371  * allocate space for signgam.
372  */
373 float   gammaf_r(float, int *);
374 float   lgammaf_r(float, int *);
375 #endif /* __DF_VISIBLE */
376
377 /*
378  * Library implementation
379  */
380 int     __fpclassifyf(float);
381 int     __fpclassifyd(double);
382 int     __isfinitef(float);
383 int     __isfinited(double);
384 int     __isinff(float);
385 int     __isinfd(double);
386 int     __isnanf(float);
387 int     __isnand(double);
388 int     __signbitf(float);
389 int     __signbitd(double);
390
391 #ifdef __HAVE_LONG_DOUBLE
392 int     __fpclassifyl(long double);
393 int     __isfinitel(long double);
394 int     __isinfl(long double);
395 int     __isnanl(long double);
396 int     __signbitl(long double);
397 #endif
398 __END_DECLS
399
400 #endif /* _MATH_H_ */