Interest in support for saturated casts?
Stephen Colebourne
jodastephen at gmail.com
Sat Jan 10 00:37:31 UTC 2009
Joseph D. Darcy wrote:
> One of the libraries enhancements I'd like to implement in JDK 7 is
> support for unsigned integer arithmetic, 4504839 "Java libraries
> should provide support for unsigned integer arithmetic" and related
> bugs. That would include methods to do conversions like
>
> Short.toUnsignedInt(myShort)
> Short.toUnsignedLong(myShort)
>
> Perhaps there could also be methods for saturating conversions,
>
> Integer.toSaturatedShort(int)
> etc.
>
> The presence of such standard methods would make it easier for HotSpot
> to intrinsify them on platforms with direct hardware support.
>
> -Joe
In a similar vein, the libraries could do with methods like:
Numbers.safeAdd(int, int)
Numbers.safeSubtract(int, int)
Numbers.safeMultiply(int, int)
Numbers.safeCompare(int, int)
which throw ArithmeticException rather than silently overflowing like
(int + int) and friends do. Weve had to develop these kinds of methods
for JSR-310.
Stephen
More information about the core-libs-dev
mailing list