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