1 /* $NetBSD: math.h,v 1.32 2004/01/20 19:52:40 kleink 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 14 /* 15 * @(#)fdlibm.h 5.1 93/09/24 16 */ 17 18 #ifndef _MATH_H_ 19 #define _MATH_H_ 20 21 #include <sys/cdefs.h> 22 #include <sys/featuretest.h> 23 24 union __float_u { 25 unsigned char __dummy[sizeof(float)]; 26 float __val; 27 }; 28 29 union __double_u { 30 unsigned char __dummy[sizeof(double)]; 31 double __val; 32 }; 33 34 union __long_double_u { 35 unsigned char __dummy[sizeof(long double)]; 36 long double __val; 37 }; 38 39 #include <machine/math.h> /* may use __float_u, __double_u, 40 or __long_double_u */ 41 42 #ifdef __HAVE_LONG_DOUBLE 43 #define __fpmacro_unary_floating(__name, __arg0) \ 44 ((sizeof (__arg0) == sizeof (float)) \ 45 ? __ ## __name ## f (__arg0) \ 46 : (sizeof (__arg0) == sizeof (double)) \ 47 ? __ ## __name ## d (__arg0) \ 48 : __ ## __name ## l (__arg0)) 49 #else 50 #define __fpmacro_unary_floating(__name, __arg0) \ 51 ((sizeof (__arg0) == sizeof (float)) \ 52 ? __ ## __name ## f (__arg0) \ 53 : __ ## __name ## d (__arg0)) 54 #endif /* __HAVE_LONG_DOUBLE */ 55 56 /* 57 * ANSI/POSIX 58 */ 59 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ 60 extern __const union __double_u __infinity; 61 #define HUGE_VAL __infinity.__val 62 63 /* 64 * ISO C99 65 */ 66 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ 67 !defined(_XOPEN_SOURCE) || \ 68 ((__STDC_VERSION__ - 0) >= 199901L) || \ 69 ((_POSIX_C_SOURCE - 0) >= 200112L) || \ 70 ((_XOPEN_SOURCE - 0) >= 600) || \ 71 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) 72 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ 73 extern __const union __float_u __infinityf; 74 #define HUGE_VALF __infinityf.__val 75 76 extern __const union __long_double_u __infinityl; 77 #define HUGE_VALL __infinityl.__val 78 79 /* 7.12#4 INFINITY */ 80 #ifdef __INFINITY 81 #define INFINITY __INFINITY /* float constant which overflows */ 82 #else 83 #define INFINITY HUGE_VALF /* positive infinity */ 84 #endif /* __INFINITY */ 85 86 /* 7.12#5 NAN: a quiet NaN, if supported */ 87 #ifdef __HAVE_NANF 88 extern __const union __float_u __nanf; 89 #define NAN __nanf.__val 90 #endif /* __HAVE_NANF */ 91 92 /* 7.12#6 number classification macros */ 93 #define FP_INFINITE 0x00 94 #define FP_NAN 0x01 95 #define FP_NORMAL 0x02 96 #define FP_SUBNORMAL 0x03 97 #define FP_ZERO 0x04 98 /* NetBSD extensions */ 99 #define _FP_LOMD 0x80 /* range for machine-specific classes */ 100 #define _FP_HIMD 0xff 101 102 #endif /* !_ANSI_SOURCE && ... */ 103 104 /* 105 * XOPEN/SVID 106 */ 107 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 108 #define M_E 2.7182818284590452354 /* e */ 109 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 110 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 111 #define M_LN2 0.69314718055994530942 /* log e2 */ 112 #define M_LN10 2.30258509299404568402 /* log e10 */ 113 #define M_PI 3.14159265358979323846 /* pi */ 114 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 115 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 116 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 117 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 118 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 119 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 120 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 121 122 #define MAXFLOAT ((float)3.40282346638528860e+38) 123 extern int signgam; 124 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ 125 126 #if defined(_NETBSD_SOURCE) 127 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 128 129 #define _LIB_VERSION_TYPE enum fdversion 130 #define _LIB_VERSION _fdlib_version 131 132 /* if global variable _LIB_VERSION is not desirable, one may 133 * change the following to be a constant by: 134 * #define _LIB_VERSION_TYPE const enum version 135 * In that case, after one initializes the value _LIB_VERSION (see 136 * s_lib_version.c) during compile time, it cannot be modified 137 * in the middle of a program 138 */ 139 extern _LIB_VERSION_TYPE _LIB_VERSION; 140 141 #define _IEEE_ fdlibm_ieee 142 #define _SVID_ fdlibm_svid 143 #define _XOPEN_ fdlibm_xopen 144 #define _POSIX_ fdlibm_posix 145 146 #ifndef __cplusplus 147 struct exception { 148 int type; 149 char *name; 150 double arg1; 151 double arg2; 152 double retval; 153 }; 154 #endif 155 156 #define HUGE MAXFLOAT 157 158 /* 159 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 160 * (one may replace the following line by "#include <values.h>") 161 */ 162 163 #define X_TLOSS 1.41484755040568800000e+16 164 165 #define DOMAIN 1 166 #define SING 2 167 #define OVERFLOW 3 168 #define UNDERFLOW 4 169 #define TLOSS 5 170 #define PLOSS 6 171 172 #endif /* _NETBSD_SOURCE */ 173 174 __BEGIN_DECLS 175 /* 176 * ANSI/POSIX 177 */ 178 double acos __P((double)); 179 double asin __P((double)); 180 double atan __P((double)); 181 double atan2 __P((double, double)); 182 double cos __P((double)); 183 double sin __P((double)); 184 double tan __P((double)); 185 186 double cosh __P((double)); 187 double sinh __P((double)); 188 double tanh __P((double)); 189 190 double exp __P((double)); 191 double frexp __P((double, int *)); 192 double ldexp __P((double, int)); 193 double log __P((double)); 194 double log10 __P((double)); 195 double modf __P((double, double *)); 196 197 double pow __P((double, double)); 198 double sqrt __P((double)); 199 200 double ceil __P((double)); 201 double fabs __P((double)); 202 double floor __P((double)); 203 double fmod __P((double, double)); 204 205 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 206 double erf __P((double)); 207 double erfc __P((double)); 208 double gamma __P((double)); 209 double hypot __P((double, double)); 210 int isnan __P((double)); 211 #if defined(_LIBC) 212 int isnanl __P((long double)); 213 #endif 214 int finite __P((double)); 215 double j0 __P((double)); 216 double j1 __P((double)); 217 double jn __P((int, double)); 218 double lgamma __P((double)); 219 double y0 __P((double)); 220 double y1 __P((double)); 221 double yn __P((int, double)); 222 223 #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 224 double acosh __P((double)); 225 double asinh __P((double)); 226 double atanh __P((double)); 227 double cbrt __P((double)); 228 double expm1 __P((double)); 229 int ilogb __P((double)); 230 double log1p __P((double)); 231 double logb __P((double)); 232 double nextafter __P((double, double)); 233 double remainder __P((double, double)); 234 double rint __P((double)); 235 double scalb __P((double, double)); 236 #endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/ 237 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ 238 239 /* 240 * ISO C99 241 */ 242 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ 243 !defined(_XOPEN_SOURCE) || \ 244 ((__STDC_VERSION__ - 0) >= 199901L) || \ 245 ((_POSIX_C_SOURCE - 0) >= 200112L) || \ 246 ((_XOPEN_SOURCE - 0) >= 600) || \ 247 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) 248 /* 7.12.3.1 int fpclassify(real-floating x) */ 249 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x) 250 251 /* 7.12.3.2 int isfinite(real-floating x) */ 252 #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x) 253 254 /* 7.12.3.5 int isnormal(real-floating x) */ 255 #define isnormal(__x) (fpclassify(__x) == FP_NORMAL) 256 257 /* 7.12.3.6 int signbit(real-floating x) */ 258 #define signbit(__x) __fpmacro_unary_floating(signbit, __x) 259 260 #endif /* !_ANSI_SOURCE && ... */ 261 262 #if defined(_NETBSD_SOURCE) 263 #ifndef __cplusplus 264 int matherr __P((struct exception *)); 265 #endif 266 267 /* 268 * IEEE Test Vector 269 */ 270 double significand __P((double)); 271 272 /* 273 * Functions callable from C, intended to support IEEE arithmetic. 274 */ 275 double copysign __P((double, double)); 276 double scalbn __P((double, int)); 277 278 /* 279 * BSD math library entry points 280 */ 281 #ifndef __MATH_PRIVATE__ 282 double cabs __P((/* struct complex { double r; double i; } */)); 283 #endif 284 double drem __P((double, double)); 285 286 #endif /* _NETBSD_SOURCE */ 287 288 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT) 289 /* 290 * Reentrant version of gamma & lgamma; passes signgam back by reference 291 * as the second argument; user must allocate space for signgam. 292 */ 293 double gamma_r __P((double, int *)); 294 double lgamma_r __P((double, int *)); 295 #endif /* _NETBSD_SOURCE || _REENTRANT */ 296 297 298 #if defined(_NETBSD_SOURCE) 299 int isinf __P((double)); 300 #if defined(_LIBC) 301 int isinfl __P((long double)); 302 #endif 303 304 /* float versions of ANSI/POSIX functions */ 305 float acosf __P((float)); 306 float asinf __P((float)); 307 float atanf __P((float)); 308 float atan2f __P((float, float)); 309 float cosf __P((float)); 310 float sinf __P((float)); 311 float tanf __P((float)); 312 313 float coshf __P((float)); 314 float sinhf __P((float)); 315 float tanhf __P((float)); 316 317 float expf __P((float)); 318 float frexpf __P((float, int *)); 319 float ldexpf __P((float, int)); 320 float logf __P((float)); 321 float log10f __P((float)); 322 float modff __P((float, float *)); 323 324 float powf __P((float, float)); 325 float sqrtf __P((float)); 326 327 float ceilf __P((float)); 328 float fabsf __P((float)); 329 float floorf __P((float)); 330 float fmodf __P((float, float)); 331 332 float erff __P((float)); 333 float erfcf __P((float)); 334 float gammaf __P((float)); 335 float hypotf __P((float, float)); 336 int isinff __P((float)); 337 int isnanf __P((float)); 338 int finitef __P((float)); 339 float j0f __P((float)); 340 float j1f __P((float)); 341 float jnf __P((int, float)); 342 float lgammaf __P((float)); 343 float y0f __P((float)); 344 float y1f __P((float)); 345 float ynf __P((int, float)); 346 347 float acoshf __P((float)); 348 float asinhf __P((float)); 349 float atanhf __P((float)); 350 float cbrtf __P((float)); 351 float logbf __P((float)); 352 float nextafterf __P((float, float)); 353 float remainderf __P((float, float)); 354 float scalbf __P((float, float)); 355 356 /* 357 * float version of IEEE Test Vector 358 */ 359 float significandf __P((float)); 360 361 /* 362 * Float versions of functions callable from C, intended to support 363 * IEEE arithmetic. 364 */ 365 float copysignf __P((float, float)); 366 int ilogbf __P((float)); 367 float rintf __P((float)); 368 float scalbnf __P((float, int)); 369 370 /* 371 * float versions of BSD math library entry points 372 */ 373 #ifndef __MATH_PRIVATE__ 374 float cabsf __P((/* struct complex { float r; float i; } */)); 375 #endif 376 float dremf __P((float, float)); 377 float expm1f __P((float)); 378 float log1pf __P((float)); 379 #endif /* _NETBSD_SOURCE */ 380 381 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT) 382 /* 383 * Float versions of reentrant version of gamma & lgamma; passes 384 * signgam back by reference as the second argument; user must 385 * allocate space for signgam. 386 */ 387 float gammaf_r __P((float, int *)); 388 float lgammaf_r __P((float, int *)); 389 #endif /* !... || _REENTRANT */ 390 391 /* 392 * Library implementation 393 */ 394 int __fpclassifyf __P((float)); 395 int __fpclassifyd __P((double)); 396 int __isfinitef __P((float)); 397 int __isfinited __P((double)); 398 int __signbitf __P((float)); 399 int __signbitd __P((double)); 400 401 #ifdef __HAVE_LONG_DOUBLE 402 int __fpclassifyl __P((long double)); 403 int __isfinitel __P((long double)); 404 int __signbitl __P((long double)); 405 #endif 406 __END_DECLS 407 408 #endif /* _MATH_H_ */ 409