Bug in Long.parseUnsignedLong

Brian Burkhalter brian.burkhalter at oracle.com
Tue Dec 24 00:58:15 UTC 2013


It looks like this could be rearranged to

long result = first * radix + second;
int guard = radix * (int) (first >>> 57);
if (guard >= 128 || (result >= 0 && guard >= 128 - Character.MAX_RADIX)) {
…

provided reasonable comments were added. I understand the first part of this conditional, guard >= 128, but the second part eludes me. Would you please explain this part.

BTW this works for the test case in question, of course.

On Dec 21, 2013, at 2:04 AM, Dmitry Nadezhin wrote:

> I can weaken the question:
> Is there a reason to prefer extra int multiplication to the cache ?
> 
> long result = first * radix + second;
> final int GUARD_BIT = 7;
> int guard = radix * (int) (first >>> (Long.SIZE - GUARD_BIT));
> if (guard >= (1 << GUARD_BIT) - Character.MAX_RADIX
>     && (guard >= (1 << GUARD_BIT) || result >= 0)) {
>  . . .




More information about the core-libs-dev mailing list