diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-06 09:51:26 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-06 09:51:26 +0000 |
commit | 13061e46fcfda5d309f35882450e523cb1ea0659 (patch) | |
tree | 12001ddc14268b69c7c3beec2eee94e07c80e779 /libstdc++-v3/config | |
parent | a3cbe8cc82b68c414ed912dd8d7e288251c06d06 (diff) | |
download | gcc-13061e46fcfda5d309f35882450e523cb1ea0659.tar.gz |
2007-05-06 Paolo Carlini <pcarlini@suse.de>
* config/locale/generic/c_locale.cc: Don't use __builtin_huge_val*
when __*_HAS_INFINITY__ is false.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@124470 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/config')
-rw-r--r-- | libstdc++-v3/config/locale/generic/c_locale.cc | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/libstdc++-v3/config/locale/generic/c_locale.cc b/libstdc++-v3/config/locale/generic/c_locale.cc index d1c66b6462d..ae1fa2899f5 100644 --- a/libstdc++-v3/config/locale/generic/c_locale.cc +++ b/libstdc++-v3/config/locale/generic/c_locale.cc @@ -34,6 +34,7 @@ // Written by Benjamin Kosnik <bkoz@redhat.com> +#include <cerrno> // For errno #include <cmath> // For isinf, finite, finitef, fabs #include <cstdlib> // For strof, strtold #include <locale> @@ -55,6 +56,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) char* __old = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C"); char* __sanity; + +#if !__FLT_HAS_INFINITY__ + errno = 0; +#endif + #if defined(_GLIBCXX_HAVE_STRTOF) float __f = strtof(__s, &__sanity); #else @@ -62,23 +68,29 @@ _GLIBCXX_BEGIN_NAMESPACE(std) float __f = static_cast<float>(__d); #ifdef _GLIBCXX_HAVE_FINITEF if (!finitef (__f)) - __f = __builtin_huge_valf(); + __s = __sanity; #elif defined (_GLIBCXX_HAVE_FINITE) if (!finite (static_cast<double> (__f))) - __f = __builtin_huge_valf(); + __s = __sanity; #elif defined (_GLIBCXX_HAVE_ISINF) if (isinf (static_cast<double> (__f))) - __f = __builtin_huge_valf(); + __s = __sanity; #else if (fabs(__d) > numeric_limits<float>::max()) - __f = __builtin_huge_valf(); + __s = __sanity; #endif #endif - if (__sanity != __s && __f != __builtin_huge_valf() - && __f != -__builtin_huge_valf()) + + if (__sanity != __s +#if !__FLT_HAS_INFINITY__ + && errno != ERANGE) +#else + && __f != __builtin_huge_valf() && __f != -__builtin_huge_valf()) +#endif __v = __f; else __err |= ios_base::failbit; + setlocale(LC_ALL, __old); free(__old); } @@ -92,12 +104,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) char* __old = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C"); char* __sanity; + +#if !__DBL_HAS_INFINITY__ + errno = 0; +#endif + double __d = strtod(__s, &__sanity); - if (__sanity != __s && __d != __builtin_huge_val() - && __d != -__builtin_huge_val()) + + if (__sanity != __s +#if !__DBL_HAS_INFINITY__ + && errno != ERANGE) +#else + && __d != __builtin_huge_val() && __d != -__builtin_huge_val()) +#endif __v = __d; else __err |= ios_base::failbit; + setlocale(LC_ALL, __old); free(__old); } @@ -110,23 +133,40 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Assumes __s formatted for "C" locale. char* __old = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C"); + +#if !__LDBL_HAS_INFINITY__ + errno = 0; +#endif + #if defined(_GLIBCXX_HAVE_STRTOLD) char* __sanity; long double __ld = strtold(__s, &__sanity); - if (__sanity != __s && __ld != __builtin_huge_vall() - && __ld != -__builtin_huge_vall()) + + if (__sanity != __s +#if !__LDBL_HAS_INFINITY__ + && errno != ERANGE) +#else + && __ld != __builtin_huge_vall() && __ld != -__builtin_huge_vall()) +#endif __v = __ld; + #else typedef char_traits<char>::int_type int_type; long double __ld; int __p = sscanf(__s, "%Lf", &__ld); + if (__p && static_cast<int_type>(__p) != char_traits<char>::eof() - && __ld != __builtin_huge_vall() - && __ld != -__builtin_huge_vall()) +#if !__LDBL_HAS_INFINITY__ + && errno != ERANGE) +#else + && __ld != __builtin_huge_vall() && __ld != -__builtin_huge_vall()) +#endif __v = __ld; + #endif else __err |= ios_base::failbit; + setlocale(LC_ALL, __old); free(__old); } |