xref: /openbsd/include/math.h (revision 898184e3)
1 /*	$OpenBSD: math.h,v 1.31 2012/12/05 23:19:57 deraadt Exp $	*/
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 
13 /*
14  * from: @(#)fdlibm.h 5.1 93/09/24
15  */
16 
17 #ifndef _MATH_H_
18 #define _MATH_H_
19 
20 #include <sys/_types.h>
21 #include <sys/limits.h>
22 
23 __BEGIN_DECLS
24 /*
25  * ANSI/POSIX
26  */
27 extern char __infinity[];
28 #if __GNUC_PREREQ__(3, 3)
29 #define HUGE_VAL	__builtin_huge_val()
30 #else /* __GNUC_PREREQ__(3, 3) */
31 #define HUGE_VAL	(*(double *)(void *)__infinity)
32 #endif /* __GNUC_PREREQ__(3, 3) */
33 
34 /*
35  * C99
36  */
37 #if __ISO_C_VISIBLE >= 1999
38 typedef	__double_t	double_t;
39 typedef	__float_t	float_t;
40 
41 #if __GNUC_PREREQ__(3, 3)
42 #define	HUGE_VALF	__builtin_huge_valf()
43 #define	HUGE_VALL	__builtin_huge_vall()
44 #define	INFINITY	__builtin_inff()
45 #define	NAN		__builtin_nanf("")
46 #else /* __GNUC_PREREQ__(3, 3) */
47 #ifdef __vax__
48 extern char __infinityf[];
49 #define	HUGE_VALF	(*(float *)(void *)__infinityf)
50 #else /* __vax__ */
51 #define	HUGE_VALF	((float)HUGE_VAL)
52 #endif /* __vax__ */
53 #define	HUGE_VALL	((long double)HUGE_VAL)
54 #define	INFINITY	HUGE_VALF
55 #ifndef __vax__
56 extern char __nan[];
57 #define	NAN		(*(float *)(void *)__nan)
58 #endif /* !__vax__ */
59 #endif /* __GNUC_PREREQ__(3, 3) */
60 
61 #define	FP_INFINITE	0x01
62 #define	FP_NAN		0x02
63 #define	FP_NORMAL	0x04
64 #define	FP_SUBNORMAL	0x08
65 #define	FP_ZERO		0x10
66 
67 #define FP_ILOGB0	(-INT_MAX)
68 #define FP_ILOGBNAN	INT_MAX
69 
70 #define fpclassify(x) \
71 	((sizeof (x) == sizeof (float)) ? \
72 		__fpclassifyf(x) \
73 	: (sizeof (x) == sizeof (double)) ? \
74 		__fpclassify(x) \
75 	:	__fpclassifyl(x))
76 #define isfinite(x) \
77 	((sizeof (x) == sizeof (float)) ? \
78 		__isfinitef(x) \
79 	: (sizeof (x) == sizeof (double)) ? \
80 		__isfinite(x) \
81 	:	__isfinitel(x))
82 #define isnormal(x) \
83 	((sizeof (x) == sizeof (float)) ? \
84 		__isnormalf(x) \
85 	: (sizeof (x) == sizeof (double)) ? \
86 		__isnormal(x) \
87 	:	__isnormall(x))
88 #define signbit(x) \
89 	((sizeof (x) == sizeof (float)) ? \
90 		__signbitf(x) \
91 	: (sizeof (x) == sizeof (double)) ? \
92 		__signbit(x) \
93 	:	__signbitl(x))
94 
95 #define	isgreater(x, y)		(!isunordered((x), (y)) && (x) > (y))
96 #define	isgreaterequal(x, y)	(!isunordered((x), (y)) && (x) >= (y))
97 #define	isless(x, y)		(!isunordered((x), (y)) && (x) < (y))
98 #define	islessequal(x, y)	(!isunordered((x), (y)) && (x) <= (y))
99 #define	islessgreater(x, y)	(!isunordered((x), (y)) && \
100 					((x) > (y) || (y) > (x)))
101 #define	isunordered(x, y)	(isnan(x) || isnan(y))
102 #endif /* __ISO_C_VISIBLE >= 1999 */
103 
104 #define isinf(x) \
105 	((sizeof (x) == sizeof (float)) ? \
106 		__isinff(x) \
107 	: (sizeof (x) == sizeof (double)) ? \
108 		__isinf(x) \
109 	:	__isinfl(x))
110 #define isnan(x) \
111 	((sizeof (x) == sizeof (float)) ? \
112 		__isnanf(x) \
113 	: (sizeof (x) == sizeof (double)) ? \
114 		__isnan(x) \
115 	:	__isnanl(x))
116 
117 /*
118  * XOPEN/SVID
119  */
120 #if __BSD_VISIBLE || __XPG_VISIBLE
121 #define	M_E		2.7182818284590452354	/* e */
122 #define	M_LOG2E		1.4426950408889634074	/* log 2e */
123 #define	M_LOG10E	0.43429448190325182765	/* log 10e */
124 #define	M_LN2		0.69314718055994530942	/* log e2 */
125 #define	M_LN10		2.30258509299404568402	/* log e10 */
126 #define	M_PI		3.14159265358979323846	/* pi */
127 #define	M_PI_2		1.57079632679489661923	/* pi/2 */
128 #define	M_PI_4		0.78539816339744830962	/* pi/4 */
129 #define	M_1_PI		0.31830988618379067154	/* 1/pi */
130 #define	M_2_PI		0.63661977236758134308	/* 2/pi */
131 #define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
132 #define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
133 #define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
134 
135 #ifdef __vax__
136 #define	MAXFLOAT	((float)1.70141173319264430e+38)
137 #else
138 #define	MAXFLOAT	((float)3.40282346638528860e+38)
139 #endif /* __vax__ */
140 
141 extern int signgam;
142 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
143 
144 #if __BSD_VISIBLE
145 #define	HUGE		MAXFLOAT
146 #endif /* __BSD_VISIBLE */
147 
148 /*
149  * ANSI/POSIX
150  */
151 double acos(double);
152 double asin(double);
153 double atan(double);
154 double atan2(double, double);
155 double cos(double);
156 double sin(double);
157 double tan(double);
158 
159 double cosh(double);
160 double sinh(double);
161 double tanh(double);
162 
163 double exp(double);
164 double frexp(double, int *);
165 double ldexp(double, int);
166 double log(double);
167 double log10(double);
168 double modf(double, double *);
169 
170 double pow(double, double);
171 double sqrt(double);
172 
173 double ceil(double);
174 double fabs(double);
175 double floor(double);
176 double fmod(double, double);
177 
178 /*
179  * C99
180  */
181 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE
182 double acosh(double);
183 double asinh(double);
184 double atanh(double);
185 
186 double exp2(double);
187 double expm1(double);
188 int ilogb(double);
189 double log1p(double);
190 double log2(double);
191 double logb(double);
192 double scalbn(double, int);
193 double scalbln(double, long int);
194 
195 double cbrt(double);
196 double hypot(double, double);
197 
198 double erf(double);
199 double erfc(double);
200 double lgamma(double);
201 double tgamma(double);
202 
203 double nearbyint(double);
204 double rint(double);
205 long int lrint(double);
206 long long int llrint(double);
207 double round(double);
208 long int lround(double);
209 long long int llround(double);
210 double trunc(double);
211 
212 double remainder(double, double);
213 double remquo(double, double, int *);
214 
215 double copysign(double, double);
216 double nan(const char *);
217 double nextafter(double, double);
218 double nexttoward(double, long double);
219 
220 double fdim(double, double);
221 double fmax(double, double);
222 double fmin(double, double);
223 
224 double fma(double, double, double);
225 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE */
226 
227 #if __BSD_VISIBLE || __XPG_VISIBLE
228 double j0(double);
229 double j1(double);
230 double jn(int, double);
231 double scalb(double, double);
232 double y0(double);
233 double y1(double);
234 double yn(int, double);
235 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
236 
237 #if __BSD_VISIBLE || __XPG_VISIBLE <= 500
238 double gamma(double);
239 #endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
240 
241 /*
242  * BSD math library entry points
243  */
244 #if __BSD_VISIBLE
245 double drem(double, double);
246 int finite(double);
247 
248 /*
249  * Reentrant version of gamma & lgamma; passes signgam back by reference
250  * as the second argument; user must allocate space for signgam.
251  */
252 double gamma_r(double, int *);
253 double lgamma_r(double, int *);
254 
255 /*
256  * IEEE Test Vector
257  */
258 double significand(double);
259 #endif /* __BSD_VISIBLE */
260 
261 /*
262  * Float versions of C99 functions
263  */
264 #if __ISO_C_VISIBLE >= 1999
265 float acosf(float);
266 float asinf(float);
267 float atanf(float);
268 float atan2f(float, float);
269 float cosf(float);
270 float sinf(float);
271 float tanf(float);
272 
273 float acoshf(float);
274 float asinhf(float);
275 float atanhf(float);
276 float coshf(float);
277 float sinhf(float);
278 float tanhf(float);
279 
280 float expf(float);
281 float exp2f(float);
282 float expm1f(float);
283 float frexpf(float, int *);
284 int ilogbf(float);
285 float ldexpf(float, int);
286 float logf(float);
287 float log10f(float);
288 float log1pf(float);
289 float log2f(float);
290 float logbf(float);
291 float modff(float, float *);
292 float scalbnf(float, int);
293 float scalblnf(float, long int);
294 
295 float cbrtf(float);
296 float fabsf(float);
297 float hypotf(float, float);
298 float powf(float, float);
299 float sqrtf(float);
300 
301 float erff(float);
302 float erfcf(float);
303 float lgammaf(float);
304 float tgammaf(float);
305 
306 float ceilf(float);
307 float floorf(float);
308 float nearbyintf(float);
309 float rintf(float);
310 long int lrintf(float);
311 long long int llrintf(float);
312 float roundf(float);
313 long int lroundf(float);
314 long long int llroundf(float);
315 float truncf(float);
316 
317 float fmodf(float, float);
318 float remainderf(float, float);
319 float remquof(float, float, int *);
320 
321 float copysignf(float, float);
322 float nanf(const char *);
323 float nextafterf(float, float);
324 float nexttowardf(float, long double);
325 
326 float fdimf(float, float);
327 float fmaxf(float, float);
328 float fminf(float, float);
329 
330 float fmaf(float, float, float);
331 #endif /* __ISO_C_VISIBLE >= 1999 */
332 
333 #if __BSD_VISIBLE || __XPG_VISIBLE
334 float j0f(float);
335 float j1f(float);
336 float jnf(int, float);
337 float scalbf(float, float);
338 float y0f(float);
339 float y1f(float);
340 float ynf(int, float);
341 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
342 
343 #if __BSD_VISIBLE || __XPG_VISIBLE <= 500
344 float gammaf(float);
345 #endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
346 
347 /*
348  * Float versions of BSD math library entry points
349  */
350 #if __BSD_VISIBLE
351 float dremf(float, float);
352 int finitef(float);
353 int isinff(float);
354 int isnanf(float);
355 
356 /*
357  * Float versions of reentrant version of gamma & lgamma; passes
358  * signgam back by reference as the second argument; user must
359  * allocate space for signgam.
360  */
361 float gammaf_r(float, int *);
362 float lgammaf_r(float, int *);
363 
364 /*
365  * Float version of IEEE Test Vector
366  */
367 float significandf(float);
368 #endif /* __BSD_VISIBLE */
369 
370 /*
371  * Long double versions of C99 functions
372  */
373 #if __ISO_C_VISIBLE >= 1999
374 long double acosl(long double);
375 long double asinl(long double);
376 long double atanl(long double);
377 long double atan2l(long double, long double);
378 long double cosl(long double);
379 long double sinl(long double);
380 long double tanl(long double);
381 
382 long double acoshl(long double);
383 long double asinhl(long double);
384 long double atanhl(long double);
385 long double coshl(long double);
386 long double sinhl(long double);
387 long double tanhl(long double);
388 
389 long double expl(long double);
390 long double exp2l(long double);
391 long double expm1l(long double);
392 long double frexpl(long double, int *);
393 int ilogbl(long double);
394 long double ldexpl(long double, int);
395 long double logl(long double);
396 long double log10l(long double);
397 long double log1pl(long double);
398 long double log2l(long double);
399 long double logbl(long double);
400 long double modfl(long double, long double *);
401 long double scalbnl(long double, int);
402 long double scalblnl(long double, long int);
403 
404 long double cbrtl(long double);
405 long double fabsl(long double);
406 long double hypotl(long double, long double);
407 long double powl(long double, long double);
408 long double sqrtl(long double);
409 
410 long double erfl(long double);
411 long double erfcl(long double);
412 long double lgammal(long double);
413 long double tgammal(long double);
414 
415 long double ceill(long double);
416 long double floorl(long double);
417 long double nearbyintl(long double);
418 long double rintl(long double);
419 long int lrintl(long double);
420 long long int llrintl(long double);
421 long double roundl(long double);
422 long int lroundl(long double);
423 long long int llroundl(long double);
424 long double truncl(long double);
425 
426 long double fmodl(long double, long double);
427 long double remainderl(long double, long double);
428 long double remquol(long double, long double, int *);
429 
430 long double copysignl(long double, long double);
431 long double nanl(const char *);
432 long double nextafterl(long double, long double);
433 long double nexttowardl(long double, long double);
434 
435 long double fdiml(long double, long double);
436 long double fmaxl(long double, long double);
437 long double fminl(long double, long double);
438 
439 long double fmal(long double, long double, long double);
440 #endif /* __ISO_C_VISIBLE >= 1999 */
441 
442 /*
443  * Library implementation
444  */
445 int __fpclassify(double);
446 int __fpclassifyf(float);
447 int __fpclassifyl(long double);
448 int __isfinite(double);
449 int __isfinitef(float);
450 int __isfinitel(long double);
451 int __isinf(double);
452 int __isinff(float);
453 int __isinfl(long double);
454 int __isnan(double);
455 int __isnanf(float);
456 int __isnanl(long double);
457 int __isnormal(double);
458 int __isnormalf(float);
459 int __isnormall(long double);
460 int __signbit(double);
461 int __signbitf(float);
462 int __signbitl(long double);
463 
464 #if __BSD_VISIBLE && defined(__vax__)
465 double infnan(int);
466 #endif /* __BSD_VISIBLE && defined(__vax__) */
467 __END_DECLS
468 
469 #endif /* !_MATH_H_ */
470