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