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