1 /* $OpenBSD: math.h,v 1.33 2014/05/03 16:13:03 martynas Exp $ */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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
10 * ====================================================
14 * from: @(#)fdlibm.h 5.1 93/09/24
20 #include <sys/_types.h>
21 #include <sys/limits.h>
27 extern char __infinity[];
28 #if __GNUC_PREREQ__(3, 3) && !defined(__vax__)
29 #define HUGE_VAL __builtin_huge_val()
30 #else /* __GNUC_PREREQ__(3, 3) && !__vax__ */
31 #define HUGE_VAL (*(double *)(void *)__infinity)
32 #endif /* __GNUC_PREREQ__(3, 3) && !__vax__ */
37 #if __ISO_C_VISIBLE >= 1999
38 typedef __double_t double_t;
39 typedef __float_t float_t;
41 #if __GNUC_PREREQ__(3, 3) && !defined(__vax__)
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) && !__vax__ */
48 extern char __infinityf[];
49 #define HUGE_VALF (*(float *)(void *)__infinityf)
51 #define HUGE_VALF ((float)HUGE_VAL)
53 #define HUGE_VALL ((long double)HUGE_VAL)
54 #define INFINITY HUGE_VALF
57 #define NAN (*(float *)(void *)__nan)
59 #endif /* __GNUC_PREREQ__(3, 3) && !__vax__ */
61 #define FP_INFINITE 0x01
63 #define FP_NORMAL 0x04
64 #define FP_SUBNORMAL 0x08
67 #define FP_ILOGB0 (-INT_MAX)
68 #define FP_ILOGBNAN INT_MAX
70 #define fpclassify(x) \
71 ((sizeof (x) == sizeof (float)) ? \
73 : (sizeof (x) == sizeof (double)) ? \
77 ((sizeof (x) == sizeof (float)) ? \
79 : (sizeof (x) == sizeof (double)) ? \
83 ((sizeof (x) == sizeof (float)) ? \
85 : (sizeof (x) == sizeof (double)) ? \
89 ((sizeof (x) == sizeof (float)) ? \
91 : (sizeof (x) == sizeof (double)) ? \
95 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
96 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
97 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
98 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
99 #define islessgreater(x, y) (!isunordered((x), (y)) && \
100 ((x) > (y) || (y) > (x)))
101 #define isunordered(x, y) (isnan(x) || isnan(y))
102 #endif /* __ISO_C_VISIBLE >= 1999 */
105 ((sizeof (x) == sizeof (float)) ? \
107 : (sizeof (x) == sizeof (double)) ? \
111 ((sizeof (x) == sizeof (float)) ? \
113 : (sizeof (x) == sizeof (double)) ? \
120 #if __BSD_VISIBLE || __XPG_VISIBLE
121 #define M_E ((double)2.7182818284590452354) /* e */
122 #define M_LOG2E ((double)1.4426950408889634074) /* log 2e */
123 #define M_LOG10E ((double)0.43429448190325182765) /* log 10e */
124 #define M_LN2 ((double)0.69314718055994530942) /* log e2 */
125 #define M_LN10 ((double)2.30258509299404568402) /* log e10 */
126 #define M_PI ((double)3.14159265358979323846) /* pi */
127 #define M_PI_2 ((double)1.57079632679489661923) /* pi/2 */
128 #define M_PI_4 ((double)0.78539816339744830962) /* pi/4 */
129 #define M_1_PI ((double)0.31830988618379067154) /* 1/pi */
130 #define M_2_PI ((double)0.63661977236758134308) /* 2/pi */
131 #define M_2_SQRTPI ((double)1.12837916709551257390) /* 2/sqrt(pi) */
132 #define M_SQRT2 ((double)1.41421356237309504880) /* sqrt(2) */
133 #define M_SQRT1_2 ((double)0.70710678118654752440) /* 1/sqrt(2) */
136 #define MAXFLOAT ((float)1.70141173319264430e+38)
138 #define MAXFLOAT ((float)3.40282346638528860e+38)
142 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
144 #if __POSIX_VISIBLE >= 201403
145 #define M_El 2.718281828459045235360287471352662498L /* e */
146 #define M_LOG2El 1.442695040888963407359924681001892137L /* log 2e */
147 #define M_LOG10El 0.434294481903251827651128918916605082L /* log 10e */
148 #define M_LN2l 0.693147180559945309417232121458176568L /* log e2 */
149 #define M_LN10l 2.302585092994045684017991454684364208L /* log e10 */
150 #define M_PIl 3.141592653589793238462643383279502884L /* pi */
151 #define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
152 #define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
153 #define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
154 #define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
155 #define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
156 #define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
157 #define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
158 #endif /* __POSIX_VISIBLE >= 201403 */
161 #define HUGE MAXFLOAT
162 #endif /* __BSD_VISIBLE */
170 double atan2(double, double);
180 double frexp(double, int *);
181 double ldexp(double, int);
183 double log10(double);
184 double modf(double, double *);
186 double pow(double, double);
191 double floor(double);
192 double fmod(double, double);
197 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE
198 double acosh(double);
199 double asinh(double);
200 double atanh(double);
203 double expm1(double);
205 double log1p(double);
208 double scalbn(double, int);
209 double scalbln(double, long int);
212 double hypot(double, double);
216 double lgamma(double);
217 double tgamma(double);
219 double nearbyint(double);
221 long int lrint(double);
222 long long int llrint(double);
223 double round(double);
224 long int lround(double);
225 long long int llround(double);
226 double trunc(double);
228 double remainder(double, double);
229 double remquo(double, double, int *);
231 double copysign(double, double);
232 double nan(const char *);
233 double nextafter(double, double);
234 double nexttoward(double, long double);
236 double fdim(double, double);
237 double fmax(double, double);
238 double fmin(double, double);
240 double fma(double, double, double);
241 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE */
243 #if __BSD_VISIBLE || __XPG_VISIBLE
246 double jn(int, double);
247 double scalb(double, double);
250 double yn(int, double);
251 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
253 #if __BSD_VISIBLE || __XPG_VISIBLE <= 500
254 double gamma(double);
255 #endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
258 * BSD math library entry points
261 double drem(double, double);
265 * Reentrant version of gamma & lgamma; passes signgam back by reference
266 * as the second argument; user must allocate space for signgam.
268 double gamma_r(double, int *);
269 double lgamma_r(double, int *);
274 double significand(double);
275 #endif /* __BSD_VISIBLE */
278 * Float versions of C99 functions
280 #if __ISO_C_VISIBLE >= 1999
284 float atan2f(float, float);
299 float frexpf(float, int *);
301 float ldexpf(float, int);
307 float modff(float, float *);
308 float scalbnf(float, int);
309 float scalblnf(float, long int);
313 float hypotf(float, float);
314 float powf(float, float);
319 float lgammaf(float);
320 float tgammaf(float);
324 float nearbyintf(float);
326 long int lrintf(float);
327 long long int llrintf(float);
329 long int lroundf(float);
330 long long int llroundf(float);
333 float fmodf(float, float);
334 float remainderf(float, float);
335 float remquof(float, float, int *);
337 float copysignf(float, float);
338 float nanf(const char *);
339 float nextafterf(float, float);
340 float nexttowardf(float, long double);
342 float fdimf(float, float);
343 float fmaxf(float, float);
344 float fminf(float, float);
346 float fmaf(float, float, float);
347 #endif /* __ISO_C_VISIBLE >= 1999 */
349 #if __BSD_VISIBLE || __XPG_VISIBLE
352 float jnf(int, float);
353 float scalbf(float, float);
356 float ynf(int, float);
357 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
359 #if __BSD_VISIBLE || __XPG_VISIBLE <= 500
361 #endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
364 * Float versions of BSD math library entry points
367 float dremf(float, float);
373 * Float versions of reentrant version of gamma & lgamma; passes
374 * signgam back by reference as the second argument; user must
375 * allocate space for signgam.
377 float gammaf_r(float, int *);
378 float lgammaf_r(float, int *);
381 * Float version of IEEE Test Vector
383 float significandf(float);
384 #endif /* __BSD_VISIBLE */
387 * Long double versions of C99 functions
389 #if __ISO_C_VISIBLE >= 1999
390 long double acosl(long double);
391 long double asinl(long double);
392 long double atanl(long double);
393 long double atan2l(long double, long double);
394 long double cosl(long double);
395 long double sinl(long double);
396 long double tanl(long double);
398 long double acoshl(long double);
399 long double asinhl(long double);
400 long double atanhl(long double);
401 long double coshl(long double);
402 long double sinhl(long double);
403 long double tanhl(long double);
405 long double expl(long double);
406 long double exp2l(long double);
407 long double expm1l(long double);
408 long double frexpl(long double, int *);
409 int ilogbl(long double);
410 long double ldexpl(long double, int);
411 long double logl(long double);
412 long double log10l(long double);
413 long double log1pl(long double);
414 long double log2l(long double);
415 long double logbl(long double);
416 long double modfl(long double, long double *);
417 long double scalbnl(long double, int);
418 long double scalblnl(long double, long int);
420 long double cbrtl(long double);
421 long double fabsl(long double);
422 long double hypotl(long double, long double);
423 long double powl(long double, long double);
424 long double sqrtl(long double);
426 long double erfl(long double);
427 long double erfcl(long double);
428 long double lgammal(long double);
429 long double tgammal(long double);
431 long double ceill(long double);
432 long double floorl(long double);
433 long double nearbyintl(long double);
434 long double rintl(long double);
435 long int lrintl(long double);
436 long long int llrintl(long double);
437 long double roundl(long double);
438 long int lroundl(long double);
439 long long int llroundl(long double);
440 long double truncl(long double);
442 long double fmodl(long double, long double);
443 long double remainderl(long double, long double);
444 long double remquol(long double, long double, int *);
446 long double copysignl(long double, long double);
447 long double nanl(const char *);
448 long double nextafterl(long double, long double);
449 long double nexttowardl(long double, long double);
451 long double fdiml(long double, long double);
452 long double fmaxl(long double, long double);
453 long double fminl(long double, long double);
455 long double fmal(long double, long double, long double);
456 #endif /* __ISO_C_VISIBLE >= 1999 */
459 * Library implementation
461 int __fpclassify(double);
462 int __fpclassifyf(float);
463 int __fpclassifyl(long double);
464 int __isfinite(double);
465 int __isfinitef(float);
466 int __isfinitel(long double);
469 int __isinfl(long double);
472 int __isnanl(long double);
473 int __isnormal(double);
474 int __isnormalf(float);
475 int __isnormall(long double);
476 int __signbit(double);
477 int __signbitf(float);
478 int __signbitl(long double);
480 #if __BSD_VISIBLE && defined(__vax__)
482 #endif /* __BSD_VISIBLE && defined(__vax__) */
485 #endif /* !_MATH_H_ */