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