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