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