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 FP_ILOGB0 (-0x7fffffff - 1) /* INT_MIN */ 36 #define FP_ILOGBNAN 0x7fffffff /* INT_MAX */ 37 #define HUGE_VAL (__infinity.__ud) 38 #define HUGE_VALF (float)HUGE_VAL 39 #define HUGE_VALL (long double)HUGE_VAL 40 #define INFINITY HUGE_VALF 41 #define NAN (__nan.__uf) 42 43 #if __ISO_C_VISIBLE >= 1999 44 #define MATH_ERRNO 1 45 #define MATH_ERREXCEPT 2 46 #define math_errhandling 0 47 #endif 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 isnanf(x) isnan(x) 64 #define isnormal(x) (fpclassify(x) == FP_NORMAL) 65 66 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) 67 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) 68 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) 69 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) 70 #define islessgreater(x, y) (!isunordered((x), (y)) && \ 71 ((x) > (y) || (y) > (x))) 72 #define isunordered(x, y) (isnan(x) || isnan(y)) 73 74 #define signbit(x) __signbit(x) 75 76 typedef __double_t double_t; 77 typedef __float_t float_t; 78 79 /* 80 * XOPEN/SVID 81 */ 82 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 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 100 #if !defined(_XOPEN_SOURCE) 101 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 102 103 #define _LIB_VERSION_TYPE enum fdversion 104 #define _LIB_VERSION _fdlib_version 105 106 /* if global variable _LIB_VERSION is not desirable, one may 107 * change the following to be a constant by: 108 * #define _LIB_VERSION_TYPE const enum version 109 * In that case, after one initializes the value _LIB_VERSION (see 110 * s_lib_version.c) during compile time, it cannot be modified 111 * in the middle of a program 112 */ 113 extern _LIB_VERSION_TYPE _LIB_VERSION; 114 115 #define _IEEE_ fdlibm_ieee 116 #define _SVID_ fdlibm_svid 117 #define _XOPEN_ fdlibm_xopen 118 #define _POSIX_ fdlibm_posix 119 120 /* We have a problem when using C++ since `exception' is a reserved 121 name in C++. */ 122 #ifndef __cplusplus 123 struct exception { 124 int type; 125 char *name; 126 double arg1; 127 double arg2; 128 double retval; 129 }; 130 #endif 131 132 #if 0 133 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 134 #define HUGE HUGE_VAL 135 #else 136 #define HUGE MAXFLOAT 137 #endif 138 139 /* 140 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 141 * (one may replace the following line by "#include <values.h>") 142 */ 143 144 #define X_TLOSS 1.41484755040568800000e+16 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 /* !_XOPEN_SOURCE */ 154 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 155 156 #include <sys/cdefs.h> 157 158 /* 159 * Most of these functions have the side effect of setting errno, so they 160 * are not declared as __pure2. (XXX: this point needs to be revisited, 161 * since C99 doesn't require the mistake of setting errno, and we mostly 162 * don't set it anyway. In C99, pragmas and functions for changing the 163 * rounding mode affect the purity of these functions.) 164 */ 165 __BEGIN_DECLS 166 /* 167 * ANSI/POSIX 168 */ 169 int __fpclassifyd(double) __pure2; 170 int __fpclassifyf(float) __pure2; 171 int __fpclassifyl(long double) __pure2; 172 int __signbit(double) __pure2; 173 174 double acos(double); 175 double asin(double); 176 double atan(double); 177 double atan2(double, double); 178 double cos(double); 179 double sin(double); 180 double tan(double); 181 182 double cosh(double); 183 double sinh(double); 184 double tanh(double); 185 186 double exp(double); 187 double frexp(double, int *); /* fundamentally !__pure2 */ 188 double ldexp(double, int); 189 double log(double); 190 double log10(double); 191 double modf(double, double *); /* fundamentally !__pure2 */ 192 193 double pow(double, double); 194 double sqrt(double); 195 196 double ceil(double); 197 double fabs(double); 198 double floor(double); 199 double fmod(double, double); 200 201 /* 202 * These functions are not in C90 so they can be "right". The ones that 203 * never set errno in lib/msun are declared as __pure2. 204 */ 205 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 206 double erf(double); 207 double erfc(double) __pure2; 208 int finite(double) __pure2; 209 double gamma(double); 210 double hypot(double, double); 211 double j0(double); 212 double j1(double); 213 double jn(int, double); 214 double lgamma(double); 215 double y0(double); 216 double y1(double); 217 double yn(int, double); 218 219 #if !defined(_XOPEN_SOURCE) 220 double acosh(double); 221 double asinh(double); 222 double atanh(double); 223 double cbrt(double) __pure2; 224 double logb(double) __pure2; 225 double nextafter(double, double); 226 double remainder(double, double); 227 double scalb(double, double); 228 double tgamma(double); 229 230 #ifndef __cplusplus 231 int matherr(struct exception *); 232 #endif 233 234 /* 235 * IEEE Test Vector 236 */ 237 double significand(double); 238 239 /* 240 * Functions callable from C, intended to support IEEE arithmetic. 241 */ 242 double copysign(double, double) __pure2; 243 int ilogb(double); 244 double rint(double) __pure2; 245 double scalbn(double, int); 246 247 /* 248 * BSD math library entry points 249 */ 250 double drem(double, double); 251 double expm1(double) __pure2; 252 double log1p(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 #if __BSD_VISIBLE 259 double gamma_r(double, int *); 260 double lgamma_r(double, int *); 261 #endif /* __BSD_VISIBLE */ 262 263 /* float versions of ANSI/POSIX functions */ 264 float acosf(float); 265 float asinf(float); 266 float atanf(float); 267 float atan2f(float, float); 268 float cosf(float); 269 float sinf(float); 270 float tanf(float); 271 272 float coshf(float); 273 float sinhf(float); 274 float tanhf(float); 275 276 float expf(float); 277 float frexpf(float, int *); /* fundamentally !__pure2 */ 278 float ldexpf(float, int); 279 float logf(float); 280 float log10f(float); 281 float modff(float, float *); /* fundamentally !__pure2 */ 282 283 float powf(float, float); 284 float sqrtf(float); 285 286 float ceilf(float); 287 float fabsf(float); 288 float floorf(float); 289 float fmodf(float, float); 290 291 float erff(float); 292 float erfcf(float) __pure2; 293 int finitef(float) __pure2; 294 float gammaf(float); 295 float hypotf(float, float) __pure2; 296 float j0f(float); 297 float j1f(float); 298 float jnf(int, float); 299 float lgammaf(float); 300 float y0f(float); 301 float y1f(float); 302 float ynf(int, float); 303 304 float acoshf(float); 305 float asinhf(float); 306 float atanhf(float); 307 float cbrtf(float) __pure2; 308 float logbf(float) __pure2; 309 float nextafterf(float, float); 310 float remainderf(float, float); 311 float scalbf(float, float); 312 313 /* 314 * float version of IEEE Test Vector 315 */ 316 float significandf(float); 317 318 /* 319 * Float versions of functions callable from C, intended to support 320 * IEEE arithmetic. 321 */ 322 float copysignf(float, float) __pure2; 323 int ilogbf(float); 324 float rintf(float); 325 float scalbnf(float, int); 326 327 /* 328 * float versions of BSD math library entry points 329 */ 330 float dremf(float, float); 331 float expm1f(float) __pure2; 332 float log1pf(float) __pure2; 333 334 /* 335 * Float versions of reentrant version of gamma & lgamma; passes 336 * signgam back by reference as the second argument; user must 337 * allocate space for signgam. 338 */ 339 #if __BSD_VISIBLE 340 float gammaf_r(float, int *); 341 float lgammaf_r(float, int *); 342 #endif /* __BSD_VISIBLE */ 343 344 /* 345 * long double versions of ISO/POSIX math functions 346 */ 347 #if 0 348 long double acoshl(long double); 349 long double acosl(long double); 350 long double asinhl(long double); 351 long double asinl(long double); 352 long double atan2l(long double, long double); 353 long double atanhl(long double); 354 long double atanl(long double); 355 long double cbrtl(long double); 356 long double ceill(long double); 357 long double copysignl(long double, long double); 358 long double coshl(long double); 359 long double cosl(long double); 360 long double erfcl(long double); 361 long double erfl(long double); 362 long double exp2l(long double); 363 long double expl(long double); 364 long double expm1l(long double); 365 #endif 366 long double fabsl(long double); 367 #if 0 368 long double fdiml(long double, long double); 369 long double floorl(long double); 370 long double fmal(long double, long double, long double); 371 long double fmaxl(long double, long double); 372 long double fminl(long double, long double); 373 long double fmodl(long double, long double); 374 long double frexpl(long double value, int *); 375 long double hypotl(long double, long double); 376 int ilogbl(long double); 377 long double ldexpl(long double, int); 378 long double lgammal(long double); 379 long long llrintl(long double); 380 long long llroundl(long double); 381 long double log10l(long double); 382 long double log1pl(long double); 383 long double log2l(long double); 384 long double logbl(long double); 385 long double logl(long double); 386 long lrintl(long double); 387 long lroundl(long double); 388 long double modfl(long double, long double *); 389 long double nanl(const char *); 390 long double nearbyintl(long double); 391 long double nextafterl(long double, long double); 392 double nexttoward(double, long double); 393 float nexttowardf(float, long double); 394 long double nexttowardl(long double, long double); 395 long double powl(long double, long double); 396 long double remainderl(long double, long double); 397 long double remquol(long double, long double, int *); 398 long double rintl(long double); 399 long double roundl(long double); 400 long double scalblnl(long double, long); 401 long double scalbnl(long double, int); 402 long double sinhl(long double); 403 long double sinl(long double); 404 long double sqrtl(long double); 405 long double tanhl(long double); 406 long double tanl(long double); 407 long double tgammal(long double); 408 long double truncl(long double); 409 #endif 410 411 #endif /* !_XOPEN_SOURCE */ 412 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 413 __END_DECLS 414 415 #endif /* !_MATH_H_ */ 416