2007-05-16 Eric Blake <ebb9@byu.net>
+ * libc/include/math.h (INFINITY, NAN, FP_ILOGB0, FP_ILOGBNAN)
+ (MATH_ERRNO, MATH_ERREXCEPT, math_errhandling): Add macros
+ required by POSIX.
+ * libc/stdlib/ldtoa.c (USE_INFINITY): Rename from INFINITY, to
+ avoid clash with <math.h>.
+
* libc/stdlib/wctomb_r.c (_wctomb_r): Avoid gcc warnings on cygwin.
* libc/search/hash.c (__hash_open): Likewise.
-
#ifndef _MATH_H_
#define _MATH_H_
__ULong i[2];
double d;
};
-
+
union __fmath
{
__ULong i[1];
float f;
};
-
+
union __ldmath
{
__ULong i[4];
/* gcc >= 3.3 implicitly defines builtins for HUGE_VALx values. */
- #ifndef HUGE_VAL
- #define HUGE_VAL (__builtin_huge_val())
- #endif
+# ifndef HUGE_VAL
+# define HUGE_VAL (__builtin_huge_val())
+# endif
- #ifndef HUGE_VALF
- #define HUGE_VALF (__builtin_huge_valf())
- #endif
+# ifndef HUGE_VALF
+# define HUGE_VALF (__builtin_huge_valf())
+# endif
- #ifndef HUGE_VALL
- #define HUGE_VALL (__builtin_huge_vall())
- #endif
+# ifndef HUGE_VALL
+# define HUGE_VALL (__builtin_huge_vall())
+# endif
+
+# ifndef INFINITY
+# define INFINITY (__builtin_inff())
+# endif
+
+# ifndef NAN
+# define NAN (__builtin_nanf(""))
+# endif
#else /* !gcc >= 3.3 */
- /* No builtins. Use floating-point unions instead. Declare as an array
- without bounds so no matter what small data support a port and/or
- library has, the reference will be via the general method for accessing
+ /* No builtins. Use floating-point unions instead. Declare as an array
+ without bounds so no matter what small data support a port and/or
+ library has, the reference will be via the general method for accessing
globals. */
#ifndef HUGE_VAL
#define FP_SUBNORMAL 3
#define FP_NORMAL 4
+#ifndef FP_ILOGB0
+# define FP_ILOGB0 (-INT_MAX)
+#endif
+#ifndef FP_ILOGBNAN
+# define FP_ILOGBNAN INT_MAX
+#endif
+
+#ifndef MATH_ERRNO
+# define MATH_ERRNO 1
+#endif
+#ifndef MATH_ERREXCEPT
+# define MATH_ERREXCEPT 2
+#endif
+#ifndef math_errhandling
+# define math_errhandling MATH_ERRNO
+#endif
+
extern int __isinff (float x);
extern int __isinfd (double x);
extern int __isnanf (float x);
/* We have a problem when using C++ since `exception' is a reserved
name in C++. */
#ifdef __cplusplus
-struct __exception
+struct __exception
#else
-struct exception
+struct exception
#endif
{
int type;
#define M_SQRT1_2 0.70710678118654752440
#define M_LN2LO 1.9082149292705877000E-10
#define M_LN2HI 6.9314718036912381649E-1
-#define M_SQRT3 1.73205080756887719000
+#define M_SQRT3 1.73205080756887719000
#define M_IVLN10 0.43429448190325182765 /* 1 / log(10) */
#define M_LOG2_E 0.693147180559945309417
#define M_INVLN2 1.4426950408889633870E0 /* 1 / log(2) */
-
/* Extended precision arithmetic functions for long double I/O.
* This program has been placed in the public domain.
*/
*
* Exception flags are NOT fully supported.
*
- * Define INFINITY in mconf.h for support of infinity; otherwise a
+ * Define USE_INFINITY in mconf.h for support of infinity; otherwise a
* saturation arithmetic is implemented.
*
* Define NANS for support of Not-a-Number items; otherwise the
#define VOLATILE
#define NANS
-#define INFINITY
+#define USE_INFINITY
/* NaN's require infinity support. */
#ifdef NANS
#ifndef INFINITY
-#define INFINITY
+#define USE_INFINITY
#endif
#endif
{
register int i;
-#ifdef INFINITY
+#ifdef USE_INFINITY
for( i=0; i<NE-1; i++ )
*x++ = 0;
*x |= 32767;
/* get the exponent */
*q = *p--;
*q++ &= 0x7fff; /* delete the sign bit */
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( (*(q-1) & 0x7fff) == 0x7fff )
{
#ifdef NANS
*q-- = *p++ | 0x8000;
else
*q-- = *p++;
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( *(p-1) == 0x7fff )
{
#ifdef NANS
j = enormlz( s );
/* a blank significand could mean either zero or infinity. */
-#ifndef INFINITY
+#ifndef USE_INFINITY
if( j > NBITS )
{
ecleazs( s );
}
#endif
exp -= j;
-#ifndef INFINITY
+#ifndef USE_INFINITY
if( exp >= 32767L )
goto overf;
#else
s[NI-1] = 0;
if( exp >= 32767L )
{
-#ifndef INFINITY
+#ifndef USE_INFINITY
overf:
#endif
-#ifdef INFINITY
+#ifdef USE_INFINITY
s[1] = 32767;
for( i=2; i<NI-1; i++ )
s[i] = 0;
int i, lost, j, k;
long lt, lta, ltb;
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( eisinf(a) )
{
emov(a,c);
}
#endif
/* Infinity over anything else is infinity. */
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( eisinf(b) )
{
if( eisneg(a) ^ eisneg(b) )
}
#endif
/* Infinity times anything else is infinity. */
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( eisinf(a) || eisinf(b) )
{
if( eisneg(a) ^ eisneg(b) )
if( r & 0x8000 )
yy[0] = 0xffff;
r &= 0x7fff;
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( r == 0x7fff )
{
#ifdef NANS
return;
}
#endif
-#ifdef INFINITY
+#ifdef USE_INFINITY
/* Point to the exponent field. */
p = &yy[NE-1];
if( (*p & 0x7fff) == 0x7fff )
eneg(y);
return;
}
-#endif /* INFINITY */
+#endif /* USE_INFINITY */
p = yy;
q = y;
for( i=0; i<NE; i++ )
for( i=0; i<4; i++ )
*q++ = *p++;
#else
-#ifdef INFINITY
+#ifdef USE_INFINITY
#ifdef IBMPC
if (eiisinf (a))
{
return;
}
#endif /* IBMPC */
-#endif /* INFINITY */
+#endif /* USE_INFINITY */
for( i=0; i<4; i++ )
*q-- = *p++;
#endif
yy[0] = 0xffff;
yy[M] = (r & 0x0f) | 0x10;
r &= ~0x800f; /* strip sign and 4 significand bits */
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( r == 0x7ff0 )
{
#ifdef NANS
i = *p++;
if( i >= (unsigned int )2047 )
{ /* Saturate at largest number less than infinity. */
-#ifdef INFINITY
+#ifdef USE_INFINITY
*y |= 0x7ff0;
#ifdef IBMPC
*(--y) = 0;
*y++ = 0;
*y++ = 0;
#endif /* IBMPC */
-#else /* !INFINITY */
+#else /* !USE_INFINITY */
*y |= (unsigned short )0x7fef;
#ifdef IBMPC
*(--y) = 0xffff;
*y++ = 0xffff;
*y++ = 0xffff;
#endif
-#endif /* !INFINITY */
+#endif /* !USE_INFINITY */
return;
}
if( i == 0 )
yy[0] = 0xffff;
yy[M] = (r & 0x7f) | 0200;
r &= ~0x807f; /* strip sign and 7 significand bits */
-#ifdef INFINITY
+#ifdef USE_INFINITY
if( r == 0x7f80 )
{
#ifdef NANS
i = *p++;
if( i >= 255 )
{ /* Saturate at largest number less than infinity. */
-#ifdef INFINITY
+#ifdef USE_INFINITY
*y |= (unsigned short )0x7f80;
#ifdef IBMPC
*(--y) = 0;
++y;
*y = 0;
#endif
-#else /* !INFINITY */
+#else /* !USE_INFINITY */
*y |= (unsigned short )0x7f7f;
#ifdef IBMPC
*(--y) = 0xffff;
++y;
*y = 0xffff;
#endif
-#endif /* !INFINITY */
+#endif /* !USE_INFINITY */
return;
}
if( i == 0 )
for (i=0; i < n; i++)
*nan++ = *p++;
}
-
-
-
-