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