Patch Ping: Double.parseDouble cannot handle NaN, Infinity or-Infinity
Bryce McKinlay
mckinlay@redhat.com
Fri Apr 1 18:30:00 GMT 2005
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
More information about the Java-patches
mailing list