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_MATH_H 22 #define OPENLIBM_MATH_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 /* Symbol present when OpenLibm is used. */ 198 int isopenlibm(void); 199 200 /* 201 * ANSI/POSIX 202 */ 203 int __fpclassifyd(double) __pure2; 204 int __fpclassifyf(float) __pure2; 205 int __fpclassifyl(long double) __pure2; 206 int __isfinitef(float) __pure2; 207 int __isfinite(double) __pure2; 208 int __isfinitel(long double) __pure2; 209 int __isinff(float) __pure2; 210 int __isinfl(long double) __pure2; 211 int __isnanf(float) __pure2; 212 int __isnanl(long double) __pure2; 213 int __isnormalf(float) __pure2; 214 int __isnormal(double) __pure2; 215 int __isnormall(long double) __pure2; 216 int __signbit(double) __pure2; 217 int __signbitf(float) __pure2; 218 int __signbitl(long double) __pure2; 219 220 double acos(double); 221 double asin(double); 222 double atan(double); 223 double atan2(double, double); 224 double cos(double); 225 double sin(double); 226 double tan(double); 227 228 double cosh(double); 229 double sinh(double); 230 double tanh(double); 231 232 double exp(double); 233 double frexp(double, int *); /* fundamentally !__pure2 */ 234 double ldexp(double, int); 235 double log(double); 236 double log10(double); 237 double modf(double, double *); /* fundamentally !__pure2 */ 238 239 double pow(double, double); 240 double sqrt(double); 241 242 double ceil(double); 243 double fabs(double) __pure2; 244 double floor(double); 245 double fmod(double, double); 246 247 /* 248 * These functions are not in C90. 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); 255 double erf(double); 256 double erfc(double); 257 double exp2(double); 258 double expm1(double); 259 double fma(double, double, double); 260 double hypot(double, double); 261 int ilogb(double) __pure2; 262 int (isinf)(double) __pure2; 263 int (isnan)(double) __pure2; 264 double lgamma(double); 265 long long llrint(double); 266 long long llround(double); 267 double log1p(double); 268 double log2(double); 269 double logb(double); 270 long lrint(double); 271 long lround(double); 272 double nan(const char *) __pure2; 273 double nextafter(double, double); 274 double remainder(double, double); 275 double remquo(double, double, int *); 276 double rint(double); 277 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ 278 279 #if __BSD_VISIBLE || __XSI_VISIBLE 280 double j0(double); 281 double j1(double); 282 double jn(int, double); 283 double y0(double); 284 double y1(double); 285 double yn(int, double); 286 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 287 288 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 289 double copysign(double, double) __pure2; 290 double fdim(double, double); 291 double fmax(double, double) __pure2; 292 double fmin(double, double) __pure2; 293 double nearbyint(double); 294 double round(double); 295 double scalbln(double, long); 296 double scalbn(double, int); 297 double tgamma(double); 298 double trunc(double); 299 #endif 300 301 /* 302 * BSD math library entry points 303 */ 304 #if __BSD_VISIBLE 305 int isnanf(float) __pure2; 306 307 /* 308 * Reentrant version of lgamma; passes signgam back by reference as the 309 * second argument; user must allocate space for signgam. 310 */ 311 double lgamma_r(double, int *); 312 313 /* 314 * Single sine/cosine function. 315 */ 316 void sincos(double, double *, double *); 317 #endif /* __BSD_VISIBLE */ 318 319 /* float versions of ANSI/POSIX functions */ 320 #if __ISO_C_VISIBLE >= 1999 321 float acosf(float); 322 float asinf(float); 323 float atanf(float); 324 float atan2f(float, float); 325 float cosf(float); 326 float sinf(float); 327 float tanf(float); 328 329 float coshf(float); 330 float sinhf(float); 331 float tanhf(float); 332 333 float exp2f(float); 334 float expf(float); 335 float expm1f(float); 336 float frexpf(float, int *); /* fundamentally !__pure2 */ 337 int ilogbf(float) __pure2; 338 float ldexpf(float, int); 339 float log10f(float); 340 float log1pf(float); 341 float log2f(float); 342 float logf(float); 343 float modff(float, float *); /* fundamentally !__pure2 */ 344 345 float powf(float, float); 346 float sqrtf(float); 347 348 float ceilf(float); 349 float fabsf(float) __pure2; 350 float floorf(float); 351 float fmodf(float, float); 352 float roundf(float); 353 354 float erff(float); 355 float erfcf(float); 356 float hypotf(float, float); 357 float lgammaf(float); 358 float tgammaf(float); 359 360 float acoshf(float); 361 float asinhf(float); 362 float atanhf(float); 363 float cbrtf(float); 364 float logbf(float); 365 float copysignf(float, float) __pure2; 366 long long llrintf(float); 367 long long llroundf(float); 368 long lrintf(float); 369 long lroundf(float); 370 float nanf(const char *) __pure2; 371 float nearbyintf(float); 372 float nextafterf(float, float); 373 float remainderf(float, float); 374 float remquof(float, float, int *); 375 float rintf(float); 376 float scalblnf(float, long); 377 float scalbnf(float, int); 378 float truncf(float); 379 380 float fdimf(float, float); 381 float fmaf(float, float, float); 382 float fmaxf(float, float) __pure2; 383 float fminf(float, float) __pure2; 384 #endif 385 386 /* 387 * float versions of BSD math library entry points 388 */ 389 #if __BSD_VISIBLE 390 /* 391 * Float versions of reentrant version of lgamma; passes signgam back by 392 * reference as the second argument; user must allocate space for signgam. 393 */ 394 float lgammaf_r(float, int *); 395 396 /* 397 * Single sine/cosine function. 398 */ 399 void sincosf(float, float *, float *); 400 #endif /* __BSD_VISIBLE */ 401 402 /* 403 * long double versions of ISO/POSIX math functions 404 */ 405 #if __ISO_C_VISIBLE >= 1999 406 long double acoshl(long double); 407 long double acosl(long double); 408 long double asinhl(long double); 409 long double asinl(long double); 410 long double atan2l(long double, long double); 411 long double atanhl(long double); 412 long double atanl(long double); 413 long double cbrtl(long double); 414 long double ceill(long double); 415 long double copysignl(long double, long double) __pure2; 416 long double coshl(long double); 417 long double cosl(long double); 418 long double erfcl(long double); 419 long double erfl(long double); 420 long double exp2l(long double); 421 long double expl(long double); 422 long double expm1l(long double); 423 long double fabsl(long double) __pure2; 424 long double fdiml(long double, long double); 425 long double floorl(long double); 426 long double fmal(long double, long double, long double); 427 long double fmaxl(long double, long double) __pure2; 428 long double fminl(long double, long double) __pure2; 429 long double fmodl(long double, long double); 430 long double frexpl(long double value, int *); /* fundamentally !__pure2 */ 431 long double hypotl(long double, long double); 432 int ilogbl(long double) __pure2; 433 long double ldexpl(long double, int); 434 long double lgammal(long double); 435 long long llrintl(long double); 436 long long llroundl(long double); 437 long double log10l(long double); 438 long double log1pl(long double); 439 long double log2l(long double); 440 long double logbl(long double); 441 long double logl(long double); 442 long lrintl(long double); 443 long lroundl(long double); 444 long double modfl(long double, long double *); /* fundamentally !__pure2 */ 445 long double nanl(const char *) __pure2; 446 long double nearbyintl(long double); 447 long double nextafterl(long double, long double); 448 double nexttoward(double, long double); 449 float nexttowardf(float, long double); 450 long double nexttowardl(long double, long double); 451 long double powl(long double, long double); 452 long double remainderl(long double, long double); 453 long double remquol(long double, long double, int *); 454 long double rintl(long double); 455 long double roundl(long double); 456 long double scalblnl(long double, long); 457 long double scalbnl(long double, int); 458 long double sinhl(long double); 459 long double sinl(long double); 460 long double sqrtl(long double); 461 long double tanhl(long double); 462 long double tanl(long double); 463 long double tgammal(long double); 464 long double truncl(long double); 465 #endif /* __ISO_C_VISIBLE >= 1999 */ 466 467 /* Reentrant version of lgammal. */ 468 #if __BSD_VISIBLE 469 long double lgammal_r(long double, int *); 470 471 /* 472 * Single sine/cosine function. 473 */ 474 void sincosl(long double, long double *, long double *); 475 #endif /* __BSD_VISIBLE */ 476 477 #if defined(__cplusplus) 478 } 479 #endif 480 #endif /* !OPENLIBM_MATH_H */ 481 482 #endif /* OPENLIBM_USE_HOST_MATH_H */ 483