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