Update contrib.
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
11 * Portions Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
15 * from: @(#)fdlibm.h 5.1 93/09/24
16 * $FreeBSD: src/lib/msun/src/math.h,v 1.61 2005/04/16 21:12:47 das Exp $
25 /* warning C4056: overflow in floating-point constant arithmetic
26 * Caused by negative floating point constants, it seems!
27 * For example, static double foo = -1.0;
29 #pragma warning( disable: 4056 )
32 /* Warning: #222-D: floating-point operation result is out of range
33 * The compiler detects constant math that overflows, we want overflow though!
34 * Warning: #39-D: division by zero
36 #pragma diag_suppress 222
37 #pragma diag_suppress 39
38 #pragma diag_suppress 2874
40 #endif //__SYMBIAN32__
49 #endif //__SYMBIAN32__
51 #include <sys/cdefs.h>
52 #include <sys/_types.h>
53 #include <stdapis/machine/_limits.h>
56 #include <libm_aliases.h>
57 #endif //__SYMBIAN32__
61 // IEC 559 math functionality
62 #define __STDC_IEC_559__ 1
63 #endif //__SYMBIAN32__
69 extern const union __infinity_un {
70 unsigned char __uc[8];
74 extern const union __nan_un {
75 unsigned char __uc[sizeof(float)];
78 #endif //__SYMBIAN32__
80 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
81 #define __MATH_BUILTIN_CONSTANTS
84 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
85 #define __MATH_BUILTIN_RELOPS
89 #define HUGE_VAL __infinite(1.0)
91 #ifdef __MATH_BUILTIN_CONSTANTS
92 #define HUGE_VAL __builtin_huge_val()
94 #define HUGE_VAL (__infinity.__ud)
96 #endif //__SYMBIAN32__
98 #if __ISO_C_VISIBLE >= 1999
99 #define FP_ILOGB0 (-__INT_MAX)
100 #define FP_ILOGBNAN __INT_MAX
102 #ifdef __MATH_BUILTIN_CONSTANTS
103 #define HUGE_VALF __builtin_huge_valf()
104 #define HUGE_VALL __builtin_huge_vall()
105 #define INFINITY __builtin_inf()
106 #define NAN __builtin_nan("")
108 #define HUGE_VALF (float)HUGE_VAL
109 #define HUGE_VALL (long double)HUGE_VAL
110 #define INFINITY HUGE_VALF
112 #define NAN nanvalf()
114 #define NAN (__nan.__uf)
115 #endif //__SYMBIAN32__
116 #endif /* __MATH_BUILTIN_CONSTANTS */
119 #define MATH_ERREXCEPT 2
120 #define math_errhandling MATH_ERREXCEPT
122 /* XXX We need a <machine/math.h>. */
123 #if defined(__ia64__) || defined(__sparc64__)
131 /* Symbolic constants to classify floating point numbers. */
132 #define FP_INFINITE 0x01
134 #define FP_NORMAL 0x04
135 #define FP_SUBNORMAL 0x08
138 #define fpclassify(x) \
139 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
140 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
143 #define isfinite(x) \
144 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
145 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
148 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
149 : (sizeof (x) == sizeof (double)) ? __isinf(x) \
152 ((sizeof (x) == sizeof (float)) ? __isnanf(x) \
153 : (sizeof (x) == sizeof (double)) ? __isnan(x) \
155 #define isnormal(x) \
156 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
157 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
161 #ifdef __MATH_BUILTIN_RELOPS
162 #define isgreater(x, y) __builtin_isgreater((x), (y))
163 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
164 #define isless(x, y) __builtin_isless((x), (y))
165 #define islessequal(x, y) __builtin_islessequal((x), (y))
166 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
167 #define isunordered(x, y) __builtin_isunordered((x), (y))
169 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
170 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
171 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
172 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
173 #define islessgreater(x, y) (!isunordered((x), (y)) && \
174 ((x) > (y) || (y) > (x)))
175 #define isunordered(x, y) (isnan(x) || isnan(y))
176 #endif /* __MATH_BUILTIN_RELOPS */
179 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
180 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
183 typedef __double_t double_t;
184 typedef __float_t float_t;
185 #endif /* __ISO_C_VISIBLE >= 1999 */
190 #if __BSD_VISIBLE || __XSI_VISIBLE
191 #define M_E 2.7182818284590452354 /* e */
192 #define M_LOG2E 1.4426950408889634074 /* log 2e */
193 #define M_LOG10E 0.43429448190325182765 /* log 10e */
194 #define M_LN2 0.69314718055994530942 /* log e2 */
195 #define M_LN10 2.30258509299404568402 /* log e10 */
196 #define M_PI 3.14159265358979323846 /* pi */
197 #define M_PI_2 1.57079632679489661923 /* pi/2 */
198 #define M_PI_4 0.78539816339744830962 /* pi/4 */
199 #define M_1_PI 0.31830988618379067154 /* 1/pi */
200 #define M_2_PI 0.63661977236758134308 /* 2/pi */
201 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
202 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
203 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
205 #define MAXFLOAT ((float)3.40282346638528860e+38)
212 #endif //__SYMBIAN32__
213 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
217 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
218 #define HUGE HUGE_VAL
220 #define HUGE MAXFLOAT
222 #endif /* __BSD_VISIBLE */
225 * Most of these functions depend on the rounding mode and have the side
226 * effect of raising floating-point exceptions, so they are not declared
227 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
234 IMPORT_C double __infinite(double x) __SOFTFP;
235 IMPORT_C float __infinitef(float x) __SOFTFP;
237 IMPORT_C double nanval(void )__SOFTFP;
238 IMPORT_C float nanvalf(void ) __SOFTFP;
239 #endif //__SYMBIAN32__
242 IMPORT_C int __fpclassifyd(double) __SOFTFP __pure2;
243 IMPORT_C int __fpclassifyf(float) __SOFTFP __pure2;
244 IMPORT_C int __fpclassifyl(long double) __SOFTFP __pure2;
245 IMPORT_C int __isfinitef(float) __SOFTFP __pure2;
246 IMPORT_C int __isfinite(double) __SOFTFP __pure2;
247 IMPORT_C int __isfinitel(long double) __SOFTFP __pure2;
248 IMPORT_C int __isinf(double) __SOFTFP __pure2;
249 IMPORT_C int __isinff(float) __SOFTFP __pure2;
250 IMPORT_C int __isinfl(long double) __SOFTFP __pure2;
252 IMPORT_C int __isnan(double) __SOFTFP __pure2;
253 IMPORT_C int __isnanf(float) __SOFTFP __pure2;
254 #endif //__SYMBIAN32__
255 IMPORT_C int __isnanl(long double) __SOFTFP __pure2;
256 IMPORT_C int __isnormalf(float) __SOFTFP __pure2;
257 IMPORT_C int __isnormal(double) __SOFTFP __pure2;
258 IMPORT_C int __isnormall(long double) __SOFTFP __pure2;
259 IMPORT_C int __signbit(double) __SOFTFP __pure2;
260 IMPORT_C int __signbitf(float) __SOFTFP __pure2;
261 IMPORT_C int __signbitl(long double) __SOFTFP __pure2;
263 IMPORT_C double acos(double) __SOFTFP;
264 IMPORT_C double asin(double) __SOFTFP;
265 IMPORT_C double atan(double) __SOFTFP;
266 IMPORT_C double atan2(double, double) __SOFTFP;
267 IMPORT_C double cos(double) __SOFTFP;
268 IMPORT_C double sin(double) __SOFTFP;
269 IMPORT_C double tan(double) __SOFTFP;
271 IMPORT_C double cosh(double) __SOFTFP;
272 IMPORT_C double sinh(double) __SOFTFP;
273 IMPORT_C double tanh(double) __SOFTFP;
275 IMPORT_C double exp(double) __SOFTFP;
276 IMPORT_C double frexp(double, int *) __SOFTFP; /* fundamentally !__pure2 */
277 IMPORT_C double ldexp(double, int) __SOFTFP;
278 IMPORT_C double log(double) __SOFTFP;
279 IMPORT_C double log10(double) __SOFTFP;
280 IMPORT_C double modf(double, double *) __SOFTFP; /* fundamentally !__pure2 */
282 IMPORT_C double pow(double, double) __SOFTFP;
283 IMPORT_C double sqrt(double) __SOFTFP;
285 IMPORT_C double ceil(double) __SOFTFP;
286 IMPORT_C double fabs(double) __SOFTFP __pure2;
287 IMPORT_C double floor(double) __SOFTFP;
288 IMPORT_C double fmod(double, double) __SOFTFP;
291 * These functions are not in C90.
293 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
294 IMPORT_C double acosh(double) __SOFTFP;
295 IMPORT_C double asinh(double) __SOFTFP;
296 IMPORT_C double atanh(double) __SOFTFP;
297 IMPORT_C double cbrt(double) __SOFTFP;
298 IMPORT_C double erf(double) __SOFTFP;
299 IMPORT_C double erfc(double) __SOFTFP;
300 IMPORT_C double exp2(double) __SOFTFP;
301 IMPORT_C double expm1(double) __SOFTFP;
302 IMPORT_C double fma(double, double, double) __SOFTFP;
303 IMPORT_C double hypot(double, double) __SOFTFP;
306 IMPORT_C int ilogb(double) __SOFTFP __pure2;
308 int (isinf)(double) __pure2;
309 int (isnan)(double) __pure2;
311 IMPORT_C double lgamma(double) __SOFTFP;
312 IMPORT_C long long llrint(double) __SOFTFP;
313 IMPORT_C long long llround(double) __SOFTFP;
314 IMPORT_C double log1p(double) __SOFTFP;
315 IMPORT_C double logb(double) __SOFTFP;
316 IMPORT_C long lrint(double) __SOFTFP;
317 IMPORT_C long lround(double) __SOFTFP;
318 IMPORT_C double nextafter(double, double) __SOFTFP;
319 IMPORT_C double remainder(double, double) __SOFTFP;
320 IMPORT_C double remquo(double, double, int *) __SOFTFP;
321 IMPORT_C double rint(double) __SOFTFP;
322 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
324 #if __BSD_VISIBLE || __XSI_VISIBLE
325 IMPORT_C double j0(double) __SOFTFP;
326 IMPORT_C double j1(double) __SOFTFP;
327 IMPORT_C double jn(int, double) __SOFTFP;
328 IMPORT_C double scalb(double, double) __SOFTFP;
329 IMPORT_C double y0(double) __SOFTFP;
330 IMPORT_C double y1(double) __SOFTFP;
331 IMPORT_C double yn(int, double) __SOFTFP;
333 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
334 IMPORT_C double gamma(double) __SOFTFP;
336 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
338 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
339 IMPORT_C double copysign(double, double) __SOFTFP __pure2;
340 IMPORT_C double fdim(double, double) __SOFTFP;
341 IMPORT_C double fmax(double, double) __SOFTFP __pure2;
342 IMPORT_C double fmin(double, double) __SOFTFP __pure2;
343 IMPORT_C double nearbyint(double) __SOFTFP;
344 IMPORT_C double round(double) __SOFTFP;
345 IMPORT_C double scalbln(double, long) __SOFTFP;
346 IMPORT_C double scalbn(double, int) __SOFTFP;
347 IMPORT_C double trunc(double) __SOFTFP;
351 * BSD math library entry points
354 IMPORT_C double drem(double, double) __SOFTFP;
355 IMPORT_C int finite(double) __SOFTFP __pure2;
356 IMPORT_C int isnanf(float) __SOFTFP __pure2;
359 * Reentrant version of gamma & lgamma; passes signgam back by reference
360 * as the second argument; user must allocate space for signgam.
362 IMPORT_C double lgamma_r(double, int *) __SOFTFP;
367 IMPORT_C double significand(double) __SOFTFP;
368 #endif /* __BSD_VISIBLE */
370 /* float versions of ANSI/POSIX functions */
371 #if __ISO_C_VISIBLE >= 1999
372 IMPORT_C float acosf(float) __SOFTFP;
374 IMPORT_C float acosf(float) __SOFTFP;
375 IMPORT_C float asinf(float) __SOFTFP;
376 IMPORT_C float atanf(float) __SOFTFP;
377 IMPORT_C float atan2f(float, float) __SOFTFP;
378 IMPORT_C float cosf(float) __SOFTFP;
379 IMPORT_C float sinf(float) __SOFTFP;
380 IMPORT_C float tanf(float) __SOFTFP;
382 IMPORT_C float coshf(float) __SOFTFP;
383 IMPORT_C float sinhf(float) __SOFTFP;
384 IMPORT_C float tanhf(float) __SOFTFP;
385 IMPORT_C float exp2f(float) __SOFTFP;
386 IMPORT_C float expf(float) __SOFTFP;
387 IMPORT_C float expm1f(float) __SOFTFP;
388 IMPORT_C float frexpf(float, int *) __SOFTFP; /* fundamentally !__pure2 */
389 IMPORT_C int ilogbf(float) __SOFTFP __pure2;
390 #ifndef __SYMBIAN32__
391 float ldexpf(float, int);
392 #endif //__SYMBIAN32__
393 IMPORT_C float log10f(float) __SOFTFP;
394 IMPORT_C float log1pf(float) __SOFTFP;
395 IMPORT_C float logf(float) __SOFTFP;
396 IMPORT_C float modff(float, float *) __SOFTFP; /* fundamentally !__pure2 */
398 IMPORT_C float powf(float, float) __SOFTFP;
399 IMPORT_C float sqrtf(float) __SOFTFP;
401 IMPORT_C float ceilf(float) __SOFTFP;
402 IMPORT_C float fabsf(float) __SOFTFP __pure2;
403 IMPORT_C float floorf(float) __SOFTFP;
404 IMPORT_C float fmodf(float, float) __SOFTFP;
405 IMPORT_C float roundf(float) __SOFTFP;
407 IMPORT_C float erff(float) __SOFTFP;
408 IMPORT_C float erfcf(float) __SOFTFP;
409 IMPORT_C float hypotf(float, float) __SOFTFP;
410 IMPORT_C float lgammaf(float) __SOFTFP;
412 IMPORT_C float acoshf(float) __SOFTFP;
413 IMPORT_C float asinhf(float) __SOFTFP;
414 IMPORT_C float atanhf(float) __SOFTFP;
415 IMPORT_C float cbrtf(float) __SOFTFP;
416 IMPORT_C float logbf(float) __SOFTFP;
417 IMPORT_C float copysignf(float, float) __SOFTFP __pure2;
418 IMPORT_C long long llrintf(float) __SOFTFP;
419 IMPORT_C long long llroundf(float) __SOFTFP;
420 IMPORT_C long lrintf(float) __SOFTFP;
421 IMPORT_C long lroundf(float) __SOFTFP;
422 IMPORT_C float nearbyintf(float) __SOFTFP;
423 IMPORT_C float nextafterf(float, float) __SOFTFP;
424 IMPORT_C float remainderf(float, float) __SOFTFP;
425 IMPORT_C float remquof(float, float, int *) __SOFTFP;
426 IMPORT_C float rintf(float) __SOFTFP;
427 IMPORT_C float scalblnf(float, long) __SOFTFP;
428 IMPORT_C float scalbnf(float, int) __SOFTFP;
429 IMPORT_C float truncf(float) __SOFTFP;
431 IMPORT_C float fdimf(float, float) __SOFTFP;
432 IMPORT_C float fmaf(float, float, float) __SOFTFP;
433 IMPORT_C float fmaxf(float, float) __SOFTFP __pure2;
434 IMPORT_C float fminf(float, float) __SOFTFP __pure2;
438 * float versions of BSD math library entry points
442 #ifdef __SYMBIAN_COMPILE_UNUSED__
443 float dremf(float, float);
446 IMPORT_C int finitef(float) __SOFTFP __pure2;
447 IMPORT_C float gammaf(float) __SOFTFP;
448 IMPORT_C float j0f(float) __SOFTFP;
449 IMPORT_C float j1f(float) __SOFTFP;
450 IMPORT_C float jnf(int, float) __SOFTFP;
451 IMPORT_C float scalbf(float, float) __SOFTFP;
452 IMPORT_C float y0f(float) __SOFTFP;
453 IMPORT_C float y1f(float) __SOFTFP;
454 IMPORT_C float ynf(int, float) __SOFTFP;
457 * Float versions of reentrant version of gamma & lgamma; passes
458 * signgam back by reference as the second argument; user must
459 * allocate space for signgam.
461 IMPORT_C float lgammaf_r(float, int *) __SOFTFP;
464 * float version of IEEE Test Vector
466 IMPORT_C float significandf(float) __SOFTFP;
467 #endif /* __BSD_VISIBLE */
470 * long double versions of ISO/POSIX math functions
472 #if __ISO_C_VISIBLE >= 1999
474 long double acoshl(long double);
475 long double acosl(long double);
476 long double asinhl(long double);
477 long double asinl(long double);
478 long double atan2l(long double, long double);
479 long double atanhl(long double);
480 long double atanl(long double);
481 long double cbrtl(long double);
483 #ifndef __SYMBIAN32__
484 long double ceill(long double);
485 #endif //__SYMBIAN32__
486 IMPORT_C long double copysignl(long double, long double) __SOFTFP __pure2;
488 long double coshl(long double);
489 long double cosl(long double);
490 long double erfcl(long double);
491 long double erfl(long double);
492 long double exp2l(long double);
493 long double expl(long double);
494 long double expm1l(long double);
496 IMPORT_C long double fabsl(long double) __SOFTFP __pure2;
497 IMPORT_C long double fdiml(long double, long double) __SOFTFP;
498 #ifndef __SYMBIAN32__
499 long double floorl(long double);
500 long double fmal(long double, long double, long double);
501 #endif //__SYMBIAN32__
502 IMPORT_C long double fmaxl(long double, long double) __SOFTFP __pure2;
503 #ifndef __SYMBIAN32__
504 long double fminl(long double, long double) __pure2;
505 #endif //__SYMBIAN32__
507 long double fmodl(long double, long double);
509 #ifndef __SYMBIAN32__
510 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
511 #endif //__SYMBIAN32__
513 long double hypotl(long double, long double);
515 IMPORT_C int ilogbl(long double) __SOFTFP __pure2;
516 #ifndef __SYMBIAN32__
517 long double ldexpl(long double, int);
518 #endif //__SYMBIAN32__
520 long double lgammal(long double);
521 long long llrintl(long double);
523 #ifndef __SYMBIAN32__
524 long long llroundl(long double);
525 #endif //__SYMBIAN32__
527 long double log10l(long double);
528 long double log1pl(long double);
529 long double log2l(long double);
530 long double logbl(long double);
531 long double logl(long double);
532 long lrintl(long double);
534 #ifndef __SYMBIAN32__
535 long lroundl(long double);
536 #endif //__SYMBIAN32__
538 long double modfl(long double, long double *); /* fundamentally !__pure2 */
539 long double nanl(const char *) __pure2;
540 long double nearbyintl(long double);
542 #ifndef __SYMBIAN32__
543 long double nextafterl(long double, long double);
544 double nexttoward(double, long double);
545 #endif //__SYMBIAN32__
546 IMPORT_C float nexttowardf(float, long double) __SOFTFP;
547 #ifndef __SYMBIAN32__
548 long double nexttowardl(long double, long double);
549 #endif //__SYMBIAN32__
551 long double powl(long double, long double);
552 long double remainderl(long double, long double);
553 long double remquol(long double, long double, int *);
554 long double rintl(long double);
556 #ifndef __SYMBIAN32__
557 long double roundl(long double);
558 #endif //__SYMBIAN32__
559 IMPORT_C long double scalblnl(long double, long) __SOFTFP;
560 #ifndef __SYMBIAN32__
561 long double scalbnl(long double, int);
562 #endif //__SYMBIAN32__
564 long double sinhl(long double);
565 long double sinl(long double);
566 long double sqrtl(long double);
567 long double tanhl(long double);
568 long double tanl(long double);
570 IMPORT_C long double truncl(long double) __SOFTFP;
572 #endif /* __ISO_C_VISIBLE >= 1999 */
575 #endif /* !_MATH_H_ */