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__
44 #endif //__SYMBIAN32__
46 #include <sys/cdefs.h>
47 #include <sys/_types.h>
48 #include <stdapis/machine/_limits.h>
51 #include <libm_aliases.h>
52 #endif //__SYMBIAN32__
56 // IEC 559 math functionality
57 #define __STDC_IEC_559__ 1
58 #endif //__SYMBIAN32__
64 extern const union __infinity_un {
65 unsigned char __uc[8];
69 extern const union __nan_un {
70 unsigned char __uc[sizeof(float)];
73 #endif //__SYMBIAN32__
75 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
76 #define __MATH_BUILTIN_CONSTANTS
79 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
80 #define __MATH_BUILTIN_RELOPS
84 #define HUGE_VAL __infinite(1.0)
86 #ifdef __MATH_BUILTIN_CONSTANTS
87 #define HUGE_VAL __builtin_huge_val()
89 #define HUGE_VAL (__infinity.__ud)
91 #endif //__SYMBIAN32__
93 #if __ISO_C_VISIBLE >= 1999
94 #define FP_ILOGB0 (-__INT_MAX)
95 #define FP_ILOGBNAN __INT_MAX
97 #ifdef __MATH_BUILTIN_CONSTANTS
98 #define HUGE_VALF __builtin_huge_valf()
99 #define HUGE_VALL __builtin_huge_vall()
100 #define INFINITY __builtin_inf()
101 #define NAN __builtin_nan("")
103 #define HUGE_VALF (float)HUGE_VAL
104 #define HUGE_VALL (long double)HUGE_VAL
105 #define INFINITY HUGE_VALF
107 #define NAN nanvalf()
109 #define NAN (__nan.__uf)
110 #endif //__SYMBIAN32__
111 #endif /* __MATH_BUILTIN_CONSTANTS */
114 #define MATH_ERREXCEPT 2
115 #define math_errhandling MATH_ERREXCEPT
117 /* XXX We need a <machine/math.h>. */
118 #if defined(__ia64__) || defined(__sparc64__)
126 /* Symbolic constants to classify floating point numbers. */
127 #define FP_INFINITE 0x01
129 #define FP_NORMAL 0x04
130 #define FP_SUBNORMAL 0x08
133 #define fpclassify(x) \
134 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
135 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
138 #define isfinite(x) \
139 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
140 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
143 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
144 : (sizeof (x) == sizeof (double)) ? __isinf(x) \
147 ((sizeof (x) == sizeof (float)) ? __isnanf(x) \
148 : (sizeof (x) == sizeof (double)) ? __isnan(x) \
150 #define isnormal(x) \
151 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
152 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
156 #ifdef __MATH_BUILTIN_RELOPS
157 #define isgreater(x, y) __builtin_isgreater((x), (y))
158 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
159 #define isless(x, y) __builtin_isless((x), (y))
160 #define islessequal(x, y) __builtin_islessequal((x), (y))
161 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
162 #define isunordered(x, y) __builtin_isunordered((x), (y))
164 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
165 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
166 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
167 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
168 #define islessgreater(x, y) (!isunordered((x), (y)) && \
169 ((x) > (y) || (y) > (x)))
170 #define isunordered(x, y) (isnan(x) || isnan(y))
171 #endif /* __MATH_BUILTIN_RELOPS */
174 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
175 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
178 typedef __double_t double_t;
179 typedef __float_t float_t;
180 #endif /* __ISO_C_VISIBLE >= 1999 */
185 #if __BSD_VISIBLE || __XSI_VISIBLE
186 #define M_E 2.7182818284590452354 /* e */
187 #define M_LOG2E 1.4426950408889634074 /* log 2e */
188 #define M_LOG10E 0.43429448190325182765 /* log 10e */
189 #define M_LN2 0.69314718055994530942 /* log e2 */
190 #define M_LN10 2.30258509299404568402 /* log e10 */
191 #define M_PI 3.14159265358979323846 /* pi */
192 #define M_PI_2 1.57079632679489661923 /* pi/2 */
193 #define M_PI_4 0.78539816339744830962 /* pi/4 */
194 #define M_1_PI 0.31830988618379067154 /* 1/pi */
195 #define M_2_PI 0.63661977236758134308 /* 2/pi */
196 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
197 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
198 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
200 #define MAXFLOAT ((float)3.40282346638528860e+38)
207 #endif //__SYMBIAN32__
208 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
212 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
213 #define HUGE HUGE_VAL
215 #define HUGE MAXFLOAT
217 #endif /* __BSD_VISIBLE */
220 * Most of these functions depend on the rounding mode and have the side
221 * effect of raising floating-point exceptions, so they are not declared
222 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
229 IMPORT_C double __infinite(double x);
230 IMPORT_C float __infinitef(float x);
232 IMPORT_C double nanval(void );
233 IMPORT_C float nanvalf(void );
234 #endif //__SYMBIAN32__
237 IMPORT_C int __fpclassifyd(double) __pure2;
238 IMPORT_C int __fpclassifyf(float) __pure2;
239 IMPORT_C int __fpclassifyl(long double) __pure2;
240 IMPORT_C int __isfinitef(float) __pure2;
241 IMPORT_C int __isfinite(double) __pure2;
242 IMPORT_C int __isfinitel(long double) __pure2;
243 IMPORT_C int __isinf(double) __pure2;
244 IMPORT_C int __isinff(float) __pure2;
245 IMPORT_C int __isinfl(long double) __pure2;
247 IMPORT_C int __isnan(double) __pure2;
248 IMPORT_C int __isnanf(float) __pure2;
249 #endif //__SYMBIAN32__
250 IMPORT_C int __isnanl(long double) __pure2;
251 IMPORT_C int __isnormalf(float) __pure2;
252 IMPORT_C int __isnormal(double) __pure2;
253 IMPORT_C int __isnormall(long double) __pure2;
254 IMPORT_C int __signbit(double) __pure2;
255 IMPORT_C int __signbitf(float) __pure2;
256 IMPORT_C int __signbitl(long double) __pure2;
258 IMPORT_C double acos(double);
259 IMPORT_C double asin(double);
260 IMPORT_C double atan(double);
261 IMPORT_C double atan2(double, double);
262 IMPORT_C double cos(double);
263 IMPORT_C double sin(double);
264 IMPORT_C double tan(double);
266 IMPORT_C double cosh(double);
267 IMPORT_C double sinh(double);
268 IMPORT_C double tanh(double);
270 IMPORT_C double exp(double);
271 IMPORT_C double frexp(double, int *); /* fundamentally !__pure2 */
272 IMPORT_C double ldexp(double, int);
273 IMPORT_C double log(double);
274 IMPORT_C double log10(double);
275 IMPORT_C double modf(double, double *); /* fundamentally !__pure2 */
277 IMPORT_C double pow(double, double);
278 IMPORT_C double sqrt(double);
280 IMPORT_C double ceil(double);
281 IMPORT_C double fabs(double) __pure2;
282 IMPORT_C double floor(double);
283 IMPORT_C double fmod(double, double);
286 * These functions are not in C90.
288 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
289 IMPORT_C double acosh(double);
290 IMPORT_C double asinh(double);
291 IMPORT_C double atanh(double);
292 IMPORT_C double cbrt(double);
293 IMPORT_C double erf(double);
294 IMPORT_C double erfc(double);
295 IMPORT_C double exp2(double);
296 IMPORT_C double expm1(double);
297 IMPORT_C double fma(double, double, double);
298 IMPORT_C double hypot(double, double);
301 IMPORT_C int ilogb(double) __pure2;
303 int (isinf)(double) __pure2;
304 int (isnan)(double) __pure2;
306 IMPORT_C double lgamma(double);
307 IMPORT_C long long llrint(double);
308 IMPORT_C long long llround(double);
309 IMPORT_C double log1p(double);
310 IMPORT_C double logb(double);
311 IMPORT_C long lrint(double);
312 IMPORT_C long lround(double);
313 IMPORT_C double nextafter(double, double);
314 IMPORT_C double remainder(double, double);
315 IMPORT_C double remquo(double, double, int *);
316 IMPORT_C double rint(double);
317 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
319 #if __BSD_VISIBLE || __XSI_VISIBLE
320 IMPORT_C double j0(double);
321 IMPORT_C double j1(double);
322 IMPORT_C double jn(int, double);
323 IMPORT_C double scalb(double, double);
324 IMPORT_C double y0(double);
325 IMPORT_C double y1(double);
326 IMPORT_C double yn(int, double);
328 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
329 IMPORT_C double gamma(double);
331 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
333 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
334 IMPORT_C double copysign(double, double) __pure2;
335 IMPORT_C double fdim(double, double);
336 IMPORT_C double fmax(double, double) __pure2;
337 IMPORT_C double fmin(double, double) __pure2;
338 IMPORT_C double nearbyint(double);
339 IMPORT_C double round(double);
340 IMPORT_C double scalbln(double, long);
341 IMPORT_C double scalbn(double, int);
342 IMPORT_C double trunc(double);
346 * BSD math library entry points
349 IMPORT_C double drem(double, double);
350 IMPORT_C int finite(double) __pure2;
351 IMPORT_C int isnanf(float) __pure2;
354 * Reentrant version of gamma & lgamma; passes signgam back by reference
355 * as the second argument; user must allocate space for signgam.
357 IMPORT_C double lgamma_r(double, int *);
362 IMPORT_C double significand(double);
363 #endif /* __BSD_VISIBLE */
365 /* float versions of ANSI/POSIX functions */
366 #if __ISO_C_VISIBLE >= 1999
367 IMPORT_C float acosf(float);
369 IMPORT_C float acosf(float);
370 IMPORT_C float asinf(float);
371 IMPORT_C float atanf(float);
372 IMPORT_C float atan2f(float, float);
373 IMPORT_C float cosf(float);
374 IMPORT_C float sinf(float);
375 IMPORT_C float tanf(float);
377 IMPORT_C float coshf(float);
378 IMPORT_C float sinhf(float);
379 IMPORT_C float tanhf(float);
380 IMPORT_C float exp2f(float);
381 IMPORT_C float expf(float);
382 IMPORT_C float expm1f(float);
383 IMPORT_C float frexpf(float, int *); /* fundamentally !__pure2 */
384 IMPORT_C int ilogbf(float) __pure2;
385 #ifndef __SYMBIAN32__
386 float ldexpf(float, int);
387 #endif //__SYMBIAN32__
388 IMPORT_C float log10f(float);
389 IMPORT_C float log1pf(float);
390 IMPORT_C float logf(float);
391 IMPORT_C float modff(float, float *); /* fundamentally !__pure2 */
393 IMPORT_C float powf(float, float);
394 IMPORT_C float sqrtf(float);
396 IMPORT_C float ceilf(float);
397 IMPORT_C float fabsf(float) __pure2;
398 IMPORT_C float floorf(float);
399 IMPORT_C float fmodf(float, float);
400 IMPORT_C float roundf(float);
402 IMPORT_C float erff(float);
403 IMPORT_C float erfcf(float);
404 IMPORT_C float hypotf(float, float);
405 IMPORT_C float lgammaf(float);
407 IMPORT_C float acoshf(float);
408 IMPORT_C float asinhf(float);
409 IMPORT_C float atanhf(float);
410 IMPORT_C float cbrtf(float);
411 IMPORT_C float logbf(float);
412 IMPORT_C float copysignf(float, float) __pure2;
413 IMPORT_C long long llrintf(float);
414 IMPORT_C long long llroundf(float);
415 IMPORT_C long lrintf(float);
416 IMPORT_C long lroundf(float);
417 IMPORT_C float nearbyintf(float);
418 IMPORT_C float nextafterf(float, float);
419 IMPORT_C float remainderf(float, float);
420 IMPORT_C float remquof(float, float, int *);
421 IMPORT_C float rintf(float);
422 IMPORT_C float scalblnf(float, long);
423 IMPORT_C float scalbnf(float, int);
424 IMPORT_C float truncf(float);
426 IMPORT_C float fdimf(float, float);
427 IMPORT_C float fmaf(float, float, float);
428 IMPORT_C float fmaxf(float, float) __pure2;
429 IMPORT_C float fminf(float, float) __pure2;
433 * float versions of BSD math library entry points
437 #ifdef __SYMBIAN_COMPILE_UNUSED__
438 float dremf(float, float);
441 IMPORT_C int finitef(float) __pure2;
442 IMPORT_C float gammaf(float);
443 IMPORT_C float j0f(float);
444 IMPORT_C float j1f(float);
445 IMPORT_C float jnf(int, float);
446 IMPORT_C float scalbf(float, float);
447 IMPORT_C float y0f(float);
448 IMPORT_C float y1f(float);
449 IMPORT_C float ynf(int, float);
452 * Float versions of reentrant version of gamma & lgamma; passes
453 * signgam back by reference as the second argument; user must
454 * allocate space for signgam.
456 IMPORT_C float lgammaf_r(float, int *);
459 * float version of IEEE Test Vector
461 IMPORT_C float significandf(float);
462 #endif /* __BSD_VISIBLE */
465 * long double versions of ISO/POSIX math functions
467 #if __ISO_C_VISIBLE >= 1999
469 long double acoshl(long double);
470 long double acosl(long double);
471 long double asinhl(long double);
472 long double asinl(long double);
473 long double atan2l(long double, long double);
474 long double atanhl(long double);
475 long double atanl(long double);
476 long double cbrtl(long double);
478 #ifndef __SYMBIAN32__
479 long double ceill(long double);
480 #endif //__SYMBIAN32__
481 IMPORT_C long double copysignl(long double, long double) __pure2;
483 long double coshl(long double);
484 long double cosl(long double);
485 long double erfcl(long double);
486 long double erfl(long double);
487 long double exp2l(long double);
488 long double expl(long double);
489 long double expm1l(long double);
491 IMPORT_C long double fabsl(long double) __pure2;
492 IMPORT_C long double fdiml(long double, long double);
493 #ifndef __SYMBIAN32__
494 long double floorl(long double);
495 long double fmal(long double, long double, long double);
496 #endif //__SYMBIAN32__
497 IMPORT_C long double fmaxl(long double, long double) __pure2;
498 #ifndef __SYMBIAN32__
499 long double fminl(long double, long double) __pure2;
500 #endif //__SYMBIAN32__
502 long double fmodl(long double, long double);
504 #ifndef __SYMBIAN32__
505 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
506 #endif //__SYMBIAN32__
508 long double hypotl(long double, long double);
510 IMPORT_C int ilogbl(long double) __pure2;
511 #ifndef __SYMBIAN32__
512 long double ldexpl(long double, int);
513 #endif //__SYMBIAN32__
515 long double lgammal(long double);
516 long long llrintl(long double);
518 #ifndef __SYMBIAN32__
519 long long llroundl(long double);
520 #endif //__SYMBIAN32__
522 long double log10l(long double);
523 long double log1pl(long double);
524 long double log2l(long double);
525 long double logbl(long double);
526 long double logl(long double);
527 long lrintl(long double);
529 #ifndef __SYMBIAN32__
530 long lroundl(long double);
531 #endif //__SYMBIAN32__
533 long double modfl(long double, long double *); /* fundamentally !__pure2 */
534 long double nanl(const char *) __pure2;
535 long double nearbyintl(long double);
537 #ifndef __SYMBIAN32__
538 long double nextafterl(long double, long double);
539 double nexttoward(double, long double);
540 #endif //__SYMBIAN32__
541 IMPORT_C float nexttowardf(float, long double);
542 #ifndef __SYMBIAN32__
543 long double nexttowardl(long double, long double);
544 #endif //__SYMBIAN32__
546 long double powl(long double, long double);
547 long double remainderl(long double, long double);
548 long double remquol(long double, long double, int *);
549 long double rintl(long double);
551 #ifndef __SYMBIAN32__
552 long double roundl(long double);
553 #endif //__SYMBIAN32__
554 IMPORT_C long double scalblnl(long double, long);
555 #ifndef __SYMBIAN32__
556 long double scalbnl(long double, int);
557 #endif //__SYMBIAN32__
559 long double sinhl(long double);
560 long double sinl(long double);
561 long double sqrtl(long double);
562 long double tanhl(long double);
563 long double tanl(long double);
565 IMPORT_C long double truncl(long double);
567 #endif /* __ISO_C_VISIBLE >= 1999 */
570 #endif /* !_MATH_H_ */