1 /* 2 * ==================================================== 3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 4 * 5 * Developed at SunPro, a Sun Microsystems, Inc. business. 6 * Permission to use, copy, modify, and distribute this 7 * software is freely granted, provided that this notice 8 * is preserved. 9 * ==================================================== 10 */ 11 12 /* 13 * from: @(#)fdlibm.h 5.1 93/09/24 14 * $FreeBSD$ 15 */ 16 17 #ifndef _MATH_H_ 18 #define _MATH_H_ 19 20 #include <sys/cdefs.h> 21 #include <sys/_types.h> 22 #include <machine/_limits.h> 23 24 /* 25 * ANSI/POSIX 26 */ 27 extern const union __infinity_un { 28 unsigned char __uc[8]; 29 double __ud; 30 } __infinity; 31 32 extern const union __nan_un { 33 unsigned char __uc[sizeof(float)]; 34 float __uf; 35 } __nan; 36 37 #if (defined(__GNUC__) && ((__GNUC__ >= 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4)) || defined(__INTEL_COMPILER) 38 #define __MATH_BUILTIN_CONSTANTS 39 #endif 40 41 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER)) 42 #define __MATH_BUILTIN_RELOPS 43 #endif 44 45 #ifdef __MATH_BUILTIN_CONSTANTS 46 #define HUGE_VAL __builtin_huge_val() 47 #else 48 #define HUGE_VAL (__infinity.__ud) 49 #endif 50 51 #if __ISO_C_VISIBLE >= 1999 52 #define FP_ILOGB0 (-__INT_MAX) 53 #define FP_ILOGBNAN __INT_MAX 54 55 #ifdef __MATH_BUILTIN_CONSTANTS 56 #define HUGE_VALF __builtin_huge_valf() 57 #define HUGE_VALL __builtin_huge_vall() 58 #define INFINITY __builtin_inf() 59 #define NAN __builtin_nan("") 60 #else 61 #define HUGE_VALF (float)HUGE_VAL 62 #define HUGE_VALL (long double)HUGE_VAL 63 #define INFINITY HUGE_VALF 64 #define NAN (__nan.__uf) 65 #endif /* __MATH_BUILTIN_CONSTANTS */ 66 67 #define MATH_ERRNO 1 68 #define MATH_ERREXCEPT 2 69 #define math_errhandling 0 70 71 /* Symbolic constants to classify floating point numbers. */ 72 #define FP_INFINITE 0x01 73 #define FP_NAN 0x02 74 #define FP_NORMAL 0x04 75 #define FP_SUBNORMAL 0x08 76 #define FP_ZERO 0x10 77 #define fpclassify(x) \ 78 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ 79 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ 80 : __fpclassifyl(x)) 81 82 #define isfinite(x) \ 83 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \ 84 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \ 85 : __isfinitel(x)) 86 #define isinf(x) \ 87 ((sizeof (x) == sizeof (float)) ? __isinff(x) \ 88 : (sizeof (x) == sizeof (double)) ? isinf(x) \ 89 : __isinfl(x)) 90 #define isnan(x) \ 91 ((sizeof (x) == sizeof (float)) ? isnanf(x) \ 92 : (sizeof (x) == sizeof (double)) ? isnan(x) \ 93 : __isnanl(x)) 94 #define isnormal(x) \ 95 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \ 96 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \ 97 : __isnormall(x)) 98 99 #ifdef __MATH_BUILTIN_RELOPS 100 #define isgreater(x, y) __builtin_isgreater((x), (y)) 101 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) 102 #define isless(x, y) __builtin_isless((x), (y)) 103 #define islessequal(x, y) __builtin_islessequal((x), (y)) 104 #define islessgreater(x, y) __builtin_islessgreater((x), (y)) 105 #define isunordered(x, y) __builtin_isunordered((x), (y)) 106 #else 107 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) 108 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) 109 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) 110 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) 111 #define islessgreater(x, y) (!isunordered((x), (y)) && \ 112 ((x) > (y) || (y) > (x))) 113 #define isunordered(x, y) (isnan(x) || isnan(y)) 114 #endif /* __MATH_BUILTIN_RELOPS */ 115 116 #define signbit(x) __signbit(x) 117 118 typedef __double_t double_t; 119 typedef __float_t float_t; 120 #endif /* __ISO_C_VISIBLE >= 1999 */ 121 122 /* 123 * XOPEN/SVID 124 */ 125 #if __BSD_VISIBLE || __XSI_VISIBLE 126 #define M_E 2.7182818284590452354 /* e */ 127 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 128 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 129 #define M_LN2 0.69314718055994530942 /* log e2 */ 130 #define M_LN10 2.30258509299404568402 /* log e10 */ 131 #define M_PI 3.14159265358979323846 /* pi */ 132 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 133 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 134 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 135 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 136 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 137 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 138 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 139 140 #define MAXFLOAT ((float)3.40282346638528860e+38) 141 extern int signgam; 142 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 143 144 #if __BSD_VISIBLE 145 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 146 147 #define _LIB_VERSION_TYPE enum fdversion 148 #define _LIB_VERSION _fdlib_version 149 150 /* if global variable _LIB_VERSION is not desirable, one may 151 * change the following to be a constant by: 152 * #define _LIB_VERSION_TYPE const enum version 153 * In that case, after one initializes the value _LIB_VERSION (see 154 * s_lib_version.c) during compile time, it cannot be modified 155 * in the middle of a program 156 */ 157 extern _LIB_VERSION_TYPE _LIB_VERSION; 158 159 #define _IEEE_ fdlibm_ieee 160 #define _SVID_ fdlibm_svid 161 #define _XOPEN_ fdlibm_xopen 162 #define _POSIX_ fdlibm_posix 163 164 /* We have a problem when using C++ since `exception' is a reserved 165 name in C++. */ 166 #ifndef __cplusplus 167 struct exception { 168 int type; 169 char *name; 170 double arg1; 171 double arg2; 172 double retval; 173 }; 174 #endif 175 176 #if 0 177 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 178 #define HUGE HUGE_VAL 179 #else 180 #define HUGE MAXFLOAT 181 #endif 182 183 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */ 184 185 #define DOMAIN 1 186 #define SING 2 187 #define OVERFLOW 3 188 #define UNDERFLOW 4 189 #define TLOSS 5 190 #define PLOSS 6 191 192 #endif /* __BSD_VISIBLE */ 193 194 /* 195 * Most of these functions have the side effect of setting errno, so they 196 * are not declared as __pure2. (XXX: this point needs to be revisited, 197 * since C99 doesn't require the mistake of setting errno, and we mostly 198 * don't set it anyway. In C99, pragmas and functions for changing the 199 * rounding mode affect the purity of these functions.) 200 */ 201 __BEGIN_DECLS 202 /* 203 * ANSI/POSIX 204 */ 205 int __fpclassifyd(double) __pure2; 206 int __fpclassifyf(float) __pure2; 207 int __fpclassifyl(long double) __pure2; 208 int __isfinitef(float) __pure2; 209 int __isfinite(double) __pure2; 210 int __isfinitel(long double) __pure2; 211 int __isinff(float) __pure2; 212 int __isinfl(long double) __pure2; 213 int __isnanl(long double) __pure2; 214 int __isnormalf(float) __pure2; 215 int __isnormal(double) __pure2; 216 int __isnormall(long double) __pure2; 217 int __signbit(double) __pure2; 218 219 double acos(double); 220 double asin(double); 221 double atan(double); 222 double atan2(double, double); 223 double cos(double); 224 double sin(double); 225 double tan(double); 226 227 double cosh(double); 228 double sinh(double); 229 double tanh(double); 230 231 double exp(double); 232 double frexp(double, int *); /* fundamentally !__pure2 */ 233 double ldexp(double, int); 234 double log(double); 235 double log10(double); 236 double modf(double, double *); /* fundamentally !__pure2 */ 237 238 double pow(double, double); 239 double sqrt(double); 240 241 double ceil(double); 242 double fabs(double); 243 double floor(double); 244 double fmod(double, double); 245 246 /* 247 * These functions are not in C90 so they can be "right". The ones that 248 * never set errno in lib/msun are declared as __pure2. 249 */ 250 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE 251 double acosh(double); 252 double asinh(double); 253 double atanh(double); 254 double cbrt(double) __pure2; 255 double erf(double); 256 double erfc(double) __pure2; 257 double expm1(double) __pure2; 258 double fdim(double, double); 259 double fmax(double, double) __pure2; 260 double fmin(double, double) __pure2; 261 double hypot(double, double); 262 int ilogb(double); 263 int (isinf)(double) __pure2; 264 int (isnan)(double) __pure2; 265 double lgamma(double); 266 double log1p(double) __pure2; 267 double logb(double) __pure2; 268 double nearbyint(double) __pure2; 269 double nextafter(double, double); 270 double remainder(double, double); 271 double rint(double) __pure2; 272 double round(double); 273 double trunc(double); 274 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ 275 276 #if __BSD_VISIBLE || __XSI_VISIBLE 277 double j0(double); 278 double j1(double); 279 double jn(int, double); 280 double scalb(double, double); 281 double y0(double); 282 double y1(double); 283 double yn(int, double); 284 285 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE 286 double gamma(double); 287 #endif 288 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 289 290 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 291 double copysign(double, double) __pure2; 292 double scalbln(double, long); 293 double scalbn(double, int); 294 double tgamma(double); 295 #endif 296 297 /* 298 * BSD math library entry points 299 */ 300 #if __BSD_VISIBLE 301 double drem(double, double); 302 int finite(double) __pure2; 303 int isnanf(float) __pure2; 304 305 /* 306 * Reentrant version of gamma & lgamma; passes signgam back by reference 307 * as the second argument; user must allocate space for signgam. 308 */ 309 double gamma_r(double, int *); 310 double lgamma_r(double, int *); 311 312 /* 313 * IEEE Test Vector 314 */ 315 double significand(double); 316 317 #ifndef __cplusplus 318 int matherr(struct exception *); 319 #endif 320 #endif /* __BSD_VISIBLE */ 321 322 /* float versions of ANSI/POSIX functions */ 323 #if __ISO_C_VISIBLE >= 1999 324 float acosf(float); 325 float asinf(float); 326 float atanf(float); 327 float atan2f(float, float); 328 float cosf(float); 329 float sinf(float); 330 float tanf(float); 331 332 float coshf(float); 333 float sinhf(float); 334 float tanhf(float); 335 336 float expf(float); 337 float expm1f(float) __pure2; 338 float frexpf(float, int *); /* fundamentally !__pure2 */ 339 int ilogbf(float); 340 float ldexpf(float, int); 341 float log10f(float); 342 float log1pf(float) __pure2; 343 float logf(float); 344 float modff(float, float *); /* fundamentally !__pure2 */ 345 346 float powf(float, float); 347 float sqrtf(float); 348 349 float ceilf(float); 350 float fabsf(float); 351 float floorf(float); 352 float fmodf(float, float); 353 float roundf(float); 354 355 float erff(float); 356 float erfcf(float) __pure2; 357 float hypotf(float, float) __pure2; 358 float lgammaf(float); 359 360 float acoshf(float); 361 float asinhf(float); 362 float atanhf(float); 363 float cbrtf(float) __pure2; 364 float logbf(float) __pure2; 365 float copysignf(float, float) __pure2; 366 float nearbyintf(float) __pure2; 367 float nextafterf(float, float); 368 float remainderf(float, float); 369 float rintf(float); 370 float scalblnf(float, long); 371 float scalbnf(float, int); 372 float truncf(float); 373 374 float fdimf(float, float); 375 float fmaxf(float, float) __pure2; 376 float fminf(float, float) __pure2; 377 #endif 378 379 /* 380 * float versions of BSD math library entry points 381 */ 382 #if __BSD_VISIBLE 383 float dremf(float, float); 384 int finitef(float) __pure2; 385 float gammaf(float); 386 float j0f(float); 387 float j1f(float); 388 float jnf(int, float); 389 float scalbf(float, float); 390 float y0f(float); 391 float y1f(float); 392 float ynf(int, float); 393 394 /* 395 * Float versions of reentrant version of gamma & lgamma; passes 396 * signgam back by reference as the second argument; user must 397 * allocate space for signgam. 398 */ 399 float gammaf_r(float, int *); 400 float lgammaf_r(float, int *); 401 402 /* 403 * float version of IEEE Test Vector 404 */ 405 float significandf(float); 406 #endif /* __BSD_VISIBLE */ 407 408 /* 409 * long double versions of ISO/POSIX math functions 410 */ 411 #if __ISO_C_VISIBLE >= 1999 412 #if 0 413 long double acoshl(long double); 414 long double acosl(long double); 415 long double asinhl(long double); 416 long double asinl(long double); 417 long double atan2l(long double, long double); 418 long double atanhl(long double); 419 long double atanl(long double); 420 long double cbrtl(long double); 421 long double ceill(long double); 422 #endif 423 long double copysignl(long double, long double); 424 #if 0 425 long double coshl(long double); 426 long double cosl(long double); 427 long double erfcl(long double); 428 long double erfl(long double); 429 long double exp2l(long double); 430 long double expl(long double); 431 long double expm1l(long double); 432 #endif 433 long double fabsl(long double); 434 long double fdiml(long double, long double); 435 #if 0 436 long double floorl(long double); 437 long double fmal(long double, long double, long double); 438 #endif 439 long double fmaxl(long double, long double) __pure2; 440 long double fminl(long double, long double) __pure2; 441 #if 0 442 long double fmodl(long double, long double); 443 long double frexpl(long double value, int *); 444 long double hypotl(long double, long double); 445 int ilogbl(long double); 446 long double ldexpl(long double, int); 447 long double lgammal(long double); 448 long long llrintl(long double); 449 long long llroundl(long double); 450 long double log10l(long double); 451 long double log1pl(long double); 452 long double log2l(long double); 453 long double logbl(long double); 454 long double logl(long double); 455 long lrintl(long double); 456 long lroundl(long double); 457 long double modfl(long double, long double *); 458 long double nanl(const char *); 459 long double nearbyintl(long double); 460 long double nextafterl(long double, long double); 461 double nexttoward(double, long double); 462 float nexttowardf(float, long double); 463 long double nexttowardl(long double, long double); 464 long double powl(long double, long double); 465 long double remainderl(long double, long double); 466 long double remquol(long double, long double, int *); 467 long double rintl(long double); 468 long double roundl(long double); 469 long double scalblnl(long double, long); 470 long double scalbnl(long double, int); 471 long double sinhl(long double); 472 long double sinl(long double); 473 long double sqrtl(long double); 474 long double tanhl(long double); 475 long double tanl(long double); 476 long double tgammal(long double); 477 long double truncl(long double); 478 #endif 479 480 #endif /* __ISO_C_VISIBLE >= 1999 */ 481 __END_DECLS 482 483 #endif /* !_MATH_H_ */ 484