| 1 | /* $NetBSD: math.h,v 1.40 2005/02/03 04:39:32 perry Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * ==================================================== |
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 6 | * |
| 7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
| 8 | * Permission to use, copy, modify, and distribute this |
| 9 | * software is freely granted, provided that this notice |
| 10 | * is preserved. |
| 11 | * ==================================================== |
| 12 | * |
| 13 | * $NetBSD: math.h,v 1.40 2005/02/03 04:39:32 perry Exp $ |
| 14 | * $DragonFly: src/include/math.h,v 1.8 2006/05/17 14:06:36 swildner Exp $ |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * @(#)fdlibm.h 5.1 93/09/24 |
| 19 | */ |
| 20 | |
| 21 | #ifndef _MATH_H_ |
| 22 | #define _MATH_H_ |
| 23 | |
| 24 | #include <sys/cdefs.h> |
| 25 | |
| 26 | #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) |
| 27 | #define __MATH_BUILTIN_CONSTANTS |
| 28 | #endif |
| 29 | |
| 30 | #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) |
| 31 | #define __MATH_BUILTIN_RELOPS |
| 32 | #endif |
| 33 | |
| 34 | union __float_u { |
| 35 | unsigned char __dummy[sizeof(float)]; |
| 36 | float __val; |
| 37 | }; |
| 38 | |
| 39 | union __double_u { |
| 40 | unsigned char __dummy[sizeof(double)]; |
| 41 | double __val; |
| 42 | }; |
| 43 | |
| 44 | union __long_double_u { |
| 45 | unsigned char __dummy[sizeof(long double)]; |
| 46 | long double __val; |
| 47 | }; |
| 48 | |
| 49 | #include <machine/math.h> |
| 50 | |
| 51 | #ifdef __HAVE_LONG_DOUBLE |
| 52 | #define __fpmacro_unary_floating(__name, __arg0) \ |
| 53 | /* LINTED */ \ |
| 54 | ((sizeof (__arg0) == sizeof (float)) \ |
| 55 | ? __ ## __name ## f (__arg0) \ |
| 56 | : (sizeof (__arg0) == sizeof (double)) \ |
| 57 | ? __ ## __name ## d (__arg0) \ |
| 58 | : __ ## __name ## l (__arg0)) |
| 59 | #else |
| 60 | #define __fpmacro_unary_floating(__name, __arg0) \ |
| 61 | /* LINTED */ \ |
| 62 | ((sizeof (__arg0) == sizeof (float)) \ |
| 63 | ? __ ## __name ## f (__arg0) \ |
| 64 | : __ ## __name ## d (__arg0)) |
| 65 | #endif /* __HAVE_LONG_DOUBLE */ |
| 66 | |
| 67 | /* |
| 68 | * ANSI/POSIX |
| 69 | */ |
| 70 | /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ |
| 71 | extern __const union __double_u __infinity; |
| 72 | #ifdef __MATH_BUILTIN_CONSTANTS |
| 73 | #define HUGE_VAL __builtin_huge_val() |
| 74 | #else |
| 75 | #define HUGE_VAL __infinity.__val |
| 76 | #endif |
| 77 | |
| 78 | /* |
| 79 | * ISO C99 |
| 80 | */ |
| 81 | #if __ISO_C_VISIBLE >= 1999 |
| 82 | /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ |
| 83 | extern __const union __float_u __infinityf; |
| 84 | #ifdef __MATH_BUILTIN_CONSTANTS |
| 85 | #define HUGE_VALF __builtin_huge_valf() |
| 86 | #else |
| 87 | #define HUGE_VALF __infinityf.__val |
| 88 | #endif |
| 89 | |
| 90 | extern __const union __long_double_u __infinityl; |
| 91 | #define HUGE_VALL __infinityl.__val |
| 92 | |
| 93 | /* 7.12#4 INFINITY */ |
| 94 | #ifdef __MATH_BUILTIN_CONSTANTS |
| 95 | #define INFINITY __builtin_inf() |
| 96 | #elif defined(__INFINITY) |
| 97 | #define INFINITY __INFINITY /* float constant which overflows */ |
| 98 | #else |
| 99 | #define INFINITY HUGE_VALF /* positive infinity */ |
| 100 | #endif /* __INFINITY */ |
| 101 | |
| 102 | /* 7.12#5 NAN: a quiet NaN, if supported */ |
| 103 | #ifdef __MATH_BUILTIN_CONSTANTS |
| 104 | #define NAN __builtin_nan("") |
| 105 | #elif defined(__HAVE_NANF) |
| 106 | extern __const union __float_u __nanf; |
| 107 | #define NAN __nanf.__val |
| 108 | #endif /* __HAVE_NANF */ |
| 109 | |
| 110 | /* 7.12#6 number classification macros */ |
| 111 | #define FP_INFINITE 0x00 |
| 112 | #define FP_NAN 0x01 |
| 113 | #define FP_NORMAL 0x02 |
| 114 | #define FP_SUBNORMAL 0x03 |
| 115 | #define FP_ZERO 0x04 |
| 116 | /* NetBSD extensions */ |
| 117 | #define _FP_LOMD 0x80 /* range for machine-specific classes */ |
| 118 | #define _FP_HIMD 0xff |
| 119 | |
| 120 | #endif /* ISO C99 */ |
| 121 | |
| 122 | /* |
| 123 | * XOPEN/SVID |
| 124 | */ |
| 125 | #if __XSI_VISIBLE > 0 |
| 126 | #define M_E 2.7182818284590452354 /* e */ |
| 127 | #define M_LOG2E 1.4426950408889634074 /* log 2e */ |
| 128 | #define M_LOG10E 0.43429448190325182765 /* log 10e */ |
| 129 | #define M_LN2 0.69314718055994530942 /* log e2 */ |
| 130 | #define M_LN10 2.30258509299404568402 /* log e10 */ |
| 131 | #define M_PI 3.14159265358979323846 /* pi */ |
| 132 | #define M_PI_2 1.57079632679489661923 /* pi/2 */ |
| 133 | #define M_PI_4 0.78539816339744830962 /* pi/4 */ |
| 134 | #define M_1_PI 0.31830988618379067154 /* 1/pi */ |
| 135 | #define M_2_PI 0.63661977236758134308 /* 2/pi */ |
| 136 | #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ |
| 137 | #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ |
| 138 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ |
| 139 | |
| 140 | #define MAXFLOAT ((float)3.40282346638528860e+38) |
| 141 | extern int signgam; |
| 142 | #endif /* _XSI_VISIBLE */ |
| 143 | |
| 144 | #if __DF_VISIBLE |
| 145 | #define HUGE MAXFLOAT |
| 146 | |
| 147 | /* |
| 148 | * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> |
| 149 | * (one may replace the following line by "#include <values.h>") |
| 150 | */ |
| 151 | |
| 152 | #define X_TLOSS 1.41484755040568800000e+16 |
| 153 | |
| 154 | #define DOMAIN 1 |
| 155 | #define SING 2 |
| 156 | #define OVERFLOW 3 |
| 157 | #define UNDERFLOW 4 |
| 158 | #define TLOSS 5 |
| 159 | #define PLOSS 6 |
| 160 | |
| 161 | #endif /* __DF_VISIBLE */ |
| 162 | |
| 163 | __BEGIN_DECLS |
| 164 | /* |
| 165 | * ANSI/POSIX |
| 166 | */ |
| 167 | double acos(double); |
| 168 | double asin(double); |
| 169 | double atan(double); |
| 170 | double atan2(double, double); |
| 171 | double cos(double); |
| 172 | double sin(double); |
| 173 | double tan(double); |
| 174 | |
| 175 | double cosh(double); |
| 176 | double sinh(double); |
| 177 | double tanh(double); |
| 178 | |
| 179 | double exp(double); |
| 180 | double frexp(double, int *); |
| 181 | double ldexp(double, int); |
| 182 | double log(double); |
| 183 | double log10(double); |
| 184 | double modf(double, double *); |
| 185 | |
| 186 | double pow(double, double); |
| 187 | double sqrt(double); |
| 188 | |
| 189 | double ceil(double); |
| 190 | double fabs(double); |
| 191 | double floor(double); |
| 192 | double fmod(double, double); |
| 193 | |
| 194 | #if __XSI_VISIBLE > 0 |
| 195 | double erf(double); |
| 196 | double erfc(double); |
| 197 | double gamma(double); |
| 198 | double hypot(double, double); |
| 199 | int finite(double); |
| 200 | double j0(double); |
| 201 | double j1(double); |
| 202 | double jn(int, double); |
| 203 | double lgamma(double); |
| 204 | double y0(double); |
| 205 | double y1(double); |
| 206 | double yn(int, double); |
| 207 | #endif /* __XSI_VISIBLE */ |
| 208 | |
| 209 | #if __XSI_VISIBLE >= 500 |
| 210 | double acosh(double); |
| 211 | double asinh(double); |
| 212 | double atanh(double); |
| 213 | double cbrt(double); |
| 214 | double expm1(double); |
| 215 | int ilogb(double); |
| 216 | double log1p(double); |
| 217 | double logb(double); |
| 218 | double nextafter(double, double); |
| 219 | double remainder(double, double); |
| 220 | double rint(double); |
| 221 | double scalb(double, double); |
| 222 | #endif /* __XSI_VISIBLE >= 500 */ |
| 223 | |
| 224 | /* |
| 225 | * ISO C99 |
| 226 | */ |
| 227 | #if __ISO_C_VISIBLE >= 1999 |
| 228 | /* 7.12.3.1 int fpclassify(real-floating x) */ |
| 229 | #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x) |
| 230 | |
| 231 | /* 7.12.3.2 int isfinite(real-floating x) */ |
| 232 | #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x) |
| 233 | |
| 234 | /* 7.12.3.5 int isnormal(real-floating x) */ |
| 235 | #define isnormal(__x) (fpclassify(__x) == FP_NORMAL) |
| 236 | |
| 237 | /* 7.12.3.6 int signbit(real-floating x) */ |
| 238 | #define signbit(__x) __fpmacro_unary_floating(signbit, __x) |
| 239 | |
| 240 | /* 7.12.4 trigonometric */ |
| 241 | |
| 242 | float acosf(float); |
| 243 | float asinf(float); |
| 244 | float atanf(float); |
| 245 | float atan2f(float, float); |
| 246 | float cosf(float); |
| 247 | float sinf(float); |
| 248 | float tanf(float); |
| 249 | |
| 250 | /* 7.12.5 hyperbolic */ |
| 251 | |
| 252 | float acoshf(float); |
| 253 | float asinhf(float); |
| 254 | float atanhf(float); |
| 255 | float coshf(float); |
| 256 | float sinhf(float); |
| 257 | float tanhf(float); |
| 258 | |
| 259 | /* 7.12.6 exp / log */ |
| 260 | |
| 261 | float expf(float); |
| 262 | float expm1f(float); |
| 263 | float frexpf(float, int *); |
| 264 | int ilogbf(float); |
| 265 | float ldexpf(float, int); |
| 266 | float logf(float); |
| 267 | float log10f(float); |
| 268 | float log1pf(float); |
| 269 | float logbf(float); |
| 270 | float modff(float, float *); |
| 271 | float scalbnf(float, int); |
| 272 | |
| 273 | /* 7.12.7 power / absolute */ |
| 274 | |
| 275 | float cbrtf(float); |
| 276 | float fabsf(float); |
| 277 | float hypotf(float, float); |
| 278 | float powf(float, float); |
| 279 | float sqrtf(float); |
| 280 | |
| 281 | /* 7.12.8 error / gamma */ |
| 282 | |
| 283 | float erff(float); |
| 284 | float erfcf(float); |
| 285 | float lgammaf(float); |
| 286 | |
| 287 | /* 7.12.9 nearest integer */ |
| 288 | |
| 289 | float ceilf(float); |
| 290 | float floorf(float); |
| 291 | float rintf(float); |
| 292 | double round(double); |
| 293 | float roundf(float); |
| 294 | long int lrint(double); |
| 295 | long int lrintf(float); |
| 296 | /* LONGLONG */ |
| 297 | long long int llrint(double); |
| 298 | /* LONGLONG */ |
| 299 | long long int llrintf(float); |
| 300 | long int lround(double); |
| 301 | long int lroundf(float); |
| 302 | /* LONGLONG */ |
| 303 | long long int llround(double); |
| 304 | /* LONGLONG */ |
| 305 | long long int llroundf(float); |
| 306 | |
| 307 | /* 7.12.10 remainder */ |
| 308 | |
| 309 | float fmodf(float, float); |
| 310 | float remainderf(float, float); |
| 311 | |
| 312 | /* 7.2.11 manipulation */ |
| 313 | |
| 314 | float copysignf(float, float); |
| 315 | float nextafterf(float, float); |
| 316 | |
| 317 | #endif /* __ISO_C_VISIBLE >= 1999 */ |
| 318 | |
| 319 | #if __ISO_C_VISIBLE >= 1999 |
| 320 | /* 7.12.3.3 int isinf(real-floating x) */ |
| 321 | #ifdef __isinf |
| 322 | #define isinf(__x) __isinf(__x) |
| 323 | #else |
| 324 | #define isinf(__x) __fpmacro_unary_floating(isinf, __x) |
| 325 | #endif |
| 326 | |
| 327 | /* 7.12.3.4 int isnan(real-floating x) */ |
| 328 | #ifdef __isnan |
| 329 | #define isnan(__x) __isnan(__x) |
| 330 | #else |
| 331 | #define isnan(__x) __fpmacro_unary_floating(isnan, __x) |
| 332 | #endif |
| 333 | |
| 334 | /* 7.12.14 Comparision macros */ |
| 335 | #ifdef __MATH_BUILTIN_RELOPS |
| 336 | #define isgreater(x, y) __builtin_isgreater((x), (y)) |
| 337 | #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) |
| 338 | #define isless(x, y) __builtin_isless((x), (y)) |
| 339 | #define islessequal(x, y) __builtin_islessequal((x), (y)) |
| 340 | #define islessgreater(x, y) __builtin_islessgreater((x), (y)) |
| 341 | #define isunordered(x, y) __builtin_isunordered((x), (y)) |
| 342 | #else |
| 343 | #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) |
| 344 | #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) |
| 345 | #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) |
| 346 | #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) |
| 347 | #define islessgreater(x, y) (!isunordered((x), (y)) && \ |
| 348 | ((x) > (y) || (y) > (x))) |
| 349 | #define isunordered(x, y) (isnan(x) || isnan(y)) |
| 350 | #endif /* __MATH_BUILTIN_RELOPS */ |
| 351 | |
| 352 | #endif /* __ISO_C_VISIBLE >= 1999 */ |
| 353 | |
| 354 | #if __DF_VISIBLE |
| 355 | /* |
| 356 | * IEEE Test Vector |
| 357 | */ |
| 358 | double significand(double); |
| 359 | |
| 360 | /* |
| 361 | * Functions callable from C, intended to support IEEE arithmetic. |
| 362 | */ |
| 363 | double copysign(double, double); |
| 364 | double scalbn(double, int); |
| 365 | |
| 366 | /* |
| 367 | * BSD math library entry points |
| 368 | */ |
| 369 | double drem(double, double); |
| 370 | |
| 371 | /* |
| 372 | * Reentrant version of gamma & lgamma; passes signgam back by reference |
| 373 | * as the second argument; user must allocate space for signgam. |
| 374 | */ |
| 375 | double gamma_r(double, int *); |
| 376 | double lgamma_r(double, int *); |
| 377 | #endif /* __DF_VISIBLE */ |
| 378 | |
| 379 | |
| 380 | #if __DF_VISIBLE |
| 381 | |
| 382 | /* float versions of ANSI/POSIX functions */ |
| 383 | |
| 384 | float gammaf(float); |
| 385 | int finitef(float); |
| 386 | float j0f(float); |
| 387 | float j1f(float); |
| 388 | float jnf(int, float); |
| 389 | float y0f(float); |
| 390 | float y1f(float); |
| 391 | float ynf(int, float); |
| 392 | |
| 393 | float scalbf(float, float); |
| 394 | |
| 395 | /* |
| 396 | * float version of IEEE Test Vector |
| 397 | */ |
| 398 | float significandf(float); |
| 399 | |
| 400 | /* |
| 401 | * float versions of BSD math library entry points |
| 402 | */ |
| 403 | float dremf(float, float); |
| 404 | |
| 405 | /* |
| 406 | * Float versions of reentrant version of gamma & lgamma; passes |
| 407 | * signgam back by reference as the second argument; user must |
| 408 | * allocate space for signgam. |
| 409 | */ |
| 410 | float gammaf_r(float, int *); |
| 411 | float lgammaf_r(float, int *); |
| 412 | #endif /* __DF_VISIBLE */ |
| 413 | |
| 414 | /* |
| 415 | * Library implementation |
| 416 | */ |
| 417 | int __fpclassifyf(float); |
| 418 | int __fpclassifyd(double); |
| 419 | int __isfinitef(float); |
| 420 | int __isfinited(double); |
| 421 | int __isinff(float); |
| 422 | int __isinfd(double); |
| 423 | int __isnanf(float); |
| 424 | int __isnand(double); |
| 425 | int __signbitf(float); |
| 426 | int __signbitd(double); |
| 427 | |
| 428 | #ifdef __HAVE_LONG_DOUBLE |
| 429 | int __fpclassifyl(long double); |
| 430 | int __isfinitel(long double); |
| 431 | int __isinfl(long double); |
| 432 | int __isnanl(long double); |
| 433 | int __signbitl(long double); |
| 434 | #endif |
| 435 | __END_DECLS |
| 436 | |
| 437 | #endif /* _MATH_H_ */ |