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