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


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


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