libm: Sync with FreeBSD (gains 6 long double functions)
[dragonfly.git] / lib / libm / src / math.h
CommitLineData
6ff43c94
PA
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
12/*
13 * from: @(#)fdlibm.h 5.1 93/09/24
2fedfd5c 14 * $FreeBSD: head/lib/msun/src/math.h 271651 2014-09-15 23:21:57Z kargl $
6ff43c94
PA
15 */
16
17#ifndef _MATH_H_
18#define _MATH_H_
19
20#include <sys/cdefs.h>
21#include <sys/types.h>
22#include <machine/limits.h>
23
24/*
25 * ANSI/POSIX
26 */
27extern const union __infinity_un {
28 unsigned char __uc[8];
29 double __ud;
30} __infinity;
31
32extern const union __nan_un {
33 unsigned char __uc[sizeof(float)];
34 float __uf;
35} __nan;
36
37#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
38#define __MATH_BUILTIN_CONSTANTS
39#endif
40
41#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
42#define __MATH_BUILTIN_RELOPS
43#endif
44
45#ifdef __MATH_BUILTIN_CONSTANTS
46#define HUGE_VAL __builtin_huge_val()
47#else
48#define HUGE_VAL (__infinity.__ud)
49#endif
50
51#if __ISO_C_VISIBLE >= 1999
52#define FP_ILOGB0 (-INT_MAX)
53#define FP_ILOGBNAN INT_MAX
54
55#ifdef __MATH_BUILTIN_CONSTANTS
56#define HUGE_VALF __builtin_huge_valf()
57#define HUGE_VALL __builtin_huge_vall()
58#define INFINITY __builtin_inff()
59#define NAN __builtin_nanf("")
60#else
61#define HUGE_VALF (float)HUGE_VAL
62#define HUGE_VALL (long double)HUGE_VAL
63#define INFINITY HUGE_VALF
64#define NAN (__nan.__uf)
65#endif /* __MATH_BUILTIN_CONSTANTS */
66
67#define MATH_ERRNO 1
68#define MATH_ERREXCEPT 2
69#define math_errhandling MATH_ERREXCEPT
70
71#define FP_FAST_FMAF 1
72
73/* Symbolic constants to classify floating point numbers. */
74#define FP_INFINITE 0x01
75#define FP_NAN 0x02
76#define FP_NORMAL 0x04
77#define FP_SUBNORMAL 0x08
78#define FP_ZERO 0x10
967141b1
JM
79
80#if (__STDC_VERSION__ >= 201112L && defined(__clang__)) || \
81 __has_extension(c_generic_selections)
82#define __fp_type_select(x, f, d, ld) _Generic((x), \
83 float: f(x), \
84 double: d(x), \
85 long double: ld(x), \
86 volatile float: f(x), \
87 volatile double: d(x), \
88 volatile long double: ld(x), \
89 volatile const float: f(x), \
90 volatile const double: d(x), \
91 volatile const long double: ld(x), \
92 const float: f(x), \
93 const double: d(x), \
94 const long double: ld(x))
95#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
96#define __fp_type_select(x, f, d, ld) __builtin_choose_expr( \
97 __builtin_types_compatible_p(__typeof(x), long double), ld(x), \
98 __builtin_choose_expr( \
99 __builtin_types_compatible_p(__typeof(x), double), d(x), \
100 __builtin_choose_expr( \
101 __builtin_types_compatible_p(__typeof(x), float), f(x), (void)0)))
102#else
103#define __fp_type_select(x, f, d, ld) \
104 ((sizeof(x) == sizeof(float)) ? f(x) \
105 : (sizeof(x) == sizeof(double)) ? d(x) \
106 : ld(x))
107#endif
108
6ff43c94 109#define fpclassify(x) \
967141b1
JM
110 __fp_type_select(x, __fpclassifyf, __fpclassifyd, __fpclassifyl)
111#define isfinite(x) __fp_type_select(x, __isfinitef, __isfinite, __isfinitel)
112#define isinf(x) __fp_type_select(x, __isinff, __isinf, __isinfl)
113#define isnan(x) \
114 __fp_type_select(x, __inline_isnanf, __inline_isnan, __inline_isnanl)
115#define isnormal(x) __fp_type_select(x, __isnormalf, __isnormal, __isnormall)
6ff43c94
PA
116
117#ifdef __MATH_BUILTIN_RELOPS
118#define isgreater(x, y) __builtin_isgreater((x), (y))
119#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
120#define isless(x, y) __builtin_isless((x), (y))
121#define islessequal(x, y) __builtin_islessequal((x), (y))
122#define islessgreater(x, y) __builtin_islessgreater((x), (y))
123#define isunordered(x, y) __builtin_isunordered((x), (y))
124#else
125#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
126#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
127#define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
128#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
129#define islessgreater(x, y) (!isunordered((x), (y)) && \
130 ((x) > (y) || (y) > (x)))
131#define isunordered(x, y) (isnan(x) || isnan(y))
132#endif /* __MATH_BUILTIN_RELOPS */
133
967141b1 134#define signbit(x) __fp_type_select(x, __signbitf, __signbit, __signbitl)
6ff43c94
PA
135
136#ifdef __LP64__
137typedef double double_t;
138typedef float float_t;
139#else
140typedef long double double_t;
141typedef long double float_t;
142#endif /* __LP64__ */
143#endif /* __ISO_C_VISIBLE >= 1999 */
144
145/*
146 * XOPEN/SVID
147 */
148#if __BSD_VISIBLE || __XSI_VISIBLE
149#define M_E 2.7182818284590452354 /* e */
150#define M_LOG2E 1.4426950408889634074 /* log 2e */
151#define M_LOG10E 0.43429448190325182765 /* log 10e */
152#define M_LN2 0.69314718055994530942 /* log e2 */
153#define M_LN10 2.30258509299404568402 /* log e10 */
154#define M_PI 3.14159265358979323846 /* pi */
155#define M_PI_2 1.57079632679489661923 /* pi/2 */
156#define M_PI_4 0.78539816339744830962 /* pi/4 */
157#define M_1_PI 0.31830988618379067154 /* 1/pi */
158#define M_2_PI 0.63661977236758134308 /* 2/pi */
159#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
160#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
161#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
162
163#define MAXFLOAT ((float)3.40282346638528860e+38)
164extern int signgam;
165#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
166
167#if __BSD_VISIBLE
168#if 0
169/* Old value from 4.4BSD-Lite math.h; this is probably better. */
170#define HUGE HUGE_VAL
171#else
172#define HUGE MAXFLOAT
173#endif
174#endif /* __BSD_VISIBLE */
175
176/*
177 * Most of these functions depend on the rounding mode and have the side
178 * effect of raising floating-point exceptions, so they are not declared
179 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
180 */
181__BEGIN_DECLS
182/*
183 * ANSI/POSIX
184 */
185int __fpclassifyd(double) __pure2;
186int __fpclassifyf(float) __pure2;
187int __fpclassifyl(long double) __pure2;
188int __isfinitef(float) __pure2;
189int __isfinite(double) __pure2;
190int __isfinitel(long double) __pure2;
191int __isinff(float) __pure2;
967141b1 192int __isinf(double) __pure2;
6ff43c94 193int __isinfl(long double) __pure2;
6ff43c94
PA
194int __isnormalf(float) __pure2;
195int __isnormal(double) __pure2;
196int __isnormall(long double) __pure2;
197int __signbit(double) __pure2;
198int __signbitf(float) __pure2;
199int __signbitl(long double) __pure2;
200
967141b1
JM
201static __inline int
202__inline_isnan(__const double __x)
203{
204
205 return (__x != __x);
206}
207
208static __inline int
209__inline_isnanf(__const float __x)
210{
211
212 return (__x != __x);
213}
214
215static __inline int
216__inline_isnanl(__const long double __x)
217{
218
219 return (__x != __x);
220}
221
222/*
223 * Version 2 of the Single UNIX Specification (UNIX98) defined isnan() and
224 * isinf() as functions taking double. C99, and the subsequent POSIX revisions
225 * (SUSv3, POSIX.1-2001, define it as a macro that accepts any real floating
226 * point type. If we are targeting SUSv2 and C99 or C11 (or C++11) then we
227 * expose the newer definition, assuming that the language spec takes
228 * precedence over the operating system interface spec.
229 */
230#if __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 && __ISO_C_VISIBLE < 1999
231#undef isinf
232#undef isnan
233int isinf(double);
234int isnan(double);
235#endif
236
6ff43c94
PA
237double acos(double);
238double asin(double);
239double atan(double);
240double atan2(double, double);
241double cos(double);
242double sin(double);
243double tan(double);
244
245double cosh(double);
246double sinh(double);
247double tanh(double);
248
249double exp(double);
250double frexp(double, int *); /* fundamentally !__pure2 */
251double ldexp(double, int);
252double log(double);
253double log10(double);
254double modf(double, double *); /* fundamentally !__pure2 */
255
256double pow(double, double);
257double sqrt(double);
258
259double ceil(double);
260double fabs(double) __pure2;
261double floor(double);
262double fmod(double, double);
263
264/*
265 * These functions are not in C90.
266 */
267#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
268double acosh(double);
269double asinh(double);
270double atanh(double);
271double cbrt(double);
272double erf(double);
273double erfc(double);
274double exp2(double);
275double expm1(double);
276double fma(double, double, double);
277double hypot(double, double);
278int ilogb(double) __pure2;
6ff43c94
PA
279double lgamma(double);
280long long llrint(double);
281long long llround(double);
282double log1p(double);
283double log2(double);
284double logb(double);
285long lrint(double);
286long lround(double);
287double nan(const char *) __pure2;
288double nextafter(double, double);
289double remainder(double, double);
290double remquo(double, double, int *);
291double rint(double);
292#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
293
294#if __BSD_VISIBLE || __XSI_VISIBLE
295double j0(double);
296double j1(double);
297double jn(int, double);
298double y0(double);
299double y1(double);
300double yn(int, double);
301
302#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
303double gamma(double);
304#endif
305
306#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
307double scalb(double, double);
308#endif
309#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
310
311#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
312double copysign(double, double) __pure2;
313double fdim(double, double);
314double fmax(double, double) __pure2;
315double fmin(double, double) __pure2;
316double nearbyint(double);
317double round(double);
318double scalbln(double, long);
319double scalbn(double, int);
320double tgamma(double);
321double trunc(double);
322#endif
323
324/*
325 * BSD math library entry points
326 */
327#if __BSD_VISIBLE
328double drem(double, double);
329int finite(double) __pure2;
330int isnanf(float) __pure2;
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
339/*
340 * IEEE Test Vector
341 */
342double significand(double);
343#endif /* __BSD_VISIBLE */
344
345/* float versions of ANSI/POSIX functions */
346#if __ISO_C_VISIBLE >= 1999
347float acosf(float);
348float asinf(float);
349float atanf(float);
350float atan2f(float, float);
351float cosf(float);
352float sinf(float);
353float tanf(float);
354
355float coshf(float);
356float sinhf(float);
357float tanhf(float);
358
359float exp2f(float);
360float expf(float);
361float expm1f(float);
362float frexpf(float, int *); /* fundamentally !__pure2 */
363int ilogbf(float) __pure2;
364float ldexpf(float, int);
365float log10f(float);
366float log1pf(float);
367float log2f(float);
368float logf(float);
369float modff(float, float *); /* fundamentally !__pure2 */
370
371float powf(float, float);
372float sqrtf(float);
373
374float ceilf(float);
375float fabsf(float) __pure2;
376float floorf(float);
377float fmodf(float, float);
378float roundf(float);
379
380float erff(float);
381float erfcf(float);
382float hypotf(float, float);
383float lgammaf(float);
384float tgammaf(float);
385
386float acoshf(float);
387float asinhf(float);
388float atanhf(float);
389float cbrtf(float);
390float logbf(float);
391float copysignf(float, float) __pure2;
392long long llrintf(float);
393long long llroundf(float);
394long lrintf(float);
395long lroundf(float);
396float nanf(const char *) __pure2;
397float nearbyintf(float);
398float nextafterf(float, float);
399float remainderf(float, float);
400float remquof(float, float, int *);
401float rintf(float);
402float scalblnf(float, long);
403float scalbnf(float, int);
404float truncf(float);
405
406float fdimf(float, float);
407float fmaf(float, float, float);
408float fmaxf(float, float) __pure2;
409float fminf(float, float) __pure2;
410#endif
411
412/*
413 * float versions of BSD math library entry points
414 */
415#if __BSD_VISIBLE
416float dremf(float, float);
417int finitef(float) __pure2;
418float gammaf(float);
419float j0f(float);
420float j1f(float);
421float jnf(int, float);
422float scalbf(float, float);
423float y0f(float);
424float y1f(float);
425float ynf(int, float);
426
427/*
428 * Float versions of reentrant version of gamma & lgamma; passes
429 * signgam back by reference as the second argument; user must
430 * allocate space for signgam.
431 */
432float gammaf_r(float, int *);
433float lgammaf_r(float, int *);
434
435/*
436 * float version of IEEE Test Vector
437 */
438float significandf(float);
439#endif /* __BSD_VISIBLE */
440
441/*
442 * long double versions of ISO/POSIX math functions
443 */
444#if __ISO_C_VISIBLE >= 1999
a8a6a916 445long double acoshl(long double);
6ff43c94 446long double acosl(long double);
a8a6a916 447long double asinhl(long double);
6ff43c94
PA
448long double asinl(long double);
449long double atan2l(long double, long double);
a8a6a916 450long double atanhl(long double);
6ff43c94
PA
451long double atanl(long double);
452long double cbrtl(long double);
453long double ceill(long double);
454long double copysignl(long double, long double) __pure2;
2fedfd5c 455long double coshl(long double);
6ff43c94 456long double cosl(long double);
2fedfd5c
JM
457long double erfcl(long double);
458long double erfl(long double);
6ff43c94
PA
459long double exp2l(long double);
460long double expl(long double);
a8a6a916 461long double expm1l(long double);
6ff43c94
PA
462long double fabsl(long double) __pure2;
463long double fdiml(long double, long double);
464long double floorl(long double);
465long double fmal(long double, long double, long double);
466long double fmaxl(long double, long double) __pure2;
467long double fminl(long double, long double) __pure2;
468long double fmodl(long double, long double);
469long double frexpl(long double value, int *); /* fundamentally !__pure2 */
470long double hypotl(long double, long double);
471int ilogbl(long double) __pure2;
472long double ldexpl(long double, int);
2fedfd5c 473long double lgammal(long double);
6ff43c94
PA
474long long llrintl(long double);
475long long llroundl(long double);
a8a6a916
JM
476long double log10l(long double);
477long double log1pl(long double);
478long double log2l(long double);
6ff43c94 479long double logbl(long double);
a8a6a916 480long double logl(long double);
6ff43c94
PA
481long lrintl(long double);
482long lroundl(long double);
483long double modfl(long double, long double *); /* fundamentally !__pure2 */
484long double nanl(const char *) __pure2;
485long double nearbyintl(long double);
486long double nextafterl(long double, long double);
487double nexttoward(double, long double);
488float nexttowardf(float, long double);
489long double nexttowardl(long double, long double);
2fedfd5c 490long double powl(long double, long double);
6ff43c94
PA
491long double remainderl(long double, long double);
492long double remquol(long double, long double, int *);
493long double rintl(long double);
494long double roundl(long double);
495long double scalblnl(long double, long);
496long double scalbnl(long double, int);
2fedfd5c 497long double sinhl(long double);
6ff43c94
PA
498long double sinl(long double);
499long double sqrtl(long double);
2fedfd5c 500long double tanhl(long double);
6ff43c94 501long double tanl(long double);
2fedfd5c 502long double tgammal(long double);
6ff43c94 503long double truncl(long double);
6ff43c94 504#endif /* __ISO_C_VISIBLE >= 1999 */
6ff43c94 505
2fedfd5c
JM
506#if __BSD_VISIBLE
507long double lgammal_r(long double, int *);
508#endif
6ff43c94
PA
509
510__END_DECLS
511
2fedfd5c 512#endif /* !_MATH_H_ */