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