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