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