1 /* 2 * ==================================================== 3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 4 * 5 * Developed at SunPro, a Sun Microsystems, Inc. business. 6 * Permission to use, copy, modify, and distribute this 7 * software is freely granted, provided that this notice 8 * is preserved. 9 * ==================================================== 10 */ 11 12 /* 13 * from: @(#)fdlibm.h 5.1 93/09/24 14 * $FreeBSD$ 15 */ 16 17 #ifndef _MATH_H_ 18 #define _MATH_H_ 19 20 #include <sys/cdefs.h> 21 #include <sys/_types.h> 22 #include <machine/_limits.h> 23 24 /* 25 * ANSI/POSIX 26 */ 27 extern const union __infinity_un { 28 unsigned char __uc[8]; 29 double __ud; 30 } __infinity; 31 32 extern const union __nan_un { 33 unsigned char __uc[sizeof(float)]; 34 float __uf; 35 } __nan; 36 37 #define HUGE_VAL (__infinity.__ud) 38 39 #if __ISO_C_VISIBLE >= 1999 40 #define FP_ILOGB0 (-__INT_MAX) 41 #define FP_ILOGBNAN __INT_MAX 42 #define HUGE_VALF (float)HUGE_VAL 43 #define HUGE_VALL (long double)HUGE_VAL 44 #define INFINITY HUGE_VALF 45 #define NAN (__nan.__uf) 46 47 #define MATH_ERRNO 1 48 #define MATH_ERREXCEPT 2 49 #define math_errhandling 0 50 51 /* Symbolic constants to classify floating point numbers. */ 52 #define FP_INFINITE 0x01 53 #define FP_NAN 0x02 54 #define FP_NORMAL 0x04 55 #define FP_SUBNORMAL 0x08 56 #define FP_ZERO 0x10 57 #define fpclassify(x) \ 58 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ 59 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ 60 : __fpclassifyl(x)) 61 62 #define isfinite(x) ((fpclassify(x) & (FP_INFINITE|FP_NAN)) == 0) 63 #define isinf(x) (fpclassify(x) == FP_INFINITE) 64 #define isnan(x) (fpclassify(x) == FP_NAN) 65 #define isnormal(x) (fpclassify(x) == FP_NORMAL) 66 67 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) 68 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) 69 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) 70 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) 71 #define islessgreater(x, y) (!isunordered((x), (y)) && \ 72 ((x) > (y) || (y) > (x))) 73 #define isunordered(x, y) (isnan(x) || isnan(y)) 74 75 #define signbit(x) __signbit(x) 76 77 typedef __double_t double_t; 78 typedef __float_t float_t; 79 #endif /* __ISO_C_VISIBLE >= 1999 */ 80 81 /* 82 * XOPEN/SVID 83 */ 84 #if __BSD_VISIBLE || __XSI_VISIBLE 85 #define M_E 2.7182818284590452354 /* e */ 86 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 87 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 88 #define M_LN2 0.69314718055994530942 /* log e2 */ 89 #define M_LN10 2.30258509299404568402 /* log e10 */ 90 #define M_PI 3.14159265358979323846 /* pi */ 91 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 92 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 93 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 94 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 95 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 96 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 97 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 98 99 #define MAXFLOAT ((float)3.40282346638528860e+38) 100 extern int signgam; 101 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 102 103 #if __BSD_VISIBLE 104 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 105 106 #define _LIB_VERSION_TYPE enum fdversion 107 #define _LIB_VERSION _fdlib_version 108 109 /* if global variable _LIB_VERSION is not desirable, one may 110 * change the following to be a constant by: 111 * #define _LIB_VERSION_TYPE const enum version 112 * In that case, after one initializes the value _LIB_VERSION (see 113 * s_lib_version.c) during compile time, it cannot be modified 114 * in the middle of a program 115 */ 116 extern _LIB_VERSION_TYPE _LIB_VERSION; 117 118 #define _IEEE_ fdlibm_ieee 119 #define _SVID_ fdlibm_svid 120 #define _XOPEN_ fdlibm_xopen 121 #define _POSIX_ fdlibm_posix 122 123 /* We have a problem when using C++ since `exception' is a reserved 124 name in C++. */ 125 #ifndef __cplusplus 126 struct exception { 127 int type; 128 char *name; 129 double arg1; 130 double arg2; 131 double retval; 132 }; 133 #endif 134 135 #define isnanf(x) isnan(x) 136 137 #if 0 138 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 139 #define HUGE HUGE_VAL 140 #else 141 #define HUGE MAXFLOAT 142 #endif 143 144 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */ 145 146 #define DOMAIN 1 147 #define SING 2 148 #define OVERFLOW 3 149 #define UNDERFLOW 4 150 #define TLOSS 5 151 #define PLOSS 6 152 153 #endif /* __BSD_VISIBLE */ 154 155 /* 156 * Most of these functions have the side effect of setting errno, so they 157 * are not declared as __pure2. (XXX: this point needs to be revisited, 158 * since C99 doesn't require the mistake of setting errno, and we mostly 159 * don't set it anyway. In C99, pragmas and functions for changing the 160 * rounding mode affect the purity of these functions.) 161 */ 162 __BEGIN_DECLS 163 /* 164 * ANSI/POSIX 165 */ 166 int __fpclassifyd(double) __pure2; 167 int __fpclassifyf(float) __pure2; 168 int __fpclassifyl(long double) __pure2; 169 int __signbit(double) __pure2; 170 171 double acos(double); 172 double asin(double); 173 double atan(double); 174 double atan2(double, double); 175 double cos(double); 176 double sin(double); 177 double tan(double); 178 179 double cosh(double); 180 double sinh(double); 181 double tanh(double); 182 183 double exp(double); 184 double frexp(double, int *); /* fundamentally !__pure2 */ 185 double ldexp(double, int); 186 double log(double); 187 double log10(double); 188 double modf(double, double *); /* fundamentally !__pure2 */ 189 190 double pow(double, double); 191 double sqrt(double); 192 193 double ceil(double); 194 double fabs(double); 195 double floor(double); 196 double fmod(double, double); 197 198 /* 199 * These functions are not in C90 so they can be "right". The ones that 200 * never set errno in lib/msun are declared as __pure2. 201 */ 202 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE 203 double acosh(double); 204 double asinh(double); 205 double atanh(double); 206 double cbrt(double) __pure2; 207 double erf(double); 208 double erfc(double) __pure2; 209 double expm1(double) __pure2; 210 double fdim(double, double); 211 double fmax(double, double) __pure2; 212 double fmin(double, double) __pure2; 213 double hypot(double, double); 214 int ilogb(double); 215 double lgamma(double); 216 double log1p(double) __pure2; 217 double logb(double) __pure2; 218 double nearbyint(double) __pure2; 219 double nextafter(double, double); 220 double remainder(double, double); 221 double rint(double) __pure2; 222 double round(double); 223 double trunc(double); 224 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ 225 226 #if __BSD_VISIBLE || __XSI_VISIBLE 227 double j0(double); 228 double j1(double); 229 double jn(int, double); 230 double scalb(double, double); 231 double y0(double); 232 double y1(double); 233 double yn(int, double); 234 235 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE 236 double gamma(double); 237 #endif 238 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 239 240 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 241 double copysign(double, double) __pure2; 242 double scalbln(double, long); 243 double scalbn(double, int); 244 double tgamma(double); 245 #endif 246 247 /* 248 * BSD math library entry points 249 */ 250 #if __BSD_VISIBLE 251 double drem(double, double); 252 int finite(double) __pure2; 253 254 /* 255 * Reentrant version of gamma & lgamma; passes signgam back by reference 256 * as the second argument; user must allocate space for signgam. 257 */ 258 double gamma_r(double, int *); 259 double lgamma_r(double, int *); 260 261 /* 262 * IEEE Test Vector 263 */ 264 double significand(double); 265 266 #ifndef __cplusplus 267 int matherr(struct exception *); 268 #endif 269 #endif /* __BSD_VISIBLE */ 270 271 /* float versions of ANSI/POSIX functions */ 272 #if __ISO_C_VISIBLE >= 1999 273 float acosf(float); 274 float asinf(float); 275 float atanf(float); 276 float atan2f(float, float); 277 float cosf(float); 278 float sinf(float); 279 float tanf(float); 280 281 float coshf(float); 282 float sinhf(float); 283 float tanhf(float); 284 285 float expf(float); 286 float expm1f(float) __pure2; 287 float frexpf(float, int *); /* fundamentally !__pure2 */ 288 int ilogbf(float); 289 float ldexpf(float, int); 290 float log10f(float); 291 float log1pf(float) __pure2; 292 float logf(float); 293 float modff(float, float *); /* fundamentally !__pure2 */ 294 295 float powf(float, float); 296 float sqrtf(float); 297 298 float ceilf(float); 299 float fabsf(float); 300 float floorf(float); 301 float fmodf(float, float); 302 float roundf(float); 303 304 float erff(float); 305 float erfcf(float) __pure2; 306 float hypotf(float, float) __pure2; 307 float lgammaf(float); 308 309 float acoshf(float); 310 float asinhf(float); 311 float atanhf(float); 312 float cbrtf(float) __pure2; 313 float logbf(float) __pure2; 314 float copysignf(float, float) __pure2; 315 float nearbyintf(float) __pure2; 316 float nextafterf(float, float); 317 float remainderf(float, float); 318 float rintf(float); 319 float scalblnf(float, long); 320 float scalbnf(float, int); 321 float truncf(float); 322 323 float fdimf(float, float); 324 float fmaxf(float, float) __pure2; 325 float fminf(float, float) __pure2; 326 #endif 327 328 /* 329 * float versions of BSD math library entry points 330 */ 331 #if __BSD_VISIBLE 332 float dremf(float, float); 333 int finitef(float) __pure2; 334 float gammaf(float); 335 float j0f(float); 336 float j1f(float); 337 float jnf(int, float); 338 float scalbf(float, float); 339 float y0f(float); 340 float y1f(float); 341 float ynf(int, float); 342 343 /* 344 * Float versions of reentrant version of gamma & lgamma; passes 345 * signgam back by reference as the second argument; user must 346 * allocate space for signgam. 347 */ 348 float gammaf_r(float, int *); 349 float lgammaf_r(float, int *); 350 351 /* 352 * float version of IEEE Test Vector 353 */ 354 float significandf(float); 355 #endif /* __BSD_VISIBLE */ 356 357 /* 358 * long double versions of ISO/POSIX math functions 359 */ 360 #if __ISO_C_VISIBLE >= 1999 361 #if 0 362 long double acoshl(long double); 363 long double acosl(long double); 364 long double asinhl(long double); 365 long double asinl(long double); 366 long double atan2l(long double, long double); 367 long double atanhl(long double); 368 long double atanl(long double); 369 long double cbrtl(long double); 370 long double ceill(long double); 371 #endif 372 long double copysignl(long double, long double); 373 #if 0 374 long double coshl(long double); 375 long double cosl(long double); 376 long double erfcl(long double); 377 long double erfl(long double); 378 long double exp2l(long double); 379 long double expl(long double); 380 long double expm1l(long double); 381 #endif 382 long double fabsl(long double); 383 long double fdiml(long double, long double); 384 #if 0 385 long double floorl(long double); 386 long double fmal(long double, long double, long double); 387 #endif 388 long double fmaxl(long double, long double) __pure2; 389 long double fminl(long double, long double) __pure2; 390 #if 0 391 long double fmodl(long double, long double); 392 long double frexpl(long double value, int *); 393 long double hypotl(long double, long double); 394 int ilogbl(long double); 395 long double ldexpl(long double, int); 396 long double lgammal(long double); 397 long long llrintl(long double); 398 long long llroundl(long double); 399 long double log10l(long double); 400 long double log1pl(long double); 401 long double log2l(long double); 402 long double logbl(long double); 403 long double logl(long double); 404 long lrintl(long double); 405 long lroundl(long double); 406 long double modfl(long double, long double *); 407 long double nanl(const char *); 408 long double nearbyintl(long double); 409 long double nextafterl(long double, long double); 410 double nexttoward(double, long double); 411 float nexttowardf(float, long double); 412 long double nexttowardl(long double, long double); 413 long double powl(long double, long double); 414 long double remainderl(long double, long double); 415 long double remquol(long double, long double, int *); 416 long double rintl(long double); 417 long double roundl(long double); 418 long double scalblnl(long double, long); 419 long double scalbnl(long double, int); 420 long double sinhl(long double); 421 long double sinl(long double); 422 long double sqrtl(long double); 423 long double tanhl(long double); 424 long double tanl(long double); 425 long double tgammal(long double); 426 long double truncl(long double); 427 #endif 428 429 #endif /* __ISO_C_VISIBLE >= 1999 */ 430 __END_DECLS 431 432 #endif /* !_MATH_H_ */ 433