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