1 /*--------------------------------------------------------------------
2 *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
3 *--------------------------------------------------------------------
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
14 * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
18 * from: @(#)fdlibm.h 5.1 93/09/24
19 * $FreeBSD: src/lib/msun/src/math.h,v 1.61 2005/04/16 21:12:47 das Exp $
28 /* warning C4056: overflow in floating-point constant arithmetic
29 * Caused by negative floating point constants, it seems!
30 * For example, static double foo = -1.0;
32 #pragma warning( disable: 4056 )
35 /* Warning: #222-D: floating-point operation result is out of range
36 * The compiler detects constant math that overflows, we want overflow though!
37 * Warning: #39-D: division by zero
39 #pragma diag_suppress 222
40 #pragma diag_suppress 39
41 #pragma diag_suppress 2874
43 #endif //__SYMBIAN32__
47 #endif //__SYMBIAN32__
49 #include <sys/cdefs.h>
50 #include <sys/_types.h>
51 #include <machine/_limits.h>
54 #include <libm_aliases.h>
55 #endif //__SYMBIAN32__
59 // IEC 559 math functionality
60 #define __STDC_IEC_559__ 1
61 #endif //__SYMBIAN32__
67 extern const union __infinity_un {
68 unsigned char __uc[8];
72 extern const union __nan_un {
73 unsigned char __uc[sizeof(float)];
76 #endif //__SYMBIAN32__
78 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
79 #define __MATH_BUILTIN_CONSTANTS
82 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
83 #define __MATH_BUILTIN_RELOPS
87 #define HUGE_VAL __infinite(1.0)
89 #ifdef __MATH_BUILTIN_CONSTANTS
90 #define HUGE_VAL __builtin_huge_val()
92 #define HUGE_VAL (__infinity.__ud)
94 #endif //__SYMBIAN32__
96 #if __ISO_C_VISIBLE >= 1999
97 #define FP_ILOGB0 (-__INT_MAX)
98 #define FP_ILOGBNAN __INT_MAX
100 #ifdef __MATH_BUILTIN_CONSTANTS
101 #define HUGE_VALF __builtin_huge_valf()
102 #define HUGE_VALL __builtin_huge_vall()
103 #define INFINITY __builtin_inf()
104 #define NAN __builtin_nan("")
106 #define HUGE_VALF (float)HUGE_VAL
107 #define HUGE_VALL (long double)HUGE_VAL
108 #define INFINITY HUGE_VALF
110 #define NAN nanvalf()
112 #define NAN (__nan.__uf)
113 #endif //__SYMBIAN32__
114 #endif /* __MATH_BUILTIN_CONSTANTS */
117 #define MATH_ERREXCEPT 2
118 #define math_errhandling MATH_ERREXCEPT
120 /* XXX We need a <machine/math.h>. */
121 #if defined(__ia64__) || defined(__sparc64__)
129 /* Symbolic constants to classify floating point numbers. */
130 #define FP_INFINITE 0x01
132 #define FP_NORMAL 0x04
133 #define FP_SUBNORMAL 0x08
136 #define fpclassify(x) \
137 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
138 : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
141 #define isfinite(x) \
142 ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
143 : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
146 ((sizeof (x) == sizeof (float)) ? __isinff(x) \
147 : (sizeof (x) == sizeof (double)) ? __isinf(x) \
150 ((sizeof (x) == sizeof (float)) ? __isnanf(x) \
151 : (sizeof (x) == sizeof (double)) ? __isnan(x) \
153 #define isnormal(x) \
154 ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
155 : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
159 #ifdef __MATH_BUILTIN_RELOPS
160 #define isgreater(x, y) __builtin_isgreater((x), (y))
161 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
162 #define isless(x, y) __builtin_isless((x), (y))
163 #define islessequal(x, y) __builtin_islessequal((x), (y))
164 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
165 #define isunordered(x, y) __builtin_isunordered((x), (y))
167 #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
168 #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
169 #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
170 #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
171 #define islessgreater(x, y) (!isunordered((x), (y)) && \
172 ((x) > (y) || (y) > (x)))
173 #define isunordered(x, y) (isnan(x) || isnan(y))
174 #endif /* __MATH_BUILTIN_RELOPS */
177 ((sizeof (x) == sizeof (float)) ? __signbitf(x) \
178 : (sizeof (x) == sizeof (double)) ? __signbit(x) \
181 typedef __double_t double_t;
182 typedef __float_t float_t;
183 #endif /* __ISO_C_VISIBLE >= 1999 */
188 #if __BSD_VISIBLE || __XSI_VISIBLE
189 #define M_E 2.7182818284590452354 /* e */
190 #define M_LOG2E 1.4426950408889634074 /* log 2e */
191 #define M_LOG10E 0.43429448190325182765 /* log 10e */
192 #define M_LN2 0.69314718055994530942 /* log e2 */
193 #define M_LN10 2.30258509299404568402 /* log e10 */
194 #define M_PI 3.14159265358979323846 /* pi */
195 #define M_PI_2 1.57079632679489661923 /* pi/2 */
196 #define M_PI_4 0.78539816339744830962 /* pi/4 */
197 #define M_1_PI 0.31830988618379067154 /* 1/pi */
198 #define M_2_PI 0.63661977236758134308 /* 2/pi */
199 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
200 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
201 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
203 #define MAXFLOAT ((float)3.40282346638528860e+38)
210 #endif //__SYMBIAN32__
211 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
215 /* Old value from 4.4BSD-Lite math.h; this is probably better. */
216 #define HUGE HUGE_VAL
218 #define HUGE MAXFLOAT
220 #endif /* __BSD_VISIBLE */
223 * Most of these functions depend on the rounding mode and have the side
224 * effect of raising floating-point exceptions, so they are not declared
225 * as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
232 IMPORT_C double __infinite(double x);
233 IMPORT_C float __infinitef(float x);
235 IMPORT_C double nanval(void );
236 IMPORT_C float nanvalf(void );
237 #endif //__SYMBIAN32__
240 IMPORT_C int __fpclassifyd(double) __pure2;
241 IMPORT_C int __fpclassifyf(float) __pure2;
242 IMPORT_C int __fpclassifyl(long double) __pure2;
243 IMPORT_C int __isfinitef(float) __pure2;
244 IMPORT_C int __isfinite(double) __pure2;
245 IMPORT_C int __isfinitel(long double) __pure2;
246 IMPORT_C int __isinf(double) __pure2;
247 IMPORT_C int __isinff(float) __pure2;
248 IMPORT_C int __isinfl(long double) __pure2;
250 IMPORT_C int __isnan(double) __pure2;
251 IMPORT_C int __isnanf(float) __pure2;
252 #endif //__SYMBIAN32__
253 IMPORT_C int __isnanl(long double) __pure2;
254 IMPORT_C int __isnormalf(float) __pure2;
255 IMPORT_C int __isnormal(double) __pure2;
256 IMPORT_C int __isnormall(long double) __pure2;
257 IMPORT_C int __signbit(double) __pure2;
258 IMPORT_C int __signbitf(float) __pure2;
259 IMPORT_C int __signbitl(long double) __pure2;
261 IMPORT_C double acos(double);
262 IMPORT_C double asin(double);
263 IMPORT_C double atan(double);
264 IMPORT_C double atan2(double, double);
265 IMPORT_C double cos(double);
266 IMPORT_C double sin(double);
267 IMPORT_C double tan(double);
269 IMPORT_C double cosh(double);
270 IMPORT_C double sinh(double);
271 IMPORT_C double tanh(double);
273 IMPORT_C double exp(double);
274 IMPORT_C double frexp(double, int *); /* fundamentally !__pure2 */
275 IMPORT_C double ldexp(double, int);
276 IMPORT_C double log(double);
277 IMPORT_C double log10(double);
278 IMPORT_C double modf(double, double *); /* fundamentally !__pure2 */
280 IMPORT_C double pow(double, double);
281 IMPORT_C double sqrt(double);
283 IMPORT_C double ceil(double);
284 IMPORT_C double fabs(double) __pure2;
285 IMPORT_C double floor(double);
286 IMPORT_C double fmod(double, double);
289 * These functions are not in C90.
291 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
292 IMPORT_C double acosh(double);
293 IMPORT_C double asinh(double);
294 IMPORT_C double atanh(double);
295 IMPORT_C double cbrt(double);
296 IMPORT_C double erf(double);
297 IMPORT_C double erfc(double);
298 IMPORT_C double exp2(double);
299 IMPORT_C double expm1(double);
300 IMPORT_C double fma(double, double, double);
301 IMPORT_C double hypot(double, double);
304 IMPORT_C int ilogb(double) __pure2;
306 int (isinf)(double) __pure2;
307 int (isnan)(double) __pure2;
309 IMPORT_C double lgamma(double);
310 IMPORT_C long long llrint(double);
311 IMPORT_C long long llround(double);
312 IMPORT_C double log1p(double);
313 IMPORT_C double logb(double);
314 IMPORT_C long lrint(double);
315 IMPORT_C long lround(double);
316 IMPORT_C double nextafter(double, double);
317 IMPORT_C double remainder(double, double);
318 IMPORT_C double remquo(double, double, int *);
319 IMPORT_C double rint(double);
320 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
322 #if __BSD_VISIBLE || __XSI_VISIBLE
323 IMPORT_C double j0(double);
324 IMPORT_C double j1(double);
325 IMPORT_C double jn(int, double);
326 IMPORT_C double scalb(double, double);
327 IMPORT_C double y0(double);
328 IMPORT_C double y1(double);
329 IMPORT_C double yn(int, double);
331 #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
332 IMPORT_C double gamma(double);
334 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
336 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
337 IMPORT_C double copysign(double, double) __pure2;
338 IMPORT_C double fdim(double, double);
339 IMPORT_C double fmax(double, double) __pure2;
340 IMPORT_C double fmin(double, double) __pure2;
341 IMPORT_C double nearbyint(double);
342 IMPORT_C double round(double);
343 IMPORT_C double scalbln(double, long);
344 IMPORT_C double scalbn(double, int);
345 IMPORT_C double trunc(double);
349 * BSD math library entry points
352 IMPORT_C double drem(double, double);
353 IMPORT_C int finite(double) __pure2;
354 IMPORT_C int isnanf(float) __pure2;
357 * Reentrant version of gamma & lgamma; passes signgam back by reference
358 * as the second argument; user must allocate space for signgam.
360 IMPORT_C double lgamma_r(double, int *);
365 IMPORT_C double significand(double);
366 #endif /* __BSD_VISIBLE */
368 /* float versions of ANSI/POSIX functions */
369 #if __ISO_C_VISIBLE >= 1999
370 IMPORT_C float acosf(float);
372 IMPORT_C float acosf(float);
373 IMPORT_C float asinf(float);
374 IMPORT_C float atanf(float);
375 IMPORT_C float atan2f(float, float);
376 IMPORT_C float cosf(float);
377 IMPORT_C float sinf(float);
378 IMPORT_C float tanf(float);
380 IMPORT_C float coshf(float);
381 IMPORT_C float sinhf(float);
382 IMPORT_C float tanhf(float);
383 IMPORT_C float exp2f(float);
384 IMPORT_C float expf(float);
385 IMPORT_C float expm1f(float);
386 IMPORT_C float frexpf(float, int *); /* fundamentally !__pure2 */
387 IMPORT_C int ilogbf(float) __pure2;
388 #ifndef __SYMBIAN32__
389 float ldexpf(float, int);
390 #endif //__SYMBIAN32__
391 IMPORT_C float log10f(float);
392 IMPORT_C float log1pf(float);
393 IMPORT_C float logf(float);
394 IMPORT_C float modff(float, float *); /* fundamentally !__pure2 */
396 IMPORT_C float powf(float, float);
397 IMPORT_C float sqrtf(float);
399 IMPORT_C float ceilf(float);
400 IMPORT_C float fabsf(float) __pure2;
401 IMPORT_C float floorf(float);
402 IMPORT_C float fmodf(float, float);
403 IMPORT_C float roundf(float);
405 IMPORT_C float erff(float);
406 IMPORT_C float erfcf(float);
407 IMPORT_C float hypotf(float, float);
408 IMPORT_C float lgammaf(float);
410 IMPORT_C float acoshf(float);
411 IMPORT_C float asinhf(float);
412 IMPORT_C float atanhf(float);
413 IMPORT_C float cbrtf(float);
414 IMPORT_C float logbf(float);
415 IMPORT_C float copysignf(float, float) __pure2;
416 IMPORT_C long long llrintf(float);
417 IMPORT_C long long llroundf(float);
418 IMPORT_C long lrintf(float);
419 IMPORT_C long lroundf(float);
420 IMPORT_C float nearbyintf(float);
421 IMPORT_C float nextafterf(float, float);
422 IMPORT_C float remainderf(float, float);
423 IMPORT_C float remquof(float, float, int *);
424 IMPORT_C float rintf(float);
425 IMPORT_C float scalblnf(float, long);
426 IMPORT_C float scalbnf(float, int);
427 IMPORT_C float truncf(float);
429 IMPORT_C float fdimf(float, float);
430 IMPORT_C float fmaf(float, float, float);
431 IMPORT_C float fmaxf(float, float) __pure2;
432 IMPORT_C float fminf(float, float) __pure2;
436 * float versions of BSD math library entry points
440 #ifdef __SYMBIAN_COMPILE_UNUSED__
441 float dremf(float, float);
444 IMPORT_C int finitef(float) __pure2;
445 IMPORT_C float gammaf(float);
446 IMPORT_C float j0f(float);
447 IMPORT_C float j1f(float);
448 IMPORT_C float jnf(int, float);
449 IMPORT_C float scalbf(float, float);
450 IMPORT_C float y0f(float);
451 IMPORT_C float y1f(float);
452 IMPORT_C float ynf(int, float);
455 * Float versions of reentrant version of gamma & lgamma; passes
456 * signgam back by reference as the second argument; user must
457 * allocate space for signgam.
459 IMPORT_C float lgammaf_r(float, int *);
462 * float version of IEEE Test Vector
464 IMPORT_C float significandf(float);
465 #endif /* __BSD_VISIBLE */
468 * long double versions of ISO/POSIX math functions
470 #if __ISO_C_VISIBLE >= 1999
472 long double acoshl(long double);
473 long double acosl(long double);
474 long double asinhl(long double);
475 long double asinl(long double);
476 long double atan2l(long double, long double);
477 long double atanhl(long double);
478 long double atanl(long double);
479 long double cbrtl(long double);
481 #ifndef __SYMBIAN32__
482 long double ceill(long double);
483 #endif //__SYMBIAN32__
484 IMPORT_C long double copysignl(long double, long double) __pure2;
486 long double coshl(long double);
487 long double cosl(long double);
488 long double erfcl(long double);
489 long double erfl(long double);
490 long double exp2l(long double);
491 long double expl(long double);
492 long double expm1l(long double);
494 IMPORT_C long double fabsl(long double) __pure2;
495 IMPORT_C long double fdiml(long double, long double);
496 #ifndef __SYMBIAN32__
497 long double floorl(long double);
498 long double fmal(long double, long double, long double);
499 #endif //__SYMBIAN32__
500 IMPORT_C long double fmaxl(long double, long double) __pure2;
501 #ifndef __SYMBIAN32__
502 long double fminl(long double, long double) __pure2;
503 #endif //__SYMBIAN32__
505 long double fmodl(long double, long double);
507 #ifndef __SYMBIAN32__
508 long double frexpl(long double value, int *); /* fundamentally !__pure2 */
509 #endif //__SYMBIAN32__
511 long double hypotl(long double, long double);
513 IMPORT_C int ilogbl(long double) __pure2;
514 #ifndef __SYMBIAN32__
515 long double ldexpl(long double, int);
516 #endif //__SYMBIAN32__
518 long double lgammal(long double);
519 long long llrintl(long double);
521 #ifndef __SYMBIAN32__
522 long long llroundl(long double);
523 #endif //__SYMBIAN32__
525 long double log10l(long double);
526 long double log1pl(long double);
527 long double log2l(long double);
528 long double logbl(long double);
529 long double logl(long double);
530 long lrintl(long double);
532 #ifndef __SYMBIAN32__
533 long lroundl(long double);
534 #endif //__SYMBIAN32__
536 long double modfl(long double, long double *); /* fundamentally !__pure2 */
537 long double nanl(const char *) __pure2;
538 long double nearbyintl(long double);
540 #ifndef __SYMBIAN32__
541 long double nextafterl(long double, long double);
542 double nexttoward(double, long double);
543 #endif //__SYMBIAN32__
544 IMPORT_C float nexttowardf(float, long double);
545 #ifndef __SYMBIAN32__
546 long double nexttowardl(long double, long double);
547 #endif //__SYMBIAN32__
549 long double powl(long double, long double);
550 long double remainderl(long double, long double);
551 long double remquol(long double, long double, int *);
552 long double rintl(long double);
554 #ifndef __SYMBIAN32__
555 long double roundl(long double);
556 #endif //__SYMBIAN32__
557 IMPORT_C long double scalblnl(long double, long);
558 #ifndef __SYMBIAN32__
559 long double scalbnl(long double, int);
560 #endif //__SYMBIAN32__
562 long double sinhl(long double);
563 long double sinl(long double);
564 long double sqrtl(long double);
565 long double tanhl(long double);
566 long double tanl(long double);
568 IMPORT_C long double truncl(long double);
570 #endif /* __ISO_C_VISIBLE >= 1999 */
573 #endif /* !_MATH_H_ */