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