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: Bryce McKinlay <mckinlay at redhat dot com>
- To: Mark Anderson <mark at panonet dot net>
- Cc: java-patches at gcc dot gnu dot org, tromey at redhat dot com, Andrew Haley <aph at redhat dot com>
- Date: Fri, 1 Apr 2005 13:30:36 -0500
- 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>
On 1-Apr-05, at 8:53 AM, Mark Anderson wrote:
OK, here is the final patch. I have went Tom's way to avoid having to
make any other changes.
*** java/lang/natDouble.cc.orig Fri Mar 4 12:35:22 2005
--- java/lang/natDouble.cc Fri Apr 1 14:26:32 2005
*************** java::lang::Double::parseDouble(jstring
*** 193,198 ****
--- 193,208 ----
double val = _strtod_r (&reent, data, &endptr);
if (endptr == data + blength)
return val;
+ else
+ {
+ // check for NaN, Infinity & -Infinity
+ if (str->equals(JvNewStringLatin1("NaN", strlen("NaN"))))
+ return NaN;
+ else if (str->equals(JvNewStringLatin1("Infinity",
strlen("Infinity"))))
+ return POSITIVE_INFINITY;
+ else if (str->equals(JvNewStringLatin1("-Infinity",
strlen("-Infinity"))))
+ return NEGATIVE_INFINITY;
+ }
}
throw new NumberFormatException(str);
}
I'm not sure that this is exactly what Tom was proposing. Why not use
strcmp() on "data" instead, to avoid the String allocations?
Regards
Bryce