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