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