This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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: Patch Ping: Double.parseDouble cannot handle NaN, Infinity or-Infinity


>>>>> "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);
 


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