math.h revision a588f905ab81bd9d0b644741e0847fba7dcb24bf
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/* 131 * Most of these functions depend on the rounding mode and have the side 132 * effect of raising floating-point exceptions, so they are not declared 133 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions. 134 */ 135 136/* 137 * ANSI/POSIX 138 */ 139int __fpclassifyd(double) __pure2; 140int __fpclassifyf(float) __pure2; 141int __fpclassifyl(long double) __pure2; 142int __isfinitef(float) __pure2; 143int __isfinite(double) __pure2; 144int __isfinitel(long double) __pure2; 145int __isinff(float) __pure2; 146int __isinfl(long double) __pure2; 147int __isnanf(float) __pure2; 148int __isnanl(long double) __pure2; 149int __isnormalf(float) __pure2; 150int __isnormal(double) __pure2; 151int __isnormall(long double) __pure2; 152int __signbit(double) __pure2; 153int __signbitf(float) __pure2; 154int __signbitl(long double) __pure2; 155 156double acos(double); 157double asin(double); 158double atan(double); 159double atan2(double, double); 160double cos(double); 161double sin(double); 162double tan(double); 163 164double cosh(double); 165double sinh(double); 166double tanh(double); 167 168double exp(double); 169double frexp(double, int *); /* fundamentally !__pure2 */ 170double ldexp(double, int); 171double log(double); 172double log10(double); 173double modf(double, double *); /* fundamentally !__pure2 */ 174 175double pow(double, double); 176double sqrt(double); 177 178double ceil(double); 179double fabs(double) __pure2; 180double floor(double); 181double fmod(double, double); 182 183/* 184 * These functions are not in C90. 185 */ 186#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE 187double acosh(double); 188double asinh(double); 189double atanh(double); 190double cbrt(double); 191double erf(double); 192double erfc(double); 193double exp2(double); 194double expm1(double); 195double fma(double, double, double); 196double hypot(double, double); 197int ilogb(double) __pure2; 198int (isinf)(double) __pure2; 199int (isnan)(double) __pure2; 200double lgamma(double); 201long long llrint(double); 202long long llround(double); 203double log1p(double); 204double log2(double); 205double logb(double); 206long lrint(double); 207long lround(double); 208double nan(const char *) __pure2; 209double nextafter(double, double); 210double remainder(double, double); 211double remquo(double, double, int *); 212double rint(double); 213#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ 214 215#if __BSD_VISIBLE || __XSI_VISIBLE 216double j0(double); 217double j1(double); 218double jn(int, double); 219double y0(double); 220double y1(double); 221double yn(int, double); 222 223#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE 224double gamma(double); 225#endif 226 227#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE 228double scalb(double, double); 229#endif 230#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 231 232#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 233double copysign(double, double) __pure2; 234double fdim(double, double); 235double fmax(double, double) __pure2; 236double fmin(double, double) __pure2; 237double nearbyint(double); 238double round(double); 239double scalbln(double, long); 240double scalbn(double, int); 241double tgamma(double); 242double trunc(double); 243#endif 244 245/* 246 * BSD math library entry points 247 */ 248#if __BSD_VISIBLE 249double drem(double, double); 250int finite(double) __pure2; 251int isnanf(float) __pure2; 252long double significandl(long double); 253 254/* 255 * Reentrant version of gamma & lgamma; passes signgam back by reference 256 * as the second argument; user must allocate space for signgam. 257 */ 258double gamma_r(double, int *); 259double lgamma_r(double, int *); 260 261/* 262 * IEEE Test Vector 263 */ 264double significand(double); 265#endif /* __BSD_VISIBLE */ 266 267/* float versions of ANSI/POSIX functions */ 268#if __ISO_C_VISIBLE >= 1999 269float acosf(float); 270float asinf(float); 271float atanf(float); 272float atan2f(float, float); 273float cosf(float); 274float sinf(float); 275float tanf(float); 276 277float coshf(float); 278float sinhf(float); 279float tanhf(float); 280 281float exp2f(float); 282float expf(float); 283float expm1f(float); 284float frexpf(float, int *); /* fundamentally !__pure2 */ 285int ilogbf(float) __pure2; 286float ldexpf(float, int); 287float log10f(float); 288float log1pf(float); 289float log2f(float); 290float logf(float); 291float modff(float, float *); /* fundamentally !__pure2 */ 292 293float powf(float, float); 294float sqrtf(float); 295 296float ceilf(float); 297float fabsf(float) __pure2; 298float floorf(float); 299float fmodf(float, float); 300float roundf(float); 301 302float erff(float); 303float erfcf(float); 304float hypotf(float, float); 305float lgammaf(float); 306float tgammaf(float); 307 308float acoshf(float); 309float asinhf(float); 310float atanhf(float); 311float cbrtf(float); 312float logbf(float); 313float copysignf(float, float) __pure2; 314long long llrintf(float); 315long long llroundf(float); 316long lrintf(float); 317long lroundf(float); 318float nanf(const char *) __pure2; 319float nearbyintf(float); 320float nextafterf(float, float); 321float remainderf(float, float); 322float remquof(float, float, int *); 323float rintf(float); 324float scalblnf(float, long); 325float scalbnf(float, int); 326float truncf(float); 327 328float fdimf(float, float); 329float fmaf(float, float, float); 330float fmaxf(float, float) __pure2; 331float fminf(float, float) __pure2; 332#endif 333 334/* 335 * float versions of BSD math library entry points 336 */ 337#if __BSD_VISIBLE 338float dremf(float, float); 339int finitef(float) __pure2; 340float gammaf(float); 341float j0f(float); 342float j1f(float); 343float jnf(int, float); 344float scalbf(float, float); 345float y0f(float); 346float y1f(float); 347float ynf(int, float); 348 349/* 350 * Float versions of reentrant version of gamma & lgamma; passes 351 * signgam back by reference as the second argument; user must 352 * allocate space for signgam. 353 */ 354float gammaf_r(float, int *); 355float lgammaf_r(float, int *); 356 357/* 358 * float version of IEEE Test Vector 359 */ 360float significandf(float); 361#endif /* __BSD_VISIBLE */ 362 363/* 364 * long double versions of ISO/POSIX math functions 365 */ 366#if __ISO_C_VISIBLE >= 1999 367long double acoshl(long double); 368long double acosl(long double); 369long double asinhl(long double); 370long double asinl(long double); 371long double atan2l(long double, long double); 372long double atanhl(long double); 373long double atanl(long double); 374long double cbrtl(long double); 375long double ceill(long double); 376long double copysignl(long double, long double) __pure2; 377long double coshl(long double); 378long double cosl(long double); 379long double erfcl(long double); 380long double erfl(long double); 381long double exp2l(long double); 382long double expl(long double); 383long double expm1l(long double); 384long double fabsl(long double) __pure2; 385long double fdiml(long double, long double); 386long double floorl(long double); 387long double fmal(long double, long double, long double); 388long double fmaxl(long double, long double) __pure2; 389long double fminl(long double, long double) __pure2; 390long double fmodl(long double, long double); 391long double frexpl(long double value, int *); /* fundamentally !__pure2 */ 392long double hypotl(long double, long double); 393int ilogbl(long double) __pure2; 394long double ldexpl(long double, int); 395long double lgammal(long double); 396long long llrintl(long double); 397long long llroundl(long double); 398long double log10l(long double); 399long double log1pl(long double); 400long double log2l(long double); 401long double logbl(long double); 402long double logl(long double); 403long lrintl(long double); 404long lroundl(long double); 405long double modfl(long double, long double *); /* fundamentally !__pure2 */ 406long double nanl(const char *) __pure2; 407long double nearbyintl(long double); 408long double nextafterl(long double, long double); 409double nexttoward(double, long double); 410float nexttowardf(float, long double); 411long double nexttowardl(long double, long double); 412long double powl(long double, long double); 413long double remainderl(long double, long double); 414long double remquol(long double, long double, int *); 415long double rintl(long double); 416long double roundl(long double); 417long double scalblnl(long double, long); 418long double scalbnl(long double, int); 419long double sinhl(long double); 420long double sinl(long double); 421long double sqrtl(long double); 422long double tanhl(long double); 423long double tanl(long double); 424long double tgammal(long double); 425long double truncl(long double); 426#endif /* __ISO_C_VISIBLE >= 1999 */ 427 428#if __BSD_VISIBLE 429long double lgammal_r(long double, int *); 430#endif 431 432#if defined(__USE_GNU) 433void sincos(double, double*, double*); 434void sincosf(float, float*, float*); 435void sincosl(long double, long double*, long double*); 436#endif /* __USE_GNU */ 437 438#pragma GCC visibility pop 439__END_DECLS 440 441#endif /* !_MATH_H_ */ 442