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