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/_types.h> 21 22 /* 23 * ANSI/POSIX 24 */ 25 extern const union __infinity_un { 26 unsigned char __uc[8]; 27 double __ud; 28 } __infinity; 29 30 extern const union __nan_un { 31 unsigned char __uc[sizeof(float)]; 32 float __uf; 33 } __nan; 34 35 #define HUGE_VAL (__infinity.__ud) 36 37 #if __ISO_C_VISIBLE >= 1999 38 #define FP_ILOGB0 (-0x7fffffff - 1) /* INT_MIN */ 39 #define FP_ILOGBNAN 0x7fffffff /* INT_MAX */ 40 #define HUGE_VALF (float)HUGE_VAL 41 #define HUGE_VALL (long double)HUGE_VAL 42 #define INFINITY HUGE_VALF 43 #define NAN (__nan.__uf) 44 45 #define MATH_ERRNO 1 46 #define MATH_ERREXCEPT 2 47 #define math_errhandling 0 48 49 /* Symbolic constants to classify floating point numbers. */ 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 #define fpclassify(x) \ 56 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ 57 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ 58 : __fpclassifyl(x)) 59 60 #define isfinite(x) ((fpclassify(x) & (FP_INFINITE|FP_NAN)) == 0) 61 #define isinf(x) (fpclassify(x) == FP_INFINITE) 62 #define isnan(x) (fpclassify(x) == FP_NAN) 63 #define isnormal(x) (fpclassify(x) == FP_NORMAL) 64 65 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) 66 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) 67 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) 68 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) 69 #define islessgreater(x, y) (!isunordered((x), (y)) && \ 70 ((x) > (y) || (y) > (x))) 71 #define isunordered(x, y) (isnan(x) || isnan(y)) 72 73 #define signbit(x) __signbit(x) 74 75 typedef __double_t double_t; 76 typedef __float_t float_t; 77 #endif /* __ISO_C_VISIBLE >= 1999 */ 78 79 /* 80 * XOPEN/SVID 81 */ 82 #if __BSD_VISIBLE || __XSI_VISIBLE 83 #define M_E 2.7182818284590452354 /* e */ 84 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 85 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 86 #define M_LN2 0.69314718055994530942 /* log e2 */ 87 #define M_LN10 2.30258509299404568402 /* log e10 */ 88 #define M_PI 3.14159265358979323846 /* pi */ 89 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 90 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 91 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 92 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 93 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 94 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 95 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 96 97 #define MAXFLOAT ((float)3.40282346638528860e+38) 98 extern int signgam; 99 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 100 101 #if __BSD_VISIBLE 102 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 103 104 #define _LIB_VERSION_TYPE enum fdversion 105 #define _LIB_VERSION _fdlib_version 106 107 /* if global variable _LIB_VERSION is not desirable, one may 108 * change the following to be a constant by: 109 * #define _LIB_VERSION_TYPE const enum version 110 * In that case, after one initializes the value _LIB_VERSION (see 111 * s_lib_version.c) during compile time, it cannot be modified 112 * in the middle of a program 113 */ 114 extern _LIB_VERSION_TYPE _LIB_VERSION; 115 116 #define _IEEE_ fdlibm_ieee 117 #define _SVID_ fdlibm_svid 118 #define _XOPEN_ fdlibm_xopen 119 #define _POSIX_ fdlibm_posix 120 121 /* We have a problem when using C++ since `exception' is a reserved 122 name in C++. */ 123 #ifndef __cplusplus 124 struct exception { 125 int type; 126 char *name; 127 double arg1; 128 double arg2; 129 double retval; 130 }; 131 #endif 132 133 #define isnanf(x) isnan(x) 134 135 #if 0 136 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 137 #define HUGE HUGE_VAL 138 #else 139 #define HUGE MAXFLOAT 140 #endif 141 142 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */ 143 144 #define DOMAIN 1 145 #define SING 2 146 #define OVERFLOW 3 147 #define UNDERFLOW 4 148 #define TLOSS 5 149 #define PLOSS 6 150 151 #endif /* __BSD_VISIBLE */ 152 153 #include <sys/cdefs.h> 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 hypot(double, double); 211 int ilogb(double); 212 double lgamma(double); 213 double log1p(double) __pure2; 214 double logb(double) __pure2; 215 double nextafter(double, double); 216 double remainder(double, double); 217 double rint(double) __pure2; 218 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ 219 220 #if __BSD_VISIBLE || __XSI_VISIBLE 221 double j0(double); 222 double j1(double); 223 double jn(int, double); 224 double scalb(double, double); 225 double y0(double); 226 double y1(double); 227 double yn(int, double); 228 229 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE 230 double gamma(double); 231 #endif 232 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */ 233 234 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 235 double copysign(double, double) __pure2; 236 double scalbn(double, int); 237 double tgamma(double); 238 #endif 239 240 /* 241 * BSD math library entry points 242 */ 243 #if __BSD_VISIBLE 244 double drem(double, double); 245 int finite(double) __pure2; 246 247 /* 248 * Reentrant version of gamma & lgamma; passes signgam back by reference 249 * as the second argument; user must allocate space for signgam. 250 */ 251 double gamma_r(double, int *); 252 double lgamma_r(double, int *); 253 254 /* 255 * IEEE Test Vector 256 */ 257 double significand(double); 258 259 #ifndef __cplusplus 260 int matherr(struct exception *); 261 #endif 262 #endif /* __BSD_VISIBLE */ 263 264 /* float versions of ANSI/POSIX functions */ 265 #if __ISO_C_VISIBLE >= 1999 266 float acosf(float); 267 float asinf(float); 268 float atanf(float); 269 float atan2f(float, float); 270 float cosf(float); 271 float sinf(float); 272 float tanf(float); 273 274 float coshf(float); 275 float sinhf(float); 276 float tanhf(float); 277 278 float expf(float); 279 float expm1f(float) __pure2; 280 float frexpf(float, int *); /* fundamentally !__pure2 */ 281 int ilogbf(float); 282 float ldexpf(float, int); 283 float log10f(float); 284 float log1pf(float) __pure2; 285 float logf(float); 286 float modff(float, float *); /* fundamentally !__pure2 */ 287 288 float powf(float, float); 289 float sqrtf(float); 290 291 float ceilf(float); 292 float fabsf(float); 293 float floorf(float); 294 float fmodf(float, float); 295 296 float erff(float); 297 float erfcf(float) __pure2; 298 float hypotf(float, float) __pure2; 299 float lgammaf(float); 300 301 float acoshf(float); 302 float asinhf(float); 303 float atanhf(float); 304 float cbrtf(float) __pure2; 305 float logbf(float) __pure2; 306 float copysignf(float, float) __pure2; 307 float nextafterf(float, float); 308 float remainderf(float, float); 309 float rintf(float); 310 float scalbnf(float, int); 311 #endif 312 313 /* 314 * float versions of BSD math library entry points 315 */ 316 #if __BSD_VISIBLE 317 float dremf(float, float); 318 int finitef(float) __pure2; 319 float gammaf(float); 320 float j0f(float); 321 float j1f(float); 322 float jnf(int, float); 323 float scalbf(float, float); 324 float y0f(float); 325 float y1f(float); 326 float ynf(int, float); 327 328 /* 329 * Float versions of reentrant version of gamma & lgamma; passes 330 * signgam back by reference as the second argument; user must 331 * allocate space for signgam. 332 */ 333 float gammaf_r(float, int *); 334 float lgammaf_r(float, int *); 335 336 /* 337 * float version of IEEE Test Vector 338 */ 339 float significandf(float); 340 #endif /* __BSD_VISIBLE */ 341 342 /* 343 * long double versions of ISO/POSIX math functions 344 */ 345 #if __ISO_C_VISIBLE >= 1999 346 #if 0 347 long double acoshl(long double); 348 long double acosl(long double); 349 long double asinhl(long double); 350 long double asinl(long double); 351 long double atan2l(long double, long double); 352 long double atanhl(long double); 353 long double atanl(long double); 354 long double cbrtl(long double); 355 long double ceill(long double); 356 #endif 357 long double copysignl(long double, long double); 358 #if 0 359 long double coshl(long double); 360 long double cosl(long double); 361 long double erfcl(long double); 362 long double erfl(long double); 363 long double exp2l(long double); 364 long double expl(long double); 365 long double expm1l(long double); 366 #endif 367 long double fabsl(long double); 368 #if 0 369 long double fdiml(long double, long double); 370 long double floorl(long double); 371 long double fmal(long double, long double, long double); 372 long double fmaxl(long double, long double); 373 long double fminl(long double, long double); 374 long double fmodl(long double, long double); 375 long double frexpl(long double value, int *); 376 long double hypotl(long double, long double); 377 int ilogbl(long double); 378 long double ldexpl(long double, int); 379 long double lgammal(long double); 380 long long llrintl(long double); 381 long long llroundl(long double); 382 long double log10l(long double); 383 long double log1pl(long double); 384 long double log2l(long double); 385 long double logbl(long double); 386 long double logl(long double); 387 long lrintl(long double); 388 long lroundl(long double); 389 long double modfl(long double, long double *); 390 long double nanl(const char *); 391 long double nearbyintl(long double); 392 long double nextafterl(long double, long double); 393 double nexttoward(double, long double); 394 float nexttowardf(float, long double); 395 long double nexttowardl(long double, long double); 396 long double powl(long double, long double); 397 long double remainderl(long double, long double); 398 long double remquol(long double, long double, int *); 399 long double rintl(long double); 400 long double roundl(long double); 401 long double scalblnl(long double, long); 402 long double scalbnl(long double, int); 403 long double sinhl(long double); 404 long double sinl(long double); 405 long double sqrtl(long double); 406 long double tanhl(long double); 407 long double tanl(long double); 408 long double tgammal(long double); 409 long double truncl(long double); 410 #endif 411 412 #endif /* __ISO_C_VISIBLE >= 1999 */ 413 __END_DECLS 414 415 #endif /* !_MATH_H_ */ 416