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