This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[trunk] Mini merge from lto branch: Handle NaNs and Inf in real_from_string (3/5)
- From: Diego Novillo <dnovillo at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 May 2008 09:52:31 -0400
- Subject: [trunk] Mini merge from lto branch: Handle NaNs and Inf in real_from_string (3/5)
This fixes handling of NaNs and Inf when reading them back from a string.
Bootstrapped and tested on x86_64. Applied to trunk.
Diego.
2008-05-16 Doug Kwan <dougkwan@google.com>
* real.c (real_to_decimal, real_to_hexadecimal): Distinguish
QNaN & SNaN.
(real_from_string): Handle NaNs and Inf as approriate.
2008-05-16 Doug Kwan <dougkwan@google.com>
* real.c (real_to_decimal, real_to_hexadecimal): Distinguish
QNaN & SNaN.
(real_from_string): Handle NaNs and Inf as approriate.
Index: real.c
===================================================================
--- real.c (revision 135361)
+++ real.c (working copy)
@@ -1471,7 +1471,8 @@ real_to_decimal (char *str, const REAL_V
return;
case rvc_nan:
/* ??? Print the significand as well, if not canonical? */
- strcpy (str, (r.sign ? "-NaN" : "+NaN"));
+ sprintf (str, "%c%cNaN", (r_orig->sign ? '-' : '+'),
+ (r_orig->signalling ? 'S' : 'Q'));
return;
default:
gcc_unreachable ();
@@ -1743,7 +1744,8 @@ real_to_hexadecimal (char *str, const RE
return;
case rvc_nan:
/* ??? Print the significand as well, if not canonical? */
- strcpy (str, (r->sign ? "-NaN" : "+NaN"));
+ sprintf (str, "%c%cNaN", (r->sign ? '-' : '+'),
+ (r->signalling ? 'S' : 'Q'));
return;
default:
gcc_unreachable ();
@@ -1812,6 +1814,22 @@ real_from_string (REAL_VALUE_TYPE *r, co
else if (*str == '+')
str++;
+ if (!strncmp (str, "QNaN", 4))
+ {
+ get_canonical_qnan (r, sign);
+ return 0;
+ }
+ else if (!strncmp (str, "SNaN", 4))
+ {
+ get_canonical_snan (r, sign);
+ return 0;
+ }
+ else if (!strncmp (str, "Inf", 3))
+ {
+ get_inf (r, sign);
+ return 0;
+ }
+
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
{
/* Hexadecimal floating point. */