From: Ken Anderson <kanderson@bb...> - 2003-02-05 22:11:19
This is a reply i got from Guy Steele about a bug Jonathan Reese reported, and the problems i ran into trying to fix it.
I'm planning to rewrite our number reader one day and include the mail as a comment, but i thought it worth passing to the group because it may take me a while to get around to it. Though it might not be worth being more consistent about numbers than Java is, so maybe the current behavior is good enough.
>Date: Wed, 8 Jan 2003 14:03:48 -0500 (EST)
>From: Guy Steele - Sun Microsystems Labs <Guy.Steele@...>
>Reply-To: Guy Steele - Sun Microsystems Labs <Guy.Steele@...>
>Subject: Re: Converting octal and hex strings to numbers in java.
>To: Guy.Steele@..., kanderson@...
> X-Sender: kanderso@...
> Date: Mon, 30 Dec 2002 15:46:39 -0500
> To: Guy Steele - Sun Microsystems Labs <Guy.Steele@...>
> From: Ken Anderson <kanderson@...>
> Subject: Converting octal and hex strings to numbers in java.
> I hope you can answer this question easily.
> I was tracking down a problem the Jonathan Reese found in JScheme which will
>optionally read numbers in either Java or Scheme format.
> Reading the JVS spec,
> it says numbers like 0xDadaCafe are valid integer constants. however,
> Integer.parseInt("DadaCafe", 16) throws a NumberFormatException, as the
>enclosed program shows. I think Long.parseLong() has a similar problem.
> I presume this has to do with the sign of the number. Can you shed some
>light on this? Is there something else i can use to read such number?
>Unfortunately, the detailed description of Integer.ParseInt that
>appeared in JLS1 was not carried forward into JLS2, nor was it
>transferred to "The Java Class Libraries". That description
>makes clear that "overly large" hexadecimal numbers are not
>accepted by ParseInt, even though literals of that form are
>indeed accepted by the compiler.
>That may be regarded as a flat-out inconsistency in the language,
>but that's just the way it is, I'm afraid. ParseInt is not the
>right tool for parsing hexadecimal integer literals. You may have
>to roll yur own. Sorry about that.