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: src/lib/msun/src/openlibm.h,v 1.82 2011/11/12 19:55:48 theraven Exp $ 15 */ 16 17 #ifdef OPENLIBM_USE_HOST_MATH_H 18 #include <math.h> 19 #else /* !OPENLIBM_USE_HOST_MATH_H */ 20 21 #ifndef OPENLIBM_H 22 #define OPENLIBM_H 23 24 #if (defined(_WIN32) || defined (_MSC_VER)) && !defined(__WIN32__) 25 #define __WIN32__ 26 #endif 27 28 #ifndef __arm__ 29 #define LONG_DOUBLE 30 #endif 31 32 #ifndef __pure2 33 #define __pure2 34 #endif 35 36 /* 37 * ANSI/POSIX 38 */ 39 extern const union __infinity_un { 40 unsigned char __uc[8]; 41 double __ud; 42 } __infinity; 43 44 extern const union __nan_un { 45 unsigned char __uc[sizeof(float)]; 46 float __uf; 47 } __nan; 48 49 /* VBS 50 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) 51 #define __MATH_BUILTIN_CONSTANTS 52 #endif 53 54 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) 55 #define __MATH_BUILTIN_RELOPS 56 #endif 57 */ 58 59 //VBS begin 60 #define __MATH_BUILTIN_CONSTANTS 61 #define __MATH_BUILTIN_RELOPS 62 #ifndef __ISO_C_VISIBLE 63 #define __ISO_C_VISIBLE 1999 64 #endif 65 //VBS end 66 67 #ifdef __MATH_BUILTIN_CONSTANTS 68 #define HUGE_VAL __builtin_huge_val() 69 #else 70 #define HUGE_VAL (__infinity.__ud) 71 #endif 72 73 #if __ISO_C_VISIBLE >= 1999 74 #define FP_ILOGB0 (-INT_MAX) 75 #define FP_ILOGBNAN INT_MAX 76 77 #ifdef __MATH_BUILTIN_CONSTANTS 78 #define HUGE_VALF __builtin_huge_valf() 79 #define HUGE_VALL __builtin_huge_vall() 80 #define INFINITY __builtin_inff() 81 #define NAN __builtin_nanf("") 82 #else 83 #define HUGE_VALF (float)HUGE_VAL 84 #define HUGE_VALL (long double)HUGE_VAL 85 #define INFINITY HUGE_VALF 86 #define NAN (__nan.__uf) 87 #endif /* __MATH_BUILTIN_CONSTANTS */ 88 89 #define MATH_ERRNO 1 90 #define MATH_ERREXCEPT 2 91 #define math_errhandling MATH_ERREXCEPT 92 93 #define FP_FAST_FMAF 1 94 #ifdef __ia64__ 95 #define FP_FAST_FMA 1 96 #define FP_FAST_FMAL 1 97 #endif 98 99 /* Symbolic constants to classify floating point numbers. */ 100 #define FP_INFINITE 0x01 101 #define FP_NAN 0x02 102 #define FP_NORMAL 0x04 103 #define FP_SUBNORMAL 0x08 104 #define FP_ZERO 0x10 105 #define fpclassify(x) \ 106 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ 107 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ 108 : __fpclassifyl(x)) 109 110 #define isfinite(x) \ 111 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \ 112 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \ 113 : __isfinitel(x)) 114 #define isinf(x) \ 115 ((sizeof (x) == sizeof (float)) ? __isinff(x) \ 116 : (sizeof (x) == sizeof (double)) ? isinf(x) \ 117 : __isinfl(x)) 118 #define isnan(x) \ 119 ((sizeof (x) == sizeof (float)) ? __isnanf(x) \ 120 : (sizeof (x) == sizeof (double)) ? isnan(x) \ 121 : __isnanl(x)) 122 #define isnormal(x) \ 123 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \ 124 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \ 125 : __isnormall(x)) 126 127 #ifdef __MATH_BUILTIN_RELOPS 128 #define isgreater(x, y) __builtin_isgreater((x), (y)) 129 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) 130 #define isless(x, y) __builtin_isless((x), (y)) 131 #define islessequal(x, y) __builtin_islessequal((x), (y)) 132 #define islessgreater(x, y) __builtin_islessgreater((x), (y)) 133 #define isunordered(x, y) __builtin_isunordered((x), (y)) 134 #else 135 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) 136 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) 137 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) 138 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) 139 #define islessgreater(x, y) (!isunordered((x), (y)) && \ 140 ((x) > (y) || (y) > (x))) 141 #define isunordered(x, y) (isnan(x) || isnan(y)) 142 #endif /* __MATH_BUILTIN_RELOPS */ 143 144 #define signbit(x) \ 145 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \ 146 : (sizeof (x) == sizeof (double)) ? __signbit(x) \ 147 : __signbitl(x)) 148 149 //VBS 150 //typedef __double_t double_t; 151 //typedef __float_t float_t; 152 #endif /* __ISO_C_VISIBLE >= 1999 */ 153 154 /* 155 * XOPEN/SVID 156 */ 157 #if __BSD_VISIBLE || __XSI_VISIBLE 158 #define M_E 2.7182818284590452354 /* e */ 159 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 160 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 161 #define M_LN2 0.69314718055994530942 /* log e2 */ 162 #define M_LN10 2.30258509299404568402 /* log e10 */ 163 #define M_PI 3.14159265358979323846 /* pi */ 164 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 165 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 166 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 167 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 168 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 169 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 170 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 171 172 #define MAXFLOAT ((float)3.40282346638528860e+38) 173 174 #ifndef OPENLIBM_ONLY_THREAD_SAFE 175 extern int signgam; 176 #endif 177 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 178 179 #if __BSD_VISIBLE 180 #if 0 181 /* Old value from 4.4BSD-Lite openlibm.h; this is probably better. */ 182 #define HUGE HUGE_VAL 183 #else 184 #define HUGE MAXFLOAT 185 #endif 186 #endif /* __BSD_VISIBLE */ 187 188 /* 189 * Most of these functions depend on the rounding mode and have the side 190 * effect of raising floating-point exceptions, so they are not declared 191 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions. 192 */ 193 194 #if defined(__cplusplus) 195 extern "C" { 196 #endif 197 /* 198 * ANSI/POSIX 199 */ 200 int __fpclassifyd(double) __pure2; 201 int __fpclassifyf(float) __pure2; 202 int __fpclassifyl(long double) __pure2; 203 int __isfinitef(float) __pure2; 204 int __isfinite(double) __pure2; 205 int __isfinitel(long double) __pure2; 206 int __isinff(float) __pure2; 207 int __isinfl(long double) __pure2; 208 int __isnanf(float) __pure2; 209 int __isnanl(long double) __pure2; 210 int __isnormalf(float) __pure2; 211 int __isnormal(double) __pure2; 212 int __isnormall(long double) __pure2; 213 int __signbit(double) __pure2; 214 int __signbitf(float) __pure2; 215 int __signbitl(long double) __pure2; 216 217 double acos(double); 218 double asin(double); 219 double atan(double); 220 double atan2(double, double); 221 double cos(double); 222 double sin(double); 223 double tan(double); 224 225 double cosh(double); 226 double sinh(double); 227 double tanh(double); 228 229 double exp(double); 230 double frexp(double, int *); /* fundamentally !__pure2 */ 231 double ldexp(double, int); 232 double log(double); 233 double log10(double); 234 double modf(double, double *); /* fundamentally !__pure2 */ 235 236 double pow(double, double); 237 double sqrt(double); 238 239 double ceil(double); 240 double fabs(double) __pure2; 241 double floor(double); 242 double fmod(double, double); 243 244 /* 245 * These functions are not in C90. 246 */ 247 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE 248 double acosh(double); 249 double asinh(double); 250 double atanh(double); 251 double cbrt(double); 252 double erf(double); 253 double erfc(double); 254 double exp2(double); 255 double expm1(double); 256 double fma(double, double, double); 257 double hypot(double, double); 258 int ilogb(double) __pure2; 259 int (isinf)(double) __pure2; 260 int (isnan)(double) __pure2; 261 double lgamma(double); 262 long long llrint(double); 263 long long llround(double); 264 double log1p(double); 265 double log2(double); 266 double logb(double); 267 long lrint(double); 268 long lround(double); 269 double nan(const char *) __pure2; 270 double nextafter(double, double); 271 double remainder(double, double); 272 double remquo(double, double, int *); 273 double rint(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 y0(double); 281 double y1(double); 282 double yn(int, double); 283 284 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE 285 double gamma(double); 286 #endif 287 288 #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE 289 double scalb(double, double); 290 #endif 291 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 292 293 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 294 double copysign(double, double) __pure2; 295 double fdim(double, double); 296 double fmax(double, double) __pure2; 297 double fmin(double, double) __pure2; 298 double nearbyint(double); 299 double round(double); 300 double scalbln(double, long); 301 double scalbn(double, int); 302 double tgamma(double); 303 double trunc(double); 304 #endif 305 306 /* 307 * BSD math library entry points 308 */ 309 #if __BSD_VISIBLE 310 double drem(double, double); 311 int finite(double) __pure2; 312 int isnanf(float) __pure2; 313 314 /* 315 * Reentrant version of gamma & lgamma; passes signgam back by reference 316 * as the second argument; user must allocate space for signgam. 317 */ 318 double gamma_r(double, int *); 319 double lgamma_r(double, int *); 320 321 /* 322 * Single sine/cosine function. 323 */ 324 void sincos(double, double *, double *); 325 326 /* 327 * IEEE Test Vector 328 */ 329 double significand(double); 330 #endif /* __BSD_VISIBLE */ 331 332 /* float versions of ANSI/POSIX functions */ 333 #if __ISO_C_VISIBLE >= 1999 334 float acosf(float); 335 float asinf(float); 336 float atanf(float); 337 float atan2f(float, float); 338 float cosf(float); 339 float sinf(float); 340 float tanf(float); 341 342 float coshf(float); 343 float sinhf(float); 344 float tanhf(float); 345 346 float exp2f(float); 347 float expf(float); 348 float expm1f(float); 349 float frexpf(float, int *); /* fundamentally !__pure2 */ 350 int ilogbf(float) __pure2; 351 float ldexpf(float, int); 352 float log10f(float); 353 float log1pf(float); 354 float log2f(float); 355 float logf(float); 356 float modff(float, float *); /* fundamentally !__pure2 */ 357 358 float powf(float, float); 359 float sqrtf(float); 360 361 float ceilf(float); 362 float fabsf(float) __pure2; 363 float floorf(float); 364 float fmodf(float, float); 365 float roundf(float); 366 367 float erff(float); 368 float erfcf(float); 369 float hypotf(float, float); 370 float lgammaf(float); 371 float tgammaf(float); 372 373 float acoshf(float); 374 float asinhf(float); 375 float atanhf(float); 376 float cbrtf(float); 377 float logbf(float); 378 float copysignf(float, float) __pure2; 379 long long llrintf(float); 380 long long llroundf(float); 381 long lrintf(float); 382 long lroundf(float); 383 float nanf(const char *) __pure2; 384 float nearbyintf(float); 385 float nextafterf(float, float); 386 float remainderf(float, float); 387 float remquof(float, float, int *); 388 float rintf(float); 389 float scalblnf(float, long); 390 float scalbnf(float, int); 391 float truncf(float); 392 393 float fdimf(float, float); 394 float fmaf(float, float, float); 395 float fmaxf(float, float) __pure2; 396 float fminf(float, float) __pure2; 397 #endif 398 399 /* 400 * float versions of BSD math library entry points 401 */ 402 #if __BSD_VISIBLE 403 float dremf(float, float); 404 int finitef(float) __pure2; 405 float gammaf(float); 406 float j0f(float); 407 float j1f(float); 408 float jnf(int, float); 409 float scalbf(float, float); 410 float y0f(float); 411 float y1f(float); 412 float ynf(int, float); 413 414 /* 415 * Float versions of reentrant version of gamma & lgamma; passes 416 * signgam back by reference as the second argument; user must 417 * allocate space for signgam. 418 */ 419 float gammaf_r(float, int *); 420 float lgammaf_r(float, int *); 421 422 /* 423 * Single sine/cosine function. 424 */ 425 void sincosf(float, float *, float *); 426 427 /* 428 * float version of IEEE Test Vector 429 */ 430 float significandf(float); 431 #endif /* __BSD_VISIBLE */ 432 433 /* 434 * long double versions of ISO/POSIX math functions 435 */ 436 #if __ISO_C_VISIBLE >= 1999 437 long double acoshl(long double); 438 long double acosl(long double); 439 long double asinhl(long double); 440 long double asinl(long double); 441 long double atan2l(long double, long double); 442 long double atanhl(long double); 443 long double atanl(long double); 444 long double cbrtl(long double); 445 long double ceill(long double); 446 long double copysignl(long double, long double) __pure2; 447 long double coshl(long double); 448 long double cosl(long double); 449 long double erfcl(long double); 450 long double erfl(long double); 451 long double exp2l(long double); 452 long double expl(long double); 453 long double expm1l(long double); 454 long double fabsl(long double) __pure2; 455 long double fdiml(long double, long double); 456 long double floorl(long double); 457 long double fmal(long double, long double, long double); 458 long double fmaxl(long double, long double) __pure2; 459 long double fminl(long double, long double) __pure2; 460 long double fmodl(long double, long double); 461 long double frexpl(long double value, int *); /* fundamentally !__pure2 */ 462 long double hypotl(long double, long double); 463 int ilogbl(long double) __pure2; 464 long double ldexpl(long double, int); 465 long double lgammal(long double); 466 long long llrintl(long double); 467 long long llroundl(long double); 468 long double log10l(long double); 469 long double log1pl(long double); 470 long double log2l(long double); 471 long double logbl(long double); 472 long double logl(long double); 473 long lrintl(long double); 474 long lroundl(long double); 475 long double modfl(long double, long double *); /* fundamentally !__pure2 */ 476 long double nanl(const char *) __pure2; 477 long double nearbyintl(long double); 478 long double nextafterl(long double, long double); 479 double nexttoward(double, long double); 480 float nexttowardf(float, long double); 481 long double nexttowardl(long double, long double); 482 long double powl(long double, long double); 483 long double remainderl(long double, long double); 484 long double remquol(long double, long double, int *); 485 long double rintl(long double); 486 long double roundl(long double); 487 long double scalblnl(long double, long); 488 long double scalbnl(long double, int); 489 long double sinhl(long double); 490 long double sinl(long double); 491 long double sqrtl(long double); 492 long double tanhl(long double); 493 long double tanl(long double); 494 long double tgammal(long double); 495 long double truncl(long double); 496 #endif /* __ISO_C_VISIBLE >= 1999 */ 497 498 /* Reentrant version of lgammal. */ 499 #if __BSD_VISIBLE 500 long double lgammal_r(long double, int *); 501 502 /* 503 * Single sine/cosine function. 504 */ 505 void sincosl(long double, long double *, long double *); 506 #endif /* __BSD_VISIBLE */ 507 508 #if defined(__cplusplus) 509 } 510 #endif 511 #endif /* !OPENLIBM_H */ 512 513 #endif /* OPENLIBM_USE_HOST_MATH_H */ 514