This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch Ping: Double.parseDouble cannot handle NaN, Infinity or-Infinity
- From: Tom Tromey <tromey at redhat dot com>
- To: Bryce McKinlay <mckinlay at redhat dot com>
- Cc: Mark Anderson <mark at panonet dot net>, java-patches at gcc dot gnu dot org, Andrew Haley <aph at redhat dot com>
- Date: 01 Apr 2005 18:17:09 -0700
- Subject: Re: Patch Ping: Double.parseDouble cannot handle NaN, Infinity or-Infinity
- References: <200503171459.54699.mark@panonet.net><m31x9x55d2.fsf@localhost.localdomain> <424B00E4.9080805@redhat.com><200504011453.30727.mark@panonet.net><fe965c82f9725875b6202a63b55f47e9@redhat.com>
- Reply-to: tromey at redhat dot com
>>>>> "Bryce" == Bryce McKinlay <mckinlay@redhat.com> writes:
>> OK, here is the final patch. I have went Tom's way to avoid having
>> to make any other changes.
Bryce> I'm not sure that this is exactly what Tom was proposing. Why
Bryce> not use strcmp() on "data" instead, to avoid the String
Bryce> allocations?
Yeah.
I'm checking in the appended to the trunk and the 4.0 branch. This
fixes the Mauve failures in this area. It is a little goofy in that
it checks against strings with '+' and '-' included.
Tom
Index: ChangeLog
from Mark Anderson <mark@panonet.net>
* java/lang/natDouble.cc (parseDouble): Handle NaN, Infinity and
-Infinity as parameters.
Index: java/lang/natDouble.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natDouble.cc,v
retrieving revision 1.18
diff -u -r1.18 natDouble.cc
--- java/lang/natDouble.cc 26 Nov 2003 18:02:34 -0000 1.18
+++ java/lang/natDouble.cc 2 Apr 2005 01:16:07 -0000
@@ -1,6 +1,6 @@
// natDouble.cc - Implementation of java.lang.Double native methods.
-/* Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation
This file is part of libgcj.
@@ -167,11 +167,15 @@
length--;
// The String could end with a f/F/d/D which is valid but we don't need.
+ bool saw_trailer = false;
if (length > 0)
{
jchar last = str->charAt(length-1);
if (last == 'f' || last == 'F' || last == 'd' || last == 'D')
- length--;
+ {
+ length--;
+ saw_trailer = true;
+ }
}
jsize start = 0;
@@ -186,6 +190,17 @@
jsize blength = _Jv_GetStringUTFRegion (str, start, length, data);
data[blength] = 0;
+ if (! saw_trailer)
+ {
+ if (! strcmp (data, "NaN") || ! strcmp (data, "+NaN")
+ || ! strcmp (data, "-NaN"))
+ return NaN;
+ else if (! strcmp (data, "Infinity") || ! strcmp (data, "+Infinity"))
+ return POSITIVE_INFINITY;
+ else if (! strcmp (data, "-Infinity"))
+ return NEGATIVE_INFINITY;
+ }
+
struct _Jv_reent reent;
memset (&reent, 0, sizeof reent);