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 /* Symbolic constants to classify floating point numbers. */ 44 #define FP_INFINITE 0x01 45 #define FP_NAN 0x02 46 #define FP_NORMAL 0x04 47 #define FP_SUBNORMAL 0x08 48 #define FP_ZERO 0x10 49 #define fpclassify(x) \ 50 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ 51 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ 52 : __fpclassifyl(x)) 53 54 #define isfinite(x) ((fpclassify(x) & (FP_INFINITE|FP_NAN)) == 0) 55 #define isinf(x) (fpclassify(x) == FP_INFINITE) 56 #define isnan(x) (fpclassify(x) == FP_NAN) 57 #define isnanf(x) isnan(x) 58 #define isnormal(x) (fpclassify(x) == FP_NORMAL) 59 60 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) 61 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) 62 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) 63 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) 64 #define islessgreater(x, y) (!isunordered((x), (y)) && \ 65 ((x) > (y) || (y) > (x))) 66 #define isunordered(x, y) (isnan(x) || isnan(y)) 67 68 #define signbit(x) __signbit(x) 69 70 typedef __double_t double_t; 71 typedef __float_t float_t; 72 73 /* 74 * XOPEN/SVID 75 */ 76 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 77 #define M_E 2.7182818284590452354 /* e */ 78 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 79 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 80 #define M_LN2 0.69314718055994530942 /* log e2 */ 81 #define M_LN10 2.30258509299404568402 /* log e10 */ 82 #define M_PI 3.14159265358979323846 /* pi */ 83 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 84 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 85 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 86 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 87 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 88 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 89 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 90 91 #define MAXFLOAT ((float)3.40282346638528860e+38) 92 extern int signgam; 93 94 #if !defined(_XOPEN_SOURCE) 95 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 96 97 #define _LIB_VERSION_TYPE enum fdversion 98 #define _LIB_VERSION _fdlib_version 99 100 /* if global variable _LIB_VERSION is not desirable, one may 101 * change the following to be a constant by: 102 * #define _LIB_VERSION_TYPE const enum version 103 * In that case, after one initializes the value _LIB_VERSION (see 104 * s_lib_version.c) during compile time, it cannot be modified 105 * in the middle of a program 106 */ 107 extern _LIB_VERSION_TYPE _LIB_VERSION; 108 109 #define _IEEE_ fdlibm_ieee 110 #define _SVID_ fdlibm_svid 111 #define _XOPEN_ fdlibm_xopen 112 #define _POSIX_ fdlibm_posix 113 114 /* We have a problem when using C++ since `exception' is a reserved 115 name in C++. */ 116 #ifndef __cplusplus 117 struct exception { 118 int type; 119 char *name; 120 double arg1; 121 double arg2; 122 double retval; 123 }; 124 #endif 125 126 #if 0 127 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 128 #define HUGE HUGE_VAL 129 #else 130 #define HUGE MAXFLOAT 131 #endif 132 133 /* 134 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 135 * (one may replace the following line by "#include <values.h>") 136 */ 137 138 #define X_TLOSS 1.41484755040568800000e+16 139 140 #define DOMAIN 1 141 #define SING 2 142 #define OVERFLOW 3 143 #define UNDERFLOW 4 144 #define TLOSS 5 145 #define PLOSS 6 146 147 #endif /* !_XOPEN_SOURCE */ 148 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 149 150 #include <sys/cdefs.h> 151 152 /* 153 * Most of these functions have the side effect of setting errno, so they 154 * are not declared as __pure2. (XXX: this point needs to be revisited, 155 * since C99 doesn't require the mistake of setting errno, and we mostly 156 * don't set it anyway. In C99, pragmas and functions for changing the 157 * rounding mode affect the purity of these functions.) 158 */ 159 __BEGIN_DECLS 160 /* 161 * ANSI/POSIX 162 */ 163 int __fpclassifyd(double) __pure2; 164 int __fpclassifyf(float) __pure2; 165 int __fpclassifyl(long double) __pure2; 166 int __signbit(double) __pure2; 167 168 double acos(double); 169 double asin(double); 170 double atan(double); 171 double atan2(double, double); 172 double cos(double); 173 double sin(double); 174 double tan(double); 175 176 double cosh(double); 177 double sinh(double); 178 double tanh(double); 179 180 double exp(double); 181 double frexp(double, int *); /* fundamentally !__pure2 */ 182 double ldexp(double, int); 183 double log(double); 184 double log10(double); 185 double modf(double, double *); /* fundamentally !__pure2 */ 186 187 double pow(double, double); 188 double sqrt(double); 189 190 double ceil(double); 191 double fabs(double); 192 double floor(double); 193 double fmod(double, double); 194 195 /* 196 * These functions are not in C90 so they can be "right". The ones that 197 * never set errno in lib/msun are declared as __pure2. 198 */ 199 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 200 double erf(double); 201 double erfc(double) __pure2; 202 int finite(double) __pure2; 203 double gamma(double); 204 double hypot(double, double); 205 double j0(double); 206 double j1(double); 207 double jn(int, double); 208 double lgamma(double); 209 double y0(double); 210 double y1(double); 211 double yn(int, double); 212 213 #if !defined(_XOPEN_SOURCE) 214 double acosh(double); 215 double asinh(double); 216 double atanh(double); 217 double cbrt(double) __pure2; 218 double logb(double) __pure2; 219 double nextafter(double, double); 220 double remainder(double, double); 221 double scalb(double, double); 222 double tgamma(double); 223 224 #ifndef __cplusplus 225 int matherr(struct exception *); 226 #endif 227 228 /* 229 * IEEE Test Vector 230 */ 231 double significand(double); 232 233 /* 234 * Functions callable from C, intended to support IEEE arithmetic. 235 */ 236 double copysign(double, double) __pure2; 237 int ilogb(double); 238 double rint(double) __pure2; 239 double scalbn(double, int); 240 241 /* 242 * BSD math library entry points 243 */ 244 double drem(double, double); 245 double expm1(double) __pure2; 246 double log1p(double) __pure2; 247 248 /* 249 * Reentrant version of gamma & lgamma; passes signgam back by reference 250 * as the second argument; user must allocate space for signgam. 251 */ 252 #if __BSD_VISIBLE 253 double gamma_r(double, int *); 254 double lgamma_r(double, int *); 255 #endif /* __BSD_VISIBLE */ 256 257 /* float versions of ANSI/POSIX functions */ 258 float acosf(float); 259 float asinf(float); 260 float atanf(float); 261 float atan2f(float, float); 262 float cosf(float); 263 float sinf(float); 264 float tanf(float); 265 266 float coshf(float); 267 float sinhf(float); 268 float tanhf(float); 269 270 float expf(float); 271 float frexpf(float, int *); /* fundamentally !__pure2 */ 272 float ldexpf(float, int); 273 float logf(float); 274 float log10f(float); 275 float modff(float, float *); /* fundamentally !__pure2 */ 276 277 float powf(float, float); 278 float sqrtf(float); 279 280 float ceilf(float); 281 float fabsf(float); 282 float floorf(float); 283 float fmodf(float, float); 284 285 float erff(float); 286 float erfcf(float) __pure2; 287 int finitef(float) __pure2; 288 float gammaf(float); 289 float hypotf(float, float) __pure2; 290 float j0f(float); 291 float j1f(float); 292 float jnf(int, float); 293 float lgammaf(float); 294 float y0f(float); 295 float y1f(float); 296 float ynf(int, float); 297 298 float acoshf(float); 299 float asinhf(float); 300 float atanhf(float); 301 float cbrtf(float) __pure2; 302 float logbf(float) __pure2; 303 float nextafterf(float, float); 304 float remainderf(float, float); 305 float scalbf(float, float); 306 307 /* 308 * float version of IEEE Test Vector 309 */ 310 float significandf(float); 311 312 /* 313 * Float versions of functions callable from C, intended to support 314 * IEEE arithmetic. 315 */ 316 float copysignf(float, float) __pure2; 317 int ilogbf(float); 318 float rintf(float); 319 float scalbnf(float, int); 320 321 /* 322 * float versions of BSD math library entry points 323 */ 324 float dremf(float, float); 325 float expm1f(float) __pure2; 326 float log1pf(float) __pure2; 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 #if __BSD_VISIBLE 334 float gammaf_r(float, int *); 335 float lgammaf_r(float, int *); 336 #endif /* __BSD_VISIBLE */ 337 338 #endif /* !_XOPEN_SOURCE */ 339 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 340 __END_DECLS 341 342 #endif /* !_MATH_H_ */ 343