FreeBSD and NetBSD both use derivates of Sun's math library. On FreeBSD,
[dragonfly.git] / include / math.h
CommitLineData
b34b60bc
JS
1/* $NetBSD: math.h,v 1.40 2005/02/03 04:39:32 perry 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 * $NetBSD: math.h,v 1.40 2005/02/03 04:39:32 perry Exp $
14 * $DragonFly: src/include/math.h,v 1.5 2005/07/26 21:15:19 joerg Exp $
15 */
16
17/*
18 * @(#)fdlibm.h 5.1 93/09/24
19 */
20
21#ifndef _MATH_H_
22#define _MATH_H_
23
24#include <sys/cdefs.h>
25
26union __float_u {
27 unsigned char __dummy[sizeof(float)];
28 float __val;
29};
30
31union __double_u {
32 unsigned char __dummy[sizeof(double)];
33 double __val;
34};
35
36union __long_double_u {
37 unsigned char __dummy[sizeof(long double)];
38 long double __val;
39};
40
41#include <machine/math.h>
42
43#ifdef __HAVE_LONG_DOUBLE
44#define __fpmacro_unary_floating(__name, __arg0) \
45 /* LINTED */ \
46 ((sizeof (__arg0) == sizeof (float)) \
47 ? __ ## __name ## f (__arg0) \
48 : (sizeof (__arg0) == sizeof (double)) \
49 ? __ ## __name ## d (__arg0) \
50 : __ ## __name ## l (__arg0))
51#else
52#define __fpmacro_unary_floating(__name, __arg0) \
53 /* LINTED */ \
54 ((sizeof (__arg0) == sizeof (float)) \
55 ? __ ## __name ## f (__arg0) \
56 : __ ## __name ## d (__arg0))
57#endif /* __HAVE_LONG_DOUBLE */
58
59/*
60 * ANSI/POSIX
61 */
62/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
63extern __const union __double_u __infinity;
64#define HUGE_VAL __infinity.__val
65
66/*
67 * ISO C99
68 */
69#if __ISO_C_VISIBLE >= 1999
70/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
71extern __const union __float_u __infinityf;
72#define HUGE_VALF __infinityf.__val
73
74extern __const union __long_double_u __infinityl;
75#define HUGE_VALL __infinityl.__val
76
77/* 7.12#4 INFINITY */
78#ifdef __INFINITY
79#define INFINITY __INFINITY /* float constant which overflows */
80#else
81#define INFINITY HUGE_VALF /* positive infinity */
82#endif /* __INFINITY */
83
84/* 7.12#5 NAN: a quiet NaN, if supported */
85#ifdef __HAVE_NANF
86extern __const union __float_u __nanf;
87#define NAN __nanf.__val
88#endif /* __HAVE_NANF */
89
90/* 7.12#6 number classification macros */
91#define FP_INFINITE 0x00
92#define FP_NAN 0x01
93#define FP_NORMAL 0x02
94#define FP_SUBNORMAL 0x03
95#define FP_ZERO 0x04
96/* NetBSD extensions */
97#define _FP_LOMD 0x80 /* range for machine-specific classes */
98#define _FP_HIMD 0xff
99
100#endif /* ISO C99 */
101
102/*
103 * XOPEN/SVID
104 */
105#if __XSI_VISIBLE > 0
106#define M_E 2.7182818284590452354 /* e */
107#define M_LOG2E 1.4426950408889634074 /* log 2e */
108#define M_LOG10E 0.43429448190325182765 /* log 10e */
109#define M_LN2 0.69314718055994530942 /* log e2 */
110#define M_LN10 2.30258509299404568402 /* log e10 */
111#define M_PI 3.14159265358979323846 /* pi */
112#define M_PI_2 1.57079632679489661923 /* pi/2 */
113#define M_PI_4 0.78539816339744830962 /* pi/4 */
114#define M_1_PI 0.31830988618379067154 /* 1/pi */
115#define M_2_PI 0.63661977236758134308 /* 2/pi */
116#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
117#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
118#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
119
120#define MAXFLOAT ((float)3.40282346638528860e+38)
121extern int signgam;
122#endif /* _XSI_VISIBLE */
123
124#if __DF_VISIBLE
125#define HUGE MAXFLOAT
126
127/*
128 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
129 * (one may replace the following line by "#include <values.h>")
130 */
131
132#define X_TLOSS 1.41484755040568800000e+16
133
134#define DOMAIN 1
135#define SING 2
136#define OVERFLOW 3
137#define UNDERFLOW 4
138#define TLOSS 5
139#define PLOSS 6
140
141#endif /* __DF_VISIBLE */
142
143__BEGIN_DECLS
144/*
145 * ANSI/POSIX
146 */
147double acos(double);
148double asin(double);
149double atan(double);
150double atan2(double, double);
151double cos(double);
152double sin(double);
153double tan(double);
154
155double cosh(double);
156double sinh(double);
157double tanh(double);
158
159double exp(double);
160double frexp(double, int *);
161double ldexp(double, int);
162double log(double);
163double log10(double);
164double modf(double, double *);
165
166double pow(double, double);
167double sqrt(double);
168
169double ceil(double);
170double fabs(double);
171double floor(double);
172double fmod(double, double);
173
174#if __XSI_VISIBLE > 0
175double erf(double);
176double erfc(double);
177double gamma(double);
178double hypot(double, double);
179int finite(double);
180double j0(double);
181double j1(double);
182double jn(int, double);
183double lgamma(double);
184double y0(double);
185double y1(double);
186double yn(int, double);
187#endif /* __XSI_VISIBLE */
188
189#if __XSI_VISIBLE >= 500
190double acosh(double);
191double asinh(double);
192double atanh(double);
193double cbrt(double);
194double expm1(double);
195int ilogb(double);
196double log1p(double);
197double logb(double);
198double nextafter(double, double);
199double remainder(double, double);
200double rint(double);
201double scalb(double, double);
202#endif /* __XSI_VISIBLE >= 500 */
203
204/*
205 * ISO C99
206 */
207#if __ISO_C_VISIBLE >= 1999
208/* 7.12.3.1 int fpclassify(real-floating x) */
209#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
210
211/* 7.12.3.2 int isfinite(real-floating x) */
212#define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
213
214/* 7.12.3.5 int isnormal(real-floating x) */
215#define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
216
217/* 7.12.3.6 int signbit(real-floating x) */
218#define signbit(__x) __fpmacro_unary_floating(signbit, __x)
219
220/* 7.12.4 trigonometric */
221
222float acosf(float);
223float asinf(float);
224float atanf(float);
225float atan2f(float, float);
226float cosf(float);
227float sinf(float);
228float tanf(float);
229
230/* 7.12.5 hyperbolic */
231
232float acoshf(float);
233float asinhf(float);
234float atanhf(float);
235float coshf(float);
236float sinhf(float);
237float tanhf(float);
238
239/* 7.12.6 exp / log */
240
241float expf(float);
242float expm1f(float);
243float frexpf(float, int *);
244int ilogbf(float);
245float ldexpf(float, int);
246float logf(float);
247float log10f(float);
248float log1pf(float);
249float logbf(float);
250float modff(float, float *);
251float scalbnf(float, int);
252
253/* 7.12.7 power / absolute */
254
255float cbrtf(float);
256float fabsf(float);
257float hypotf(float, float);
258float powf(float, float);
259float sqrtf(float);
260
261/* 7.12.8 error / gamma */
262
263float erff(float);
264float erfcf(float);
265float lgammaf(float);
266
267/* 7.12.9 nearest integer */
268
269float ceilf(float);
270float floorf(float);
271float rintf(float);
272double round(double);
273float roundf(float);
274long int lrint(double);
275long int lrintf(float);
276/* LONGLONG */
277long long int llrint(double);
278/* LONGLONG */
279long long int llrintf(float);
280long int lround(double);
281long int lroundf(float);
282/* LONGLONG */
283long long int llround(double);
284/* LONGLONG */
285long long int llroundf(float);
286
287/* 7.12.10 remainder */
288
289float fmodf(float, float);
290float remainderf(float, float);
291
292/* 7.2.11 manipulation */
293
294float copysignf(float, float);
295float nextafterf(float, float);
296
297#endif /* __ISO_C_VISIBLE >= 1999 */
298
299#if __ISO_C_VISIBLE >= 1999
300/* 7.12.3.3 int isinf(real-floating x) */
301#ifdef __isinf
302#define isinf(__x) __isinf(__x)
303#else
304#define isinf(__x) __fpmacro_unary_floating(isinf, __x)
305#endif
306
307/* 7.12.3.4 int isnan(real-floating x) */
308#ifdef __isnan
309#define isnan(__x) __isnan(__x)
310#else
311#define isnan(__x) __fpmacro_unary_floating(isnan, __x)
312#endif
313#endif /* __ISO_C_VISIBLE >= 1999 */
314
315#if __DF_VISIBLE
316/*
317 * IEEE Test Vector
318 */
319double significand(double);
320
321/*
322 * Functions callable from C, intended to support IEEE arithmetic.
323 */
324double copysign(double, double);
325double scalbn(double, int);
326
327/*
328 * BSD math library entry points
329 */
330double drem(double, double);
331
332/*
333 * Reentrant version of gamma & lgamma; passes signgam back by reference
334 * as the second argument; user must allocate space for signgam.
335 */
336double gamma_r(double, int *);
337double lgamma_r(double, int *);
338#endif /* __DF_VISIBLE */
339
340
341#if __DF_VISIBLE
342
343/* float versions of ANSI/POSIX functions */
344
345float gammaf(float);
346int isinff(float);
347int isnanf(float);
348int finitef(float);
349float j0f(float);
350float j1f(float);
351float jnf(int, float);
352float y0f(float);
353float y1f(float);
354float ynf(int, float);
355
356float scalbf(float, float);
357
358/*
359 * float version of IEEE Test Vector
360 */
361float significandf(float);
362
363/*
364 * float versions of BSD math library entry points
365 */
366float dremf(float, float);
367
368/*
369 * Float versions of reentrant version of gamma & lgamma; passes
370 * signgam back by reference as the second argument; user must
371 * allocate space for signgam.
372 */
373float gammaf_r(float, int *);
374float lgammaf_r(float, int *);
375#endif /* __DF_VISIBLE */
376
377/*
378 * Library implementation
379 */
380int __fpclassifyf(float);
381int __fpclassifyd(double);
382int __isfinitef(float);
383int __isfinited(double);
384int __isinff(float);
385int __isinfd(double);
386int __isnanf(float);
387int __isnand(double);
388int __signbitf(float);
389int __signbitd(double);
390
391#ifdef __HAVE_LONG_DOUBLE
392int __fpclassifyl(long double);
393int __isfinitel(long double);
394int __isinfl(long double);
395int __isnanl(long double);
396int __signbitl(long double);
397#endif
398__END_DECLS
399
400#endif /* _MATH_H_ */