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