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 __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) 38 #define __MATH_BUILTIN_CONSTANTS 39 #endif 40 41 #if __GNUC_PREREQ__(3, 0) && !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 MATH_ERREXCEPT 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) \ 117 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \ 118 : (sizeof (x) == sizeof (double)) ? __signbit(x) \ 119 : __signbitl(x)) 120 121 typedef __double_t double_t; 122 typedef __float_t float_t; 123 #endif /* __ISO_C_VISIBLE >= 1999 */ 124 125 /* 126 * XOPEN/SVID 127 */ 128 #if __BSD_VISIBLE || __XSI_VISIBLE 129 #define M_E 2.7182818284590452354 /* e */ 130 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 131 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 132 #define M_LN2 0.69314718055994530942 /* log e2 */ 133 #define M_LN10 2.30258509299404568402 /* log e10 */ 134 #define M_PI 3.14159265358979323846 /* pi */ 135 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 136 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 137 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 138 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 139 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 140 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 141 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 142 143 #define MAXFLOAT ((float)3.40282346638528860e+38) 144 extern int signgam; 145 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 146 147 #if __BSD_VISIBLE 148 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 149 150 #define _LIB_VERSION_TYPE enum fdversion 151 #define _LIB_VERSION _fdlib_version 152 153 /* if global variable _LIB_VERSION is not desirable, one may 154 * change the following to be a constant by: 155 * #define _LIB_VERSION_TYPE const enum version 156 * In that case, after one initializes the value _LIB_VERSION (see 157 * s_lib_version.c) during compile time, it cannot be modified 158 * in the middle of a program 159 */ 160 extern _LIB_VERSION_TYPE _LIB_VERSION; 161 162 #define _IEEE_ fdlibm_ieee 163 #define _SVID_ fdlibm_svid 164 #define _XOPEN_ fdlibm_xopen 165 #define _POSIX_ fdlibm_posix 166 167 /* We have a problem when using C++ since `exception' is a reserved 168 name in C++. */ 169 #ifndef __cplusplus 170 struct exception { 171 int type; 172 char *name; 173 double arg1; 174 double arg2; 175 double retval; 176 }; 177 #endif 178 179 #if 0 180 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 181 #define HUGE HUGE_VAL 182 #else 183 #define HUGE MAXFLOAT 184 #endif 185 186 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */ 187 188 #define DOMAIN 1 189 #define SING 2 190 #define OVERFLOW 3 191 #define UNDERFLOW 4 192 #define TLOSS 5 193 #define PLOSS 6 194 195 #endif /* __BSD_VISIBLE */ 196 197 /* 198 * Most of these functions depend on the rounding mode and have the side 199 * effect of raising floating-point exceptions, so they are not declared 200 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions. 201 */ 202 __BEGIN_DECLS 203 /* 204 * ANSI/POSIX 205 */ 206 int __fpclassifyd(double) __pure2; 207 int __fpclassifyf(float) __pure2; 208 int __fpclassifyl(long double) __pure2; 209 int __isfinitef(float) __pure2; 210 int __isfinite(double) __pure2; 211 int __isfinitel(long double) __pure2; 212 int __isinff(float) __pure2; 213 int __isinfl(long double) __pure2; 214 int __isnanl(long double) __pure2; 215 int __isnormalf(float) __pure2; 216 int __isnormal(double) __pure2; 217 int __isnormall(long double) __pure2; 218 int __signbit(double) __pure2; 219 int __signbitf(float) __pure2; 220 int __signbitl(long double) __pure2; 221 222 double acos(double); 223 double asin(double); 224 double atan(double); 225 double atan2(double, double); 226 double cos(double); 227 double sin(double); 228 double tan(double); 229 230 double cosh(double); 231 double sinh(double); 232 double tanh(double); 233 234 double exp(double); 235 double frexp(double, int *); /* fundamentally !__pure2 */ 236 double ldexp(double, int); 237 double log(double); 238 double log10(double); 239 double modf(double, double *); /* fundamentally !__pure2 */ 240 241 double pow(double, double); 242 double sqrt(double); 243 244 double ceil(double); 245 double fabs(double) __pure2; 246 double floor(double); 247 double fmod(double, double); 248 249 /* 250 * These functions are not in C90. 251 */ 252 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE 253 double acosh(double); 254 double asinh(double); 255 double atanh(double); 256 double cbrt(double); 257 double erf(double); 258 double erfc(double); 259 double expm1(double); 260 double hypot(double, double); 261 /* Our ilogb raises no exceptions; we side with IEEE-754R and C99, not POSIX */ 262 int ilogb(double) __pure2; 263 int (isinf)(double) __pure2; 264 int (isnan)(double) __pure2; 265 double lgamma(double); 266 long long llrint(double); 267 long long llround(double); 268 double log1p(double); 269 double logb(double); 270 long lrint(double); 271 long lround(double); 272 double nextafter(double, double); 273 double remainder(double, double); 274 double rint(double); 275 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ 276 277 #if __BSD_VISIBLE || __XSI_VISIBLE 278 double j0(double); 279 double j1(double); 280 double jn(int, double); 281 double scalb(double, double); 282 double y0(double); 283 double y1(double); 284 double yn(int, double); 285 286 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE 287 double gamma(double); 288 #endif 289 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 290 291 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 292 double copysign(double, double) __pure2; 293 double fdim(double, double); 294 double fmax(double, double) __pure2; 295 double fmin(double, double) __pure2; 296 double nearbyint(double); 297 double round(double); 298 double scalbln(double, long); 299 double scalbn(double, int); 300 double tgamma(double); 301 double trunc(double); 302 #endif 303 304 /* 305 * BSD math library entry points 306 */ 307 #if __BSD_VISIBLE 308 double drem(double, double); 309 int finite(double) __pure2; 310 int isnanf(float) __pure2; 311 312 /* 313 * Reentrant version of gamma & lgamma; passes signgam back by reference 314 * as the second argument; user must allocate space for signgam. 315 */ 316 double gamma_r(double, int *); 317 double lgamma_r(double, int *); 318 319 /* 320 * IEEE Test Vector 321 */ 322 double significand(double); 323 324 #ifndef __cplusplus 325 int matherr(struct exception *); 326 #endif 327 #endif /* __BSD_VISIBLE */ 328 329 /* float versions of ANSI/POSIX functions */ 330 #if __ISO_C_VISIBLE >= 1999 331 float acosf(float); 332 float asinf(float); 333 float atanf(float); 334 float atan2f(float, float); 335 float cosf(float); 336 float sinf(float); 337 float tanf(float); 338 339 float coshf(float); 340 float sinhf(float); 341 float tanhf(float); 342 343 float expf(float); 344 float expm1f(float); 345 float frexpf(float, int *); /* fundamentally !__pure2 */ 346 int ilogbf(float) __pure2; 347 float ldexpf(float, int); 348 float log10f(float); 349 float log1pf(float); 350 float logf(float); 351 float modff(float, float *); /* fundamentally !__pure2 */ 352 353 float powf(float, float); 354 float sqrtf(float); 355 356 float ceilf(float); 357 float fabsf(float) __pure2; 358 float floorf(float); 359 float fmodf(float, float); 360 float roundf(float); 361 362 float erff(float); 363 float erfcf(float); 364 float hypotf(float, float); 365 float lgammaf(float); 366 367 float acoshf(float); 368 float asinhf(float); 369 float atanhf(float); 370 float cbrtf(float); 371 float logbf(float); 372 float copysignf(float, float) __pure2; 373 long long llrintf(float); 374 long long llroundf(float); 375 long lrintf(float); 376 long lroundf(float); 377 float nearbyintf(float); 378 float nextafterf(float, float); 379 float remainderf(float, float); 380 float rintf(float); 381 float scalblnf(float, long); 382 float scalbnf(float, int); 383 float truncf(float); 384 385 float fdimf(float, float); 386 float fmaxf(float, float) __pure2; 387 float fminf(float, float) __pure2; 388 #endif 389 390 /* 391 * float versions of BSD math library entry points 392 */ 393 #if __BSD_VISIBLE 394 float dremf(float, float); 395 int finitef(float) __pure2; 396 float gammaf(float); 397 float j0f(float); 398 float j1f(float); 399 float jnf(int, float); 400 float scalbf(float, float); 401 float y0f(float); 402 float y1f(float); 403 float ynf(int, float); 404 405 /* 406 * Float versions of reentrant version of gamma & lgamma; passes 407 * signgam back by reference as the second argument; user must 408 * allocate space for signgam. 409 */ 410 float gammaf_r(float, int *); 411 float lgammaf_r(float, int *); 412 413 /* 414 * float version of IEEE Test Vector 415 */ 416 float significandf(float); 417 #endif /* __BSD_VISIBLE */ 418 419 /* 420 * long double versions of ISO/POSIX math functions 421 */ 422 #if __ISO_C_VISIBLE >= 1999 423 #if 0 424 long double acoshl(long double); 425 long double acosl(long double); 426 long double asinhl(long double); 427 long double asinl(long double); 428 long double atan2l(long double, long double); 429 long double atanhl(long double); 430 long double atanl(long double); 431 long double cbrtl(long double); 432 #endif 433 long double ceill(long double); 434 long double copysignl(long double, long double) __pure2; 435 #if 0 436 long double coshl(long double); 437 long double cosl(long double); 438 long double erfcl(long double); 439 long double erfl(long double); 440 long double exp2l(long double); 441 long double expl(long double); 442 long double expm1l(long double); 443 #endif 444 long double fabsl(long double) __pure2; 445 long double fdiml(long double, long double); 446 long double floorl(long double); 447 #if 0 448 long double fmal(long double, long double, long double); 449 #endif 450 long double fmaxl(long double, long double) __pure2; 451 long double fminl(long double, long double) __pure2; 452 #if 0 453 long double fmodl(long double, long double); 454 long double frexpl(long double value, int *); /* fundamentally !__pure2 */ 455 long double hypotl(long double, long double); 456 #endif 457 int ilogbl(long double) __pure2; 458 #if 0 459 long double ldexpl(long double, int); 460 long double lgammal(long double); 461 long long llrintl(long double); 462 long long llroundl(long double); 463 long double log10l(long double); 464 long double log1pl(long double); 465 long double log2l(long double); 466 long double logbl(long double); 467 long double logl(long double); 468 long lrintl(long double); 469 long lroundl(long double); 470 long double modfl(long double, long double *); /* fundamentally !__pure2 */ 471 long double nanl(const char *) __pure2; 472 long double nearbyintl(long double); 473 long double nextafterl(long double, long double); 474 double nexttoward(double, long double); 475 float nexttowardf(float, long double); 476 long double nexttowardl(long double, long double); 477 long double powl(long double, long double); 478 long double remainderl(long double, long double); 479 long double remquol(long double, long double, int *); 480 long double rintl(long double); 481 long double roundl(long double); 482 long double scalblnl(long double, long); 483 long double scalbnl(long double, int); 484 long double sinhl(long double); 485 long double sinl(long double); 486 long double sqrtl(long double); 487 long double tanhl(long double); 488 long double tanl(long double); 489 long double tgammal(long double); 490 long double truncl(long double); 491 #endif 492 493 #endif /* __ISO_C_VISIBLE >= 1999 */ 494 __END_DECLS 495 496 #endif /* !_MATH_H_ */ 497