This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] do_get of floats vs underflow


Hi again,

to be clear, I just finished testing the below on x86_64-linux, both gnu and generic locale models.

Paolo.

////////////////////
2007-04-07  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/31117
	* config/locale/gnu/c_locale.cc (__convert_to_v): Do not use errno,
	just check that the value is finite.
	* config/locale/generic/c_locale.cc (__convert_to_v): Likewise.
Index: config/locale/gnu/c_locale.cc
===================================================================
--- config/locale/gnu/c_locale.cc	(revision 123617)
+++ config/locale/gnu/c_locale.cc	(working copy)
@@ -1,6 +1,6 @@
 // Wrapper for underlying C-language localization -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -34,7 +34,6 @@
 
 // Written by Benjamin Kosnik <bkoz@redhat.com>
 
-#include <cerrno>  // For errno
 #include <locale>
 #include <stdexcept>
 #include <langinfo.h>
@@ -48,9 +47,9 @@
 		   const __c_locale& __cloc)
     {
       char* __sanity;
-      errno = 0;
       float __f = __strtof_l(__s, &__sanity, __cloc);
-      if (__sanity != __s && errno != ERANGE)
+      if (__sanity != __s && __f != __builtin_huge_valf()
+	  && __f != -__builtin_huge_valf())
 	__v = __f;
       else
 	__err |= ios_base::failbit;
@@ -62,9 +61,9 @@
 		   const __c_locale& __cloc)
     {
       char* __sanity;
-      errno = 0;
       double __d = __strtod_l(__s, &__sanity, __cloc);
-      if (__sanity != __s && errno != ERANGE)
+      if (__sanity != __s && __d != __builtin_huge_val()
+	  && __d != -__builtin_huge_val())
 	__v = __d;
       else
 	__err |= ios_base::failbit;
@@ -76,7 +75,6 @@
 		   const __c_locale& __cloc)
     {
       char* __sanity;
-      errno = 0;
 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
       // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
       // glibc versions.
@@ -84,7 +82,8 @@
 #else
       long double __ld = __strtold_l(__s, &__sanity, __cloc);
 #endif
-      if (__sanity != __s && errno != ERANGE)
+      if (__sanity != __s && __ld != __builtin_huge_vall()
+	  && __ld != -__builtin_huge_vall())
 	__v = __ld;
       else
 	__err |= ios_base::failbit;
Index: config/locale/generic/c_locale.cc
===================================================================
--- config/locale/generic/c_locale.cc	(revision 123617)
+++ config/locale/generic/c_locale.cc	(working copy)
@@ -1,6 +1,6 @@
 // Wrapper for underlying C-language localization -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -34,7 +34,6 @@
 
 // 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>
@@ -52,7 +51,6 @@
 		   const __c_locale&) 	      
     {
       // Assumes __s formatted for "C" locale.
-      errno = 0;
       char* __old = strdup(setlocale(LC_ALL, NULL));
       setlocale(LC_ALL, "C");
       char* __sanity;
@@ -63,19 +61,20 @@
       float __f = static_cast<float>(__d);
 #ifdef _GLIBCXX_HAVE_FINITEF
       if (!finitef (__f))
-	errno = ERANGE;
+	__f = __builtin_huge_valf();
 #elif defined (_GLIBCXX_HAVE_FINITE)
       if (!finite (static_cast<double> (__f)))
-	errno = ERANGE;
+	__f = __builtin_huge_valf();
 #elif defined (_GLIBCXX_HAVE_ISINF)
       if (isinf (static_cast<double> (__f)))
-	errno = ERANGE;
+	__f = __builtin_huge_valf();
 #else
       if (fabs(__d) > numeric_limits<float>::max())
-	errno = ERANGE;
+	__f = __builtin_huge_valf();
 #endif
 #endif
-      if (__sanity != __s && errno != ERANGE)
+      if (__sanity != __s && __f != __builtin_huge_valf()
+	  && __f != -__builtin_huge_valf())
 	__v = __f;
       else
 	__err |= ios_base::failbit;
@@ -89,12 +88,12 @@
 		   const __c_locale&) 
     {
       // Assumes __s formatted for "C" locale.
-      errno = 0;
       char* __old = strdup(setlocale(LC_ALL, NULL));
       setlocale(LC_ALL, "C");
       char* __sanity;
       double __d = strtod(__s, &__sanity);
-      if (__sanity != __s && errno != ERANGE)
+      if (__sanity != __s && __d != __builtin_huge_val()
+	  && __d != -__builtin_huge_val())
 	__v = __d;
       else
 	__err |= ios_base::failbit;
@@ -108,20 +107,21 @@
 		   ios_base::iostate& __err, const __c_locale&) 
     {
       // Assumes __s formatted for "C" locale.
-      errno = 0;
       char* __old = strdup(setlocale(LC_ALL, NULL));
       setlocale(LC_ALL, "C");
 #if defined(_GLIBCXX_HAVE_STRTOLD)
       char* __sanity;
       long double __ld = strtold(__s, &__sanity);
-      if (__sanity != __s && errno != ERANGE)
+      if (__sanity != __s && __ld != __builtin_huge_vall()
+	  && __ld != -__builtin_huge_vall())
 	__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()
-	  && errno != ERANGE)
+	  && __ld != __builtin_huge_vall()
+	  && __ld != -__builtin_huge_vall())
 	__v = __ld;
 #endif
       else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]