1 /* $NetBSD: math.h,v 1.26 2003/05/17 20:42:28 thorpej 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 /* 43 * ANSI/POSIX 44 */ 45 extern __const union __double_u __infinity; 46 #define HUGE_VAL __infinity.__val 47 48 /* 49 * ISO C99 50 */ 51 #if defined(__HAVE_NANF) && \ 52 (!defined(_ANSI_SOURCE) && \ 53 (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ 54 defined(_NETBSD_SOURCE))) 55 extern __const union __float_u __nanf; 56 #define NAN __nanf.__val 57 #endif /* __HAVE_NANF && (!_ANSI_SOURCE && ....) */ 58 59 /* 60 * XOPEN/SVID 61 */ 62 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 63 #define M_E 2.7182818284590452354 /* e */ 64 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 65 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 66 #define M_LN2 0.69314718055994530942 /* log e2 */ 67 #define M_LN10 2.30258509299404568402 /* log e10 */ 68 #define M_PI 3.14159265358979323846 /* pi */ 69 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 70 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 71 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 72 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 73 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 74 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 75 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 76 77 #define MAXFLOAT ((float)3.40282346638528860e+38) 78 extern int signgam; 79 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ 80 81 #if defined(_NETBSD_SOURCE) 82 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 83 84 #define _LIB_VERSION_TYPE enum fdversion 85 #define _LIB_VERSION _fdlib_version 86 87 /* if global variable _LIB_VERSION is not desirable, one may 88 * change the following to be a constant by: 89 * #define _LIB_VERSION_TYPE const enum version 90 * In that case, after one initializes the value _LIB_VERSION (see 91 * s_lib_version.c) during compile time, it cannot be modified 92 * in the middle of a program 93 */ 94 extern _LIB_VERSION_TYPE _LIB_VERSION; 95 96 #define _IEEE_ fdlibm_ieee 97 #define _SVID_ fdlibm_svid 98 #define _XOPEN_ fdlibm_xopen 99 #define _POSIX_ fdlibm_posix 100 101 #ifndef __cplusplus 102 struct exception { 103 int type; 104 char *name; 105 double arg1; 106 double arg2; 107 double retval; 108 }; 109 #endif 110 111 #define HUGE MAXFLOAT 112 113 /* 114 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 115 * (one may replace the following line by "#include <values.h>") 116 */ 117 118 #define X_TLOSS 1.41484755040568800000e+16 119 120 #define DOMAIN 1 121 #define SING 2 122 #define OVERFLOW 3 123 #define UNDERFLOW 4 124 #define TLOSS 5 125 #define PLOSS 6 126 127 #endif /* _NETBSD_SOURCE */ 128 129 __BEGIN_DECLS 130 /* 131 * ANSI/POSIX 132 */ 133 double acos __P((double)); 134 double asin __P((double)); 135 double atan __P((double)); 136 double atan2 __P((double, double)); 137 double cos __P((double)); 138 double sin __P((double)); 139 double tan __P((double)); 140 141 double cosh __P((double)); 142 double sinh __P((double)); 143 double tanh __P((double)); 144 145 double exp __P((double)); 146 double frexp __P((double, int *)); 147 double ldexp __P((double, int)); 148 double log __P((double)); 149 double log10 __P((double)); 150 double modf __P((double, double *)); 151 152 double pow __P((double, double)); 153 double sqrt __P((double)); 154 155 double ceil __P((double)); 156 double fabs __P((double)); 157 double floor __P((double)); 158 double fmod __P((double, double)); 159 160 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 161 double erf __P((double)); 162 double erfc __P((double)); 163 double gamma __P((double)); 164 double hypot __P((double, double)); 165 int isnan __P((double)); 166 #if defined(_LIBC) 167 int isnanl __P((long double)); 168 #endif 169 int finite __P((double)); 170 double j0 __P((double)); 171 double j1 __P((double)); 172 double jn __P((int, double)); 173 double lgamma __P((double)); 174 double y0 __P((double)); 175 double y1 __P((double)); 176 double yn __P((int, double)); 177 178 #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 179 double acosh __P((double)); 180 double asinh __P((double)); 181 double atanh __P((double)); 182 double cbrt __P((double)); 183 double expm1 __P((double)); 184 int ilogb __P((double)); 185 double log1p __P((double)); 186 double logb __P((double)); 187 double nextafter __P((double, double)); 188 double remainder __P((double, double)); 189 double rint __P((double)); 190 double scalb __P((double, double)); 191 #endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/ 192 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ 193 194 #if defined(_NETBSD_SOURCE) 195 #ifndef __cplusplus 196 int matherr __P((struct exception *)); 197 #endif 198 199 /* 200 * IEEE Test Vector 201 */ 202 double significand __P((double)); 203 204 /* 205 * Functions callable from C, intended to support IEEE arithmetic. 206 */ 207 double copysign __P((double, double)); 208 double scalbn __P((double, int)); 209 210 /* 211 * BSD math library entry points 212 */ 213 #ifndef __MATH_PRIVATE__ 214 double cabs __P((/* struct complex { double r; double i; } */)); 215 #endif 216 double drem __P((double, double)); 217 218 #endif /* _NETBSD_SOURCE */ 219 220 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT) 221 /* 222 * Reentrant version of gamma & lgamma; passes signgam back by reference 223 * as the second argument; user must allocate space for signgam. 224 */ 225 double gamma_r __P((double, int *)); 226 double lgamma_r __P((double, int *)); 227 #endif /* _NETBSD_SOURCE || _REENTRANT */ 228 229 230 #if defined(_NETBSD_SOURCE) 231 int isinf __P((double)); 232 #if defined(_LIBC) 233 int isinfl __P((long double)); 234 #endif 235 236 /* float versions of ANSI/POSIX functions */ 237 float acosf __P((float)); 238 float asinf __P((float)); 239 float atanf __P((float)); 240 float atan2f __P((float, float)); 241 float cosf __P((float)); 242 float sinf __P((float)); 243 float tanf __P((float)); 244 245 float coshf __P((float)); 246 float sinhf __P((float)); 247 float tanhf __P((float)); 248 249 float expf __P((float)); 250 float frexpf __P((float, int *)); 251 float ldexpf __P((float, int)); 252 float logf __P((float)); 253 float log10f __P((float)); 254 float modff __P((float, float *)); 255 256 float powf __P((float, float)); 257 float sqrtf __P((float)); 258 259 float ceilf __P((float)); 260 float fabsf __P((float)); 261 float floorf __P((float)); 262 float fmodf __P((float, float)); 263 264 float erff __P((float)); 265 float erfcf __P((float)); 266 float gammaf __P((float)); 267 float hypotf __P((float, float)); 268 int isinff __P((float)); 269 int isnanf __P((float)); 270 int finitef __P((float)); 271 float j0f __P((float)); 272 float j1f __P((float)); 273 float jnf __P((int, float)); 274 float lgammaf __P((float)); 275 float y0f __P((float)); 276 float y1f __P((float)); 277 float ynf __P((int, float)); 278 279 float acoshf __P((float)); 280 float asinhf __P((float)); 281 float atanhf __P((float)); 282 float cbrtf __P((float)); 283 float logbf __P((float)); 284 float nextafterf __P((float, float)); 285 float remainderf __P((float, float)); 286 float scalbf __P((float, float)); 287 288 /* 289 * float version of IEEE Test Vector 290 */ 291 float significandf __P((float)); 292 293 /* 294 * Float versions of functions callable from C, intended to support 295 * IEEE arithmetic. 296 */ 297 float copysignf __P((float, float)); 298 int ilogbf __P((float)); 299 float rintf __P((float)); 300 float scalbnf __P((float, int)); 301 302 /* 303 * float versions of BSD math library entry points 304 */ 305 #ifndef __MATH_PRIVATE__ 306 float cabsf __P((/* struct complex { float r; float i; } */)); 307 #endif 308 float dremf __P((float, float)); 309 float expm1f __P((float)); 310 float log1pf __P((float)); 311 #endif /* _NETBSD_SOURCE */ 312 313 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT) 314 /* 315 * Float versions of reentrant version of gamma & lgamma; passes 316 * signgam back by reference as the second argument; user must 317 * allocate space for signgam. 318 */ 319 float gammaf_r __P((float, int *)); 320 float lgammaf_r __P((float, int *)); 321 #endif /* !... || _REENTRANT */ 322 323 __END_DECLS 324 325 #endif /* _MATH_H_ */ 326