Index: ChangeLog =================================================================== RCS file: /cvs/src/src/newlib/ChangeLog,v retrieving revision 1.1354 diff -p -u -r1.1354 ChangeLog --- ChangeLog 14 May 2009 20:16:21 -0000 1.1354 +++ ChangeLog 15 May 2009 00:10:07 -0000 @@ -1,3 +1,20 @@ +2009-05-14 Craig Howland + + * configure.in: Add configuration test for long double type existing + and set flag _HAVE_LONG_DOUBLE if true. Fix INIT_ARRAY (.init_array) + and _LDBL_EQ_DBL tests to not link so that will work with + cross-compilers. + * configure: Regenerated. + * newlib.hin: Add _HAVE_LONG_DOUBLE flag. + * libc/include/math.h: Change non-builtin defines for HUGE_VAL, + HUGE_VALF, and HUGE_VALL to be constant expressions. Add definitions + for the non-builtin case for INFINITY and NAN. Gate HUGE_VALL and + union __ldmath definitions with (new) _HAVE_LONG_DOUBLE. + *libm/common/s_infconst.c: Change definitions to use values from + float.h instead of non-so-portable integer forms. Mark as being + deprecated (because now removed from math.h, are not used anywhere + in Newlib, itself). + 2009-05-14 Corinna Vinschen * libc/ctype/local.h (JP_JIS, JP_SJIS, JP_EUCJP): Move definition Index: configure.in =================================================================== RCS file: /cvs/src/src/newlib/configure.in,v retrieving revision 1.40 diff -p -u -r1.40 configure.in --- configure.in 24 Apr 2009 22:49:54 -0000 1.40 +++ configure.in 15 May 2009 00:10:07 -0000 @@ -378,8 +378,8 @@ int __start (void) { return 0; } int foo (void) { return 1; } int (*fp) (void) __attribute__ ((section (".init_array"))) = foo; EOF -if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest conftest.c - -static -nostartfiles -nostdlib 1>&AS_MESSAGE_LOG_FD]) +if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c -o conftest conftest.c + 1>&AS_MESSAGE_LOG_FD]) then if ${READELF} -S conftest | grep -e INIT_ARRAY > /dev/null; then libc_cv_initfinit_array=yes @@ -395,7 +395,41 @@ if test $libc_cv_initfinit_array = yes; AC_DEFINE_UNQUOTED(HAVE_INITFINI_ARRAY) fi -AC_CACHE_CHECK(long double equals double, +dnl Autoconf 2.59 doesn't support the AC_TYPE_LONG_DOUBLE macro. Instead of: +dnl AC_TYPE_LONG_DOUBLE +dnl AM_CONDITIONAL(HAVE_LONG_DOUBLE, test x"$ac_cv_type_long_double" = x"yes") +dnl we specify our own long double test. +dnl Additionally, ac_cv_objext is broken so that AC_COMPILE_IFELSE cannot be +dnl used, so use AC_TRY_COMMAND instead. +AC_CACHE_CHECK(whether long double type exists, + acnewlib_cv_type_long_double, [dnl +cat > conftest.c < +#if defined(LDBL_MANT_DIG) + #define _HAVE_LONG_DOUBLE + #else + #error "LDBL != DBL" +#endif +long double test() { +long double ld = 0.0L; +return ld; +} +EOF +if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c + 1>&AS_MESSAGE_LOG_FD]) +then + acnewlib_cv_type_long_double=yes; +else + acnewlib_cv_type_long_double=no; +fi +rm -f conftest*]) +if test $acnewlib_cv_type_long_double = yes; then + AC_DEFINE_UNQUOTED(_HAVE_LONG_DOUBLE) +fi +AM_CONDITIONAL(HAVE_LONG_DOUBLE, test x"$acnewlib_cv_type_long_double" = x"yes") + +AC_CACHE_CHECK(whether long double equals double, newlib_ldbl_eq_dbl, [dnl cat > conftest.c < @@ -406,8 +440,8 @@ cat > conftest.c <&AS_MESSAGE_LOG_FD]) +if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c + 1>&AS_MESSAGE_LOG_FD]) then newlib_ldbl_eq_dbl=yes; else Index: newlib.hin =================================================================== RCS file: /cvs/src/src/newlib/newlib.hin,v retrieving revision 1.18 diff -p -u -r1.18 newlib.hin --- newlib.hin 24 Apr 2009 22:49:54 -0000 1.18 +++ newlib.hin 15 May 2009 00:10:07 -0000 @@ -46,6 +46,9 @@ functions. */ #undef _ATEXIT_DYNAMIC_ALLOC +/* True if long double supported. */ +#undef _HAVE_LONG_DOUBLE + /* True if long double supported and it is equal to double. */ #undef _LDBL_EQ_DBL Index: libc/include/math.h =================================================================== RCS file: /cvs/src/src/newlib/libc/include/math.h,v retrieving revision 1.40 diff -p -u -r1.40 math.h --- libc/include/math.h 24 Apr 2009 22:49:55 -0000 1.40 +++ libc/include/math.h 15 May 2009 00:10:07 -0000 @@ -8,23 +8,28 @@ _BEGIN_STD_C +/* __dmath, __fmath, and __ldmath are only here for backwards compatibility + * in case any code used them. They are no longer used by Newlib, itself, + * other than legacy. */ union __dmath { - __ULong i[2]; double d; + __ULong i[2]; }; union __fmath { - __ULong i[1]; float f; + __ULong i[1]; }; +#if defined(_HAVE_LONG_DOUBLE) union __ldmath { + long double ld; __ULong i[4]; - _LONG_DOUBLE ld; }; +#endif /* Natural log of 2 */ #define _M_LOG2_E 0.693147180559945309417 @@ -57,24 +62,45 @@ union __ldmath #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 - globals. */ + /* No builtins. Use fixed defines instead. (All 3 HUGE plus the INFINITY + * and NAN macros are required to be constant expressions. Using a variable-- + * even a static const--does not meet this requirement, as it cannot be + * evaluated at translation time.) + * The infinities are done using numbers that are far in excess of + * something that would be expected to be encountered in a floating-point + * implementation. (A more certain way uses values from float.h, but that is + * avoided because system includes are not supposed to include each other.) + * This method might produce warnings from some compilers. (It does in + * newer GCCs, but not for ones that would hit this #else.) If this happens, + * please report details to the Newlib mailing list. */ #ifndef HUGE_VAL - extern __IMPORT const union __dmath __infinity[]; - #define HUGE_VAL (__infinity[0].d) + #define HUGE_VAL (1.0e999999999) #endif #ifndef HUGE_VALF - extern __IMPORT const union __fmath __infinityf[]; - #define HUGE_VALF (__infinityf[0].f) + #define HUGE_VALF (1.0e999999999F) + #endif + + #if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE) + #define HUGE_VALL (1.0e999999999L) + #endif + + #if !defined(INFINITY) + #define INFINITY (HUGE_VALF) #endif - #ifndef HUGE_VALL - extern __IMPORT const union __ldmath __infinityld[]; - #define HUGE_VALL (__infinityld[0].ld) + #if !defined(NAN) + #if defined(__GNUC__) && defined(__cplusplus) + /* Exception: older g++ versions warn about the divide by 0 used in the + * normal case (even though older gccs do not). This trick suppresses the + * warning, but causes errors for plain gcc, so is only used in the one + * special case. */ + static const union { __ULong __i[1]; float __d; } __Nanf = {0x7FC00000}; + #define NAN (__Nanf.__d) + #else + #define NAN (0.0F/0.0F) + #endif #endif #endif /* !gcc >= 3.3 */ Index: libm/common/s_infconst.c =================================================================== RCS file: /cvs/src/src/newlib/libm/common/s_infconst.c,v retrieving revision 1.1 diff -p -u -r1.1 s_infconst.c --- libm/common/s_infconst.c 14 Oct 2005 21:11:39 -0000 1.1 +++ libm/common/s_infconst.c 15 May 2009 00:10:07 -0000 @@ -3,38 +3,19 @@ */ #include -#include "fdlibm.h" +#include +/* These should never actually be used any longer, as their use in math.h was + * removed, but they are kept here in case a user was pointing to them. + * FIXME: deprecate these identifiers and then delete them. */ + /* Float version of infinity. */ -const union __fmath __infinityf[1] = {{{0x7f800000}}}; +const union __fmath __infinityf[1] = { { FLT_MAX+FLT_MAX } }; /* Double version of infinity. */ -#ifndef _DOUBLE_IS_32BITS - #ifdef __IEEE_BIG_ENDIAN - const union __dmath __infinity[1] = {{{0x7ff00000, 0}}}; - #else - const union __dmath __infinity[1] = {{{0, 0x7ff00000}}}; - #endif -#else /* defined (_DOUBLE_IS_32BITS) */ - const union __dmath __infinity[1] = {{{0x7f800000, 0}}}; -#endif /* defined (_DOUBLE_IS_32BITS) */ +const union __dmath __infinity[1] = { { DBL_MAX+DBL_MAX } }; /* Long double version of infinity. */ -#ifdef __IEEE_BIG_ENDIAN - #if LDBL_MANT_DIG == 24 - const union __ldmath __infinityld[1] = {{{0x7f800000, 0, 0, 0}}}; - #elif LDBL_MANT_DIG == 53 - const union __ldmath __infinityld[1] = {{{0x7ff00000, 0, 0, 0}}}; - #else - const union __ldmath __infinityld[1] = {{{0x7fff0000, 0, 0, 0}}}; - #endif /* LDBL_MANT_DIG size */ -#else /* __IEEE_LITTLE_ENDIAN */ - #if LDBL_MANT_DIG == 24 - const union __ldmath __infinityld[1] = {{{0x7f800000, 0, 0, 0}}}; - #elif LDBL_MANT_DIG == 53 - const union __ldmath __infinityld[1] = {{{0, 0x7ff00000, 0, 0}}}; - #else - const union __ldmath __infinityld[1] = {{{0, 0x80000000, 0x00007fff, 0}}}; - #endif /* LDBL_MANT_DIG size */ -#endif /* __IEEE_LITTLE_ENDIAN */ - +#if defined(_HAVE_LONG_DOUBLE) +const union __ldmath __infinityld[1] = { { LDBL_MAX+LDBL_MAX } }; +#endif