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