1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 23 */ 24 /* 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 #ifndef _ISO_MATH_C99_H 30 #define _ISO_MATH_C99_H 31 32 #include <sys/isa_defs.h> 33 #include <sys/feature_tests.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__) 40 #if defined(__GNUC__) 41 #undef HUGE_VAL 42 #define HUGE_VAL (__builtin_huge_val()) 43 #undef HUGE_VALF 44 #define HUGE_VALF (__builtin_huge_valf()) 45 #undef HUGE_VALL 46 #define HUGE_VALL (__builtin_huge_vall()) 47 #undef INFINITY 48 #define INFINITY (__builtin_inff()) 49 #undef NAN 50 #define NAN (__builtin_nanf("")) 51 52 /* 53 * C99 7.12.3 classification macros 54 */ 55 #undef isnan 56 #undef isinf 57 #if __GNUC__ >= 4 58 #define isnan(x) __builtin_isnan(x) 59 #define isinf(x) __builtin_isinf(x) 60 #else 61 #define isnan(x) __extension__( \ 62 { __typeof(x) __x_n = (x); \ 63 __builtin_isunordered(__x_n, __x_n); }) 64 #define isinf(x) __extension__( \ 65 { __typeof(x) __x_i = (x); \ 66 __x_i == (__typeof(__x_i)) INFINITY || \ 67 __x_i == (__typeof(__x_i)) (-INFINITY); }) 68 #endif 69 #undef isfinite 70 #define isfinite(x) __extension__( \ 71 { __typeof(x) __x_f = (x); \ 72 !isnan(__x_f) && !isinf(__x_f); }) 73 #undef isnormal 74 #define isnormal(x) __extension__( \ 75 { __typeof(x) __x_r = (x); isfinite(__x_r) && \ 76 (sizeof (__x_r) == sizeof (float) ? \ 77 __builtin_fabsf(__x_r) >= __FLT_MIN__ : \ 78 sizeof (__x_r) == sizeof (double) ? \ 79 __builtin_fabs(__x_r) >= __DBL_MIN__ : \ 80 __builtin_fabsl(__x_r) >= __LDBL_MIN__); }) 81 #undef fpclassify 82 #define fpclassify(x) __extension__( \ 83 { __typeof(x) __x_c = (x); \ 84 isnan(__x_c) ? FP_NAN : \ 85 isinf(__x_c) ? FP_INFINITE : \ 86 isnormal(__x_c) ? FP_NORMAL : \ 87 __x_c == (__typeof(__x_c)) 0 ? FP_ZERO : \ 88 FP_SUBNORMAL; }) 89 #undef signbit 90 #if defined(_BIG_ENDIAN) 91 #define signbit(x) __extension__( \ 92 { __typeof(x) __x_s = (x); \ 93 (int)(*(unsigned *)&__x_s >> 31); }) 94 #elif defined(_LITTLE_ENDIAN) 95 #define signbit(x) __extension__( \ 96 { __typeof(x) __x_s = (x); \ 97 (sizeof (__x_s) == sizeof (float) ? \ 98 (int)(*(unsigned *)&__x_s >> 31) : \ 99 sizeof (__x_s) == sizeof (double) ? \ 100 (int)(((unsigned *)&__x_s)[1] >> 31) : \ 101 (int)(((unsigned short *)&__x_s)[4] >> 15)); }) 102 #endif 103 104 /* 105 * C99 7.12.14 comparison macros 106 */ 107 #undef isgreater 108 #define isgreater(x, y) __builtin_isgreater(x, y) 109 #undef isgreaterequal 110 #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y) 111 #undef isless 112 #define isless(x, y) __builtin_isless(x, y) 113 #undef islessequal 114 #define islessequal(x, y) __builtin_islessequal(x, y) 115 #undef islessgreater 116 #define islessgreater(x, y) __builtin_islessgreater(x, y) 117 #undef isunordered 118 #define isunordered(x, y) __builtin_isunordered(x, y) 119 #else /* defined(__GNUC__) */ 120 #undef HUGE_VAL 121 #define HUGE_VAL __builtin_huge_val 122 #undef HUGE_VALF 123 #define HUGE_VALF __builtin_huge_valf 124 #undef HUGE_VALL 125 #define HUGE_VALL __builtin_huge_vall 126 #undef INFINITY 127 #define INFINITY __builtin_infinity 128 #undef NAN 129 #define NAN __builtin_nan 130 131 /* 132 * C99 7.12.3 classification macros 133 */ 134 #undef fpclassify 135 #define fpclassify(x) __builtin_fpclassify(x) 136 #undef isfinite 137 #define isfinite(x) __builtin_isfinite(x) 138 #undef isinf 139 #define isinf(x) __builtin_isinf(x) 140 #undef isnan 141 #define isnan(x) __builtin_isnan(x) 142 #undef isnormal 143 #define isnormal(x) __builtin_isnormal(x) 144 #undef signbit 145 #define signbit(x) __builtin_signbit(x) 146 147 /* 148 * C99 7.12.14 comparison macros 149 */ 150 #undef isgreater 151 #define isgreater(x, y) ((x) __builtin_isgreater(y)) 152 #undef isgreaterequal 153 #define isgreaterequal(x, y) ((x) __builtin_isgreaterequal(y)) 154 #undef isless 155 #define isless(x, y) ((x) __builtin_isless(y)) 156 #undef islessequal 157 #define islessequal(x, y) ((x) __builtin_islessequal(y)) 158 #undef islessgreater 159 #define islessgreater(x, y) ((x) __builtin_islessgreater(y)) 160 #undef isunordered 161 #define isunordered(x, y) ((x) __builtin_isunordered(y)) 162 #endif /* defined(__GNUC__) */ 163 #endif /* defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || ... */ 164 165 #if defined(__EXTENSIONS__) || defined(_STDC_C99) || \ 166 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 167 defined(__C99FEATURES__) 168 #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ - 0 == 0 169 typedef float float_t; 170 typedef double double_t; 171 #elif __FLT_EVAL_METHOD__ - 0 == 1 172 typedef double float_t; 173 typedef double double_t; 174 #elif __FLT_EVAL_METHOD__ - 0 == 2 175 typedef long double float_t; 176 typedef long double double_t; 177 #elif defined(__sparc) || defined(__amd64) 178 typedef float float_t; 179 typedef double double_t; 180 #elif defined(__i386) 181 typedef long double float_t; 182 typedef long double double_t; 183 #endif 184 185 #undef FP_ZERO 186 #define FP_ZERO 0 187 #undef FP_SUBNORMAL 188 #define FP_SUBNORMAL 1 189 #undef FP_NORMAL 190 #define FP_NORMAL 2 191 #undef FP_INFINITE 192 #define FP_INFINITE 3 193 #undef FP_NAN 194 #define FP_NAN 4 195 196 #undef FP_ILOGB0 197 #define FP_ILOGB0 (-2147483647) 198 #undef FP_ILOGBNAN 199 #define FP_ILOGBNAN 2147483647 200 201 #undef MATH_ERRNO 202 #define MATH_ERRNO 1 203 #undef MATH_ERREXCEPT 204 #define MATH_ERREXCEPT 2 205 #undef math_errhandling 206 #define math_errhandling MATH_ERREXCEPT 207 208 extern double acosh(double); 209 extern double asinh(double); 210 extern double atanh(double); 211 212 extern double exp2(double); 213 extern double expm1(double); 214 extern int ilogb(double); 215 extern double log1p(double); 216 extern double log2(double); 217 extern double logb(double); 218 extern double scalbn(double, int); 219 extern double scalbln(double, long int); 220 221 extern double cbrt(double); 222 extern double hypot(double, double); 223 224 extern double erf(double); 225 extern double erfc(double); 226 extern double lgamma(double); 227 extern double tgamma(double); 228 229 extern double nearbyint(double); 230 extern double rint(double); 231 extern long int lrint(double); 232 extern double round(double); 233 extern long int lround(double); 234 extern double trunc(double); 235 236 extern double remainder(double, double); 237 extern double remquo(double, double, int *); 238 239 extern double copysign(double, double); 240 extern double nan(const char *); 241 extern double nextafter(double, double); 242 extern double nexttoward(double, long double); 243 244 extern double fdim(double, double); 245 extern double fmax(double, double); 246 extern double fmin(double, double); 247 248 extern double fma(double, double, double); 249 250 extern float acosf(float); 251 extern float asinf(float); 252 extern float atanf(float); 253 extern float atan2f(float, float); 254 extern float cosf(float); 255 extern float sinf(float); 256 extern float tanf(float); 257 258 extern float acoshf(float); 259 extern float asinhf(float); 260 extern float atanhf(float); 261 extern float coshf(float); 262 extern float sinhf(float); 263 extern float tanhf(float); 264 265 extern float expf(float); 266 extern float exp2f(float); 267 extern float expm1f(float); 268 extern float frexpf(float, int *); 269 extern int ilogbf(float); 270 extern float ldexpf(float, int); 271 extern float logf(float); 272 extern float log10f(float); 273 extern float log1pf(float); 274 extern float log2f(float); 275 extern float logbf(float); 276 extern float modff(float, float *); 277 extern float scalbnf(float, int); 278 extern float scalblnf(float, long int); 279 280 extern float cbrtf(float); 281 extern float fabsf(float); 282 extern float hypotf(float, float); 283 extern float powf(float, float); 284 extern float sqrtf(float); 285 286 extern float erff(float); 287 extern float erfcf(float); 288 extern float lgammaf(float); 289 extern float tgammaf(float); 290 291 extern float ceilf(float); 292 extern float floorf(float); 293 extern float nearbyintf(float); 294 extern float rintf(float); 295 extern long int lrintf(float); 296 extern float roundf(float); 297 extern long int lroundf(float); 298 extern float truncf(float); 299 300 extern float fmodf(float, float); 301 extern float remainderf(float, float); 302 extern float remquof(float, float, int *); 303 304 extern float copysignf(float, float); 305 extern float nanf(const char *); 306 extern float nextafterf(float, float); 307 extern float nexttowardf(float, long double); 308 309 extern float fdimf(float, float); 310 extern float fmaxf(float, float); 311 extern float fminf(float, float); 312 313 extern float fmaf(float, float, float); 314 315 extern long double acosl(long double); 316 extern long double asinl(long double); 317 extern long double atanl(long double); 318 extern long double atan2l(long double, long double); 319 extern long double cosl(long double); 320 extern long double sinl(long double); 321 extern long double tanl(long double); 322 323 extern long double acoshl(long double); 324 extern long double asinhl(long double); 325 extern long double atanhl(long double); 326 extern long double coshl(long double); 327 extern long double sinhl(long double); 328 extern long double tanhl(long double); 329 330 extern long double expl(long double); 331 extern long double exp2l(long double); 332 extern long double expm1l(long double); 333 extern long double frexpl(long double, int *); 334 extern int ilogbl(long double); 335 extern long double ldexpl(long double, int); 336 extern long double logl(long double); 337 extern long double log10l(long double); 338 extern long double log1pl(long double); 339 extern long double log2l(long double); 340 extern long double logbl(long double); 341 extern long double modfl(long double, long double *); 342 extern long double scalbnl(long double, int); 343 extern long double scalblnl(long double, long int); 344 345 extern long double cbrtl(long double); 346 extern long double fabsl(long double); 347 extern long double hypotl(long double, long double); 348 extern long double powl(long double, long double); 349 extern long double sqrtl(long double); 350 351 extern long double erfl(long double); 352 extern long double erfcl(long double); 353 extern long double lgammal(long double); 354 extern long double tgammal(long double); 355 356 extern long double ceill(long double); 357 extern long double floorl(long double); 358 extern long double nearbyintl(long double); 359 extern long double rintl(long double); 360 extern long int lrintl(long double); 361 extern long double roundl(long double); 362 extern long int lroundl(long double); 363 extern long double truncl(long double); 364 365 extern long double fmodl(long double, long double); 366 extern long double remainderl(long double, long double); 367 extern long double remquol(long double, long double, int *); 368 369 extern long double copysignl(long double, long double); 370 extern long double nanl(const char *); 371 extern long double nextafterl(long double, long double); 372 extern long double nexttowardl(long double, long double); 373 374 extern long double fdiml(long double, long double); 375 extern long double fmaxl(long double, long double); 376 extern long double fminl(long double, long double); 377 378 extern long double fmal(long double, long double, long double); 379 380 #if !defined(_STRICT_STDC) && !defined(_NO_LONGLONG) || defined(_STDC_C99) || \ 381 defined(__C99FEATURES__) 382 extern long long int llrint(double); 383 extern long long int llround(double); 384 385 extern long long int llrintf(float); 386 extern long long int llroundf(float); 387 388 extern long long int llrintl(long double); 389 extern long long int llroundl(long double); 390 #endif 391 392 #if !defined(__cplusplus) 393 #pragma does_not_read_global_data(asinh, exp2, expm1) 394 #pragma does_not_read_global_data(ilogb, log2) 395 #pragma does_not_read_global_data(scalbn, scalbln, cbrt) 396 #pragma does_not_read_global_data(erf, erfc, tgamma) 397 #pragma does_not_read_global_data(nearbyint, rint, lrint, round, lround, trunc) 398 #pragma does_not_read_global_data(remquo) 399 #pragma does_not_read_global_data(copysign, nan, nexttoward) 400 #pragma does_not_read_global_data(fdim, fmax, fmin, fma) 401 #pragma does_not_write_global_data(asinh, exp2, expm1) 402 #pragma does_not_write_global_data(ilogb, log2) 403 #pragma does_not_write_global_data(scalbn, scalbln, cbrt) 404 #pragma does_not_write_global_data(erf, erfc, tgamma) 405 #pragma does_not_write_global_data(nearbyint, rint, lrint, round, lround, trunc) 406 #pragma does_not_write_global_data(copysign, nan, nexttoward) 407 #pragma does_not_write_global_data(fdim, fmax, fmin, fma) 408 409 #pragma does_not_read_global_data(acosf, asinf, atanf, atan2f) 410 #pragma does_not_read_global_data(cosf, sinf, tanf) 411 #pragma does_not_read_global_data(acoshf, asinhf, atanhf, coshf, sinhf, tanhf) 412 #pragma does_not_read_global_data(expf, exp2f, expm1f, frexpf, ilogbf, ldexpf) 413 #pragma does_not_read_global_data(logf, log10f, log1pf, log2f, logbf) 414 #pragma does_not_read_global_data(modff, scalbnf, scalblnf) 415 #pragma does_not_read_global_data(cbrtf, fabsf, hypotf, powf, sqrtf) 416 #pragma does_not_read_global_data(erff, erfcf, lgammaf, tgammaf) 417 #pragma does_not_read_global_data(ceilf, floorf, nearbyintf) 418 #pragma does_not_read_global_data(rintf, lrintf, roundf, lroundf, truncf) 419 #pragma does_not_read_global_data(fmodf, remainderf, remquof) 420 #pragma does_not_read_global_data(copysignf, nanf, nextafterf, nexttowardf) 421 #pragma does_not_read_global_data(fdimf, fmaxf, fminf, fmaf) 422 #pragma does_not_write_global_data(acosf, asinf, atanf, atan2f) 423 #pragma does_not_write_global_data(cosf, sinf, tanf) 424 #pragma does_not_write_global_data(acoshf, asinhf, atanhf, coshf, sinhf, tanhf) 425 #pragma does_not_write_global_data(expf, exp2f, expm1f, ilogbf, ldexpf) 426 #pragma does_not_write_global_data(logf, log10f, log1pf, log2f, logbf) 427 #pragma does_not_write_global_data(cbrtf, fabsf, hypotf, powf, sqrtf) 428 #pragma does_not_write_global_data(erff, erfcf, tgammaf) 429 #pragma does_not_write_global_data(ceilf, floorf, nearbyintf) 430 #pragma does_not_write_global_data(rintf, lrintf, roundf, lroundf, truncf) 431 #pragma does_not_write_global_data(fmodf, remainderf) 432 #pragma does_not_write_global_data(copysignf, nanf, nextafterf, nexttowardf) 433 #pragma does_not_write_global_data(fdimf, fmaxf, fminf, fmaf) 434 435 #pragma does_not_read_global_data(acosl, asinl, atanl, atan2l) 436 #pragma does_not_read_global_data(cosl, sinl, tanl) 437 #pragma does_not_read_global_data(acoshl, asinhl, atanhl, coshl, sinhl, tanhl) 438 #pragma does_not_read_global_data(expl, exp2l, expm1l, frexpl, ilogbl, ldexpl) 439 #pragma does_not_read_global_data(logl, log10l, log1pl, log2l, logbl) 440 #pragma does_not_read_global_data(modfl, scalbnl, scalblnl) 441 #pragma does_not_read_global_data(cbrtl, fabsl, hypotl, powl, sqrtl) 442 #pragma does_not_read_global_data(erfl, erfcl, lgammal, tgammal) 443 #pragma does_not_read_global_data(ceill, floorl, nearbyintl) 444 #pragma does_not_read_global_data(rintl, lrintl, roundl, lroundl, truncl) 445 #pragma does_not_read_global_data(fmodl, remainderl, remquol) 446 #pragma does_not_read_global_data(copysignl, nanl, nextafterl, nexttowardl) 447 #pragma does_not_read_global_data(fdiml, fmaxl, fminl, fmal) 448 #pragma does_not_write_global_data(acosl, asinl, atanl, atan2l) 449 #pragma does_not_write_global_data(cosl, sinl, tanl) 450 #pragma does_not_write_global_data(acoshl, asinhl, atanhl, coshl, sinhl, tanhl) 451 #pragma does_not_write_global_data(expl, exp2l, expm1l, ilogbl, ldexpl) 452 #pragma does_not_write_global_data(logl, log10l, log1pl, log2l, logbl) 453 #pragma does_not_write_global_data(cbrtl, fabsl, hypotl, powl, sqrtl) 454 #pragma does_not_write_global_data(erfl, erfcl, tgammal) 455 #pragma does_not_write_global_data(ceill, floorl, nearbyintl) 456 #pragma does_not_write_global_data(rintl, lrintl, roundl, lroundl, truncl) 457 #pragma does_not_write_global_data(fmodl, remainderl) 458 #pragma does_not_write_global_data(copysignl, nanl, nextafterl, nexttowardl) 459 #pragma does_not_write_global_data(fdiml, fmaxl, fminl, fmal) 460 461 #if !defined(_STRICT_STDC) && !defined(_NO_LONGLONG) || defined(_STDC_C99) || \ 462 defined(__C99FEATURES__) 463 #pragma does_not_read_global_data(llrint, llround) 464 #pragma does_not_read_global_data(llrintf, llroundf, llrintl, llroundl) 465 #pragma does_not_write_global_data(llrint, llround) 466 #pragma does_not_write_global_data(llrintf, llroundf, llrintl, llroundl) 467 #endif 468 #endif /* !defined(__cplusplus) */ 469 470 #if defined(__MATHERR_ERRNO_DONTCARE) 471 #pragma does_not_read_global_data(acosh, atanh, hypot, lgamma, log1p, logb) 472 #pragma does_not_read_global_data(nextafter, remainder) 473 #pragma does_not_write_global_data(acosh, atanh, hypot, log1p, logb) 474 #pragma does_not_write_global_data(nextafter, remainder) 475 476 #pragma no_side_effect(acosh, asinh, atanh, exp2, expm1) 477 #pragma no_side_effect(ilogb, log1p, log2, logb) 478 #pragma no_side_effect(scalbn, scalbln, cbrt, hypot) 479 #pragma no_side_effect(erf, erfc, tgamma) 480 #pragma no_side_effect(nearbyint, rint, lrint, round, lround, trunc) 481 #pragma no_side_effect(remainder) 482 #pragma no_side_effect(copysign, nan, nextafter, nexttoward) 483 #pragma no_side_effect(fdim, fmax, fmin, fma) 484 485 #pragma no_side_effect(acosf, asinf, atanf, atan2f) 486 #pragma no_side_effect(cosf, sinf, tanf, coshf, sinhf, tanhf) 487 #pragma no_side_effect(acoshf, asinhf, atanhf, coshf, sinhf, tanhf) 488 #pragma no_side_effect(expf, exp2f, expm1f, ilogbf, ldexpf) 489 #pragma no_side_effect(logf, log10f, log1pf, log2f, logbf) 490 #pragma no_side_effect(cbrtf, fabsf, hypotf, powf, sqrtf) 491 #pragma no_side_effect(erff, erfcf, tgammaf) 492 #pragma no_side_effect(ceilf, floorf, nearbyintf) 493 #pragma no_side_effect(rintf, lrintf, roundf, lroundf, truncf) 494 #pragma no_side_effect(fmodf, remainderf) 495 #pragma no_side_effect(copysignf, nanf, nextafterf, nexttowardf) 496 #pragma no_side_effect(fdimf, fmaxf, fminf, fmaf) 497 498 #pragma no_side_effect(acosl, asinl, atanl, atan2l) 499 #pragma no_side_effect(cosl, sinl, tanl, coshl, sinhl, tanhl) 500 #pragma no_side_effect(acoshl, asinhl, atanhl, coshl, sinhl, tanhl) 501 #pragma no_side_effect(expl, exp2l, expm1l, ilogbl, ldexpl) 502 #pragma no_side_effect(logl, log10l, log1pl, log2l, logbl) 503 #pragma no_side_effect(cbrtl, fabsl, hypotl, powl, sqrtl) 504 #pragma no_side_effect(erfl, erfcl, tgammal) 505 #pragma no_side_effect(ceill, floorl, nearbyintl) 506 #pragma no_side_effect(rintl, lrintl, roundl, lroundl, truncl) 507 #pragma no_side_effect(fmodl, remainderl) 508 #pragma no_side_effect(copysignl, nanl, nextafterl, nexttowardl) 509 #pragma no_side_effect(fdiml, fmaxl, fminl, fmal) 510 511 #if !defined(_STRICT_STDC) && !defined(_NO_LONGLONG) || defined(_STDC_C99) || \ 512 defined(__C99FEATURES__) 513 #pragma no_side_effect(llrint, llround, llrintf, llroundf, llrintl, llroundl) 514 #endif 515 #endif /* defined(__MATHERR_ERRNO_DONTCARE) */ 516 #endif /* defined(__EXTENSIONS__) || defined(_STDC_C99) || ... */ 517 518 #ifdef __cplusplus 519 } 520 #endif 521 522 #endif /* _ISO_MATH_C99_H */