JDK 8 code review request for initial unsigned integer arithmetic library support
Ulf Zibis
Ulf.Zibis at gmx.de
Thu Jan 19 03:52:21 UTC 2012
Am 18.01.2012 03:54, schrieb Joe Darcy:
> I've posted a revised webrev at
>
> http://cr.openjdk.java.net/~darcy/4504839.2
Instead
<code>'\u0030'</code>
you can use
{@code '\u005Cu0030'}
Byte:
=====
459 public static int toUnsignedInt(byte x) {
460 return ((int) x) & 0xff;
461 }
This should be good enough (similar at Short, Integer):
459 public static int toUnsignedInt(byte x) {
460 return x & 0xff;
461 }
(This notation if regularly used in sun.nio.cs coders.)
missing:
public static short toUnsignedShort(byte x)
superfluous:
public static long toUnsignedInt(byte x)
public static long toUnsignedLong(byte x) (similar at Short)
one can use:
int i = toUnsignedShort(x)
long l = toUnsignedShort(x) (similar at Short)
Integer:
========
623 * <li>The value represented by the string is larger than the
624 * largest unsigned {@code int}, 2<sup>32</sup>-1.
If you format {@code int}, then you speak about the java type int, which is always signed, never
unsigned.
IMO you should better write 'unsigned 32-bit integer".
(similar at Long)
598 * Parses the string argument as an unsigned integer in the radix
599 * specified by the second argument.
IMHO, there should be a note about what happens on values above 2^31 - 1.
672 * Parses the string argument as an unsigned decimal integer. The
673 * characters in the string must all be decimal digits, except
Better, like lines 598ff, or contrariwise (similar at Long):
672 * Parses the string argument as an unsigned decimal integer.
673 *
674 * The characters in the string must all be decimal digits, except
Long:
=====
What about:
private static final BigInteger BEYOND_UNSIGNED_LONG = BigInteger.valueOf(1).shiftLeft(64);
private static BigInteger toUnsignedBigInteger(long i) {
BigInteger result = BigInteger.valueOf(i);
if (i < 0L)
result = result.add(BEYOND_UNSIGNED_LONG);
return result;
}
Instead
private static BigInteger toUnsignedBigInteger(long i)
at class BigInteger we more generally could have:
public static BigInteger unsignedValueOf(long i)
610 * Parses the string argument as an unsigned {@code long} in the
611 * radix specified by the second argument.
IMHO, there should be a note about what happens on values above 2^63 - 1.
-Ulf
More information about the core-libs-dev
mailing list