math.h (9222B)
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 #ifndef _MATH_H_ 13 #define _MATH_H_ 14 15 16 /* 17 * ANSI/POSIX 18 */ 19 extern const union __infinity_un { 20 unsigned char __uc[8]; 21 double __ud; 22 } __infinity; 23 24 extern const union __nan_un { 25 unsigned char __uc[sizeof(float)]; 26 float __uf; 27 } __nan; 28 29 #define HUGE_VAL __builtin_huge_val() 30 31 #define FP_ILOGB0 (-INT_MAX) 32 #define FP_ILOGBNAN INT_MAX 33 34 #define HUGE_VALF __builtin_huge_valf() 35 #define HUGE_VALL __builtin_huge_vall() 36 #define INFINITY __builtin_inf() 37 #define NAN __builtin_nan("") 38 39 #define MATH_ERRNO 1 40 #define MATH_ERREXCEPT 2 41 #define math_errhandling MATH_ERREXCEPT 42 43 #define FP_FAST_FMAF 44 45 /* Symbolic constants to classify floating point numbers. */ 46 #define FP_INFINITE 0x01 47 #define FP_NAN 0x02 48 #define FP_NORMAL 0x04 49 #define FP_SUBNORMAL 0x08 50 #define FP_ZERO 0x10 51 #define fpclassify(x) \ 52 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ 53 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ 54 : __fpclassifyl(x)) 55 56 #define isfinite(x) \ 57 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \ 58 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \ 59 : __isfinitel(x)) 60 #define isinf(x) \ 61 ((sizeof (x) == sizeof (float)) ? __isinff(x) \ 62 : (sizeof (x) == sizeof (double)) ? isinf(x) \ 63 : __isinfl(x)) 64 #define isnan(x) \ 65 ((sizeof (x) == sizeof (float)) ? isnanf(x) \ 66 : (sizeof (x) == sizeof (double)) ? isnan(x) \ 67 : __isnanl(x)) 68 #define isnormal(x) \ 69 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \ 70 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \ 71 : __isnormall(x)) 72 73 #define isgreater(x, y) __builtin_isgreater((x), (y)) 74 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) 75 #define isless(x, y) __builtin_isless((x), (y)) 76 #define islessequal(x, y) __builtin_islessequal((x), (y)) 77 #define islessgreater(x, y) __builtin_islessgreater((x), (y)) 78 #define isunordered(x, y) __builtin_isunordered((x), (y)) 79 80 #define signbit(x) \ 81 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \ 82 : (sizeof (x) == sizeof (double)) ? __signbit(x) \ 83 : __signbitl(x)) 84 85 86 /* FLT_EVAL_METHOD = 0 (float.h) */ 87 typedef double double_t; 88 typedef float float_t; 89 90 91 /* 92 * XOPEN/SVID 93 */ 94 #define M_E 2.7182818284590452354 /* e */ 95 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 96 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 97 #define M_LN2 0.69314718055994530942 /* log e2 */ 98 #define M_LN10 2.30258509299404568402 /* log e10 */ 99 #define M_PI 3.14159265358979323846 /* pi */ 100 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 101 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 102 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 103 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 104 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 105 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 106 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 107 108 #define MAXFLOAT ((float)3.40282346638528860e+38) 109 extern int signgam; 110 111 #if __BSD_VISIBLE 112 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 113 114 #define _LIB_VERSION_TYPE enum fdversion 115 #define _LIB_VERSION _fdlib_version 116 117 /* if global variable _LIB_VERSION is not desirable, one may 118 * change the following to be a constant by: 119 * #define _LIB_VERSION_TYPE const enum version 120 * In that case, after one initializes the value _LIB_VERSION (see 121 * s_lib_version.c) during compile time, it cannot be modified 122 * in the middle of a program 123 */ 124 extern _LIB_VERSION_TYPE _LIB_VERSION; 125 126 #define _IEEE_ fdlibm_ieee 127 #define _SVID_ fdlibm_svid 128 #define _XOPEN_ fdlibm_xopen 129 #define _POSIX_ fdlibm_posix 130 131 /* We have a problem when using C++ since `exception' is a reserved 132 name in C++. */ 133 #ifndef __cplusplus 134 struct exception { 135 int type; 136 char *name; 137 double arg1; 138 double arg2; 139 double retval; 140 }; 141 #endif 142 143 #if 0 144 /* Old value from 4.4BSD-Lite math.h; this is probably better. */ 145 #define HUGE HUGE_VAL 146 #else 147 #define HUGE MAXFLOAT 148 #endif 149 150 #define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */ 151 152 #define DOMAIN 1 153 #define SING 2 154 #define OVERFLOW 3 155 #define UNDERFLOW 4 156 #define TLOSS 5 157 #define PLOSS 6 158 159 #endif /* __BSD_VISIBLE */ 160 161 /* 162 * Most of these functions depend on the rounding mode and have the side 163 * effect of raising floating-point exceptions, so they are not declared 164 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions. 165 */ 166 #define __pure2 __attribute__((__const__)) 167 168 /* 169 * ANSI/POSIX 170 */ 171 int __fpclassifyd(double) __pure2; 172 int __fpclassifyf(float) __pure2; 173 int __fpclassifyl(long double) __pure2; 174 int __isfinitef(float) __pure2; 175 int __isfinite(double) __pure2; 176 int __isfinitel(long double) __pure2; 177 int __isinff(float) __pure2; 178 int __isinfl(long double) __pure2; 179 int __isnanl(long double) __pure2; 180 int __isnormalf(float) __pure2; 181 int __isnormal(double) __pure2; 182 int __isnormall(long double) __pure2; 183 int __signbit(double) __pure2; 184 int __signbitf(float) __pure2; 185 int __signbitl(long double) __pure2; 186 187 double acos(double); 188 double asin(double); 189 double atan(double); 190 double atan2(double, double); 191 double cos(double); 192 double sin(double); 193 double tan(double); 194 195 double cosh(double); 196 double sinh(double); 197 double tanh(double); 198 199 double exp(double); 200 double frexp(double, int *); /* fundamentally !__pure2 */ 201 double ldexp(double, int); 202 double log(double); 203 double log10(double); 204 double modf(double, double *); /* fundamentally !__pure2 */ 205 206 double pow(double, double); 207 double sqrt(double); 208 209 double ceil(double); 210 double fabs(double) __pure2; 211 double floor(double); 212 double fmod(double, double); 213 214 /* 215 * These functions are not in C90. 216 */ 217 double acosh(double); 218 double asinh(double); 219 double atanh(double); 220 double cbrt(double); 221 double erf(double); 222 double erfc(double); 223 double expm1(double); 224 double hypot(double, double); 225 /* Our ilogb raises no exceptions; we side with IEEE-754R and C99, not POSIX */ 226 int ilogb(double) __pure2; 227 int (isinf)(double) __pure2; 228 int (isnan)(double) __pure2; 229 double lgamma(double); 230 long long llrint(double); 231 long long llround(double); 232 double log1p(double); 233 double logb(double); 234 long lrint(double); 235 long lround(double); 236 double nextafter(double, double); 237 double remainder(double, double); 238 double rint(double); 239 240 double j0(double); 241 double j1(double); 242 double jn(int, double); 243 double scalb(double, double); 244 double y0(double); 245 double y1(double); 246 double yn(int, double); 247 248 double copysign(double, double) __pure2; 249 double fdim(double, double); 250 double fmax(double, double) __pure2; 251 double fmin(double, double) __pure2; 252 double nearbyint(double); 253 double round(double); 254 double scalbln(double, long); 255 double scalbn(double, int); 256 double tgamma(double); 257 double trunc(double); 258 259 /* 260 * BSD math library entry points 261 */ 262 double drem(double, double); 263 int finite(double) __pure2; 264 int isnanf(float) __pure2; 265 266 /* 267 * Reentrant version of gamma & lgamma; passes signgam back by reference 268 * as the second argument; user must allocate space for signgam. 269 */ 270 double gamma_r(double, int *); 271 double lgamma_r(double, int *); 272 273 /* 274 * IEEE Test Vector 275 */ 276 double significand(double); 277 278 279 /* float versions of ANSI/POSIX functions */ 280 float acosf(float); 281 float asinf(float); 282 float atanf(float); 283 float atan2f(float, float); 284 float cosf(float); 285 float sinf(float); 286 float tanf(float); 287 288 float coshf(float); 289 float sinhf(float); 290 float tanhf(float); 291 292 float expf(float); 293 float expm1f(float); 294 float frexpf(float, int *); /* fundamentally !__pure2 */ 295 int ilogbf(float) __pure2; 296 float ldexpf(float, int); 297 float log10f(float); 298 float log1pf(float); 299 float logf(float); 300 float modff(float, float *); /* fundamentally !__pure2 */ 301 302 float powf(float, float); 303 float sqrtf(float); 304 305 float ceilf(float); 306 float fabsf(float) __pure2; 307 float floorf(float); 308 float fmodf(float, float); 309 float roundf(float); 310 311 float erff(float); 312 float erfcf(float); 313 float hypotf(float, float); 314 float lgammaf(float); 315 316 float acoshf(float); 317 float asinhf(float); 318 float atanhf(float); 319 float cbrtf(float); 320 float logbf(float); 321 float copysignf(float, float) __pure2; 322 long long llrintf(float); 323 long long llroundf(float); 324 long lrintf(float); 325 long lroundf(float); 326 float nearbyintf(float); 327 float nextafterf(float, float); 328 float remainderf(float, float); 329 float rintf(float); 330 float scalblnf(float, long); 331 float scalbnf(float, int); 332 float truncf(float); 333 334 float fdimf(float, float); 335 float fmaxf(float, float) __pure2; 336 float fminf(float, float) __pure2; 337 338 /* 339 * float versions of BSD math library entry points 340 */ 341 float dremf(float, float); 342 int finitef(float) __pure2; 343 float gammaf(float); 344 float j0f(float); 345 float j1f(float); 346 float jnf(int, float); 347 float scalbf(float, float); 348 float y0f(float); 349 float y1f(float); 350 float ynf(int, float); 351 352 /* 353 * Float versions of reentrant version of gamma & lgamma; passes 354 * signgam back by reference as the second argument; user must 355 * allocate space for signgam. 356 */ 357 float gammaf_r(float, int *); 358 float lgammaf_r(float, int *); 359 360 /* 361 * float version of IEEE Test Vector 362 */ 363 float significandf(float); 364 365 #endif /* !_MATH_H_ */