On Tue, 10 May 2022 04:42:19 GMT, Joe Darcy <da...@openjdk.org> wrote:
>> Raffaello Giulietti has updated the pull request with a new target base due >> to a merge or a rebase. The incremental webrev excludes the unrelated >> changes brought in by the merge/rebase. The pull request contains four >> additional commits since the last revision: >> >> - 8279986: methods Math::asXExact for safely checked primitive casts >> >> Merge branch 'master' into JDK-8279986 >> - 8279986: methods Math::asXExact for safely checked primitive casts >> >> Merge branch 'master' into JDK-8279986 >> - 8279986: methods Math::asXExact for safely checked primitive casts >> - 8279986: methods Math::asXExact for safely checked primitive casts > > src/java.base/share/classes/java/lang/Math.java line 1578: > >> 1576: */ >> 1577: @ForceInline >> 1578: public static long toUnsignedIntExact(long value) { > > Existing methods like Integer.parseUnsignedInt interpret the negative int > values as positive values larger than MAX_INT. So if an int is not going to > be returned here, I suggest a name like "toUnsignedIntRangeExact". Returning a `long` is probably less error prone. When the result is to be used in an `int` context, one simply has to add a `(int)` cast, as mandated by language, compiler and IDE. On the other hand, if this method were to return an `int`, when using the result in a `long` context one has to remember masking it with `0xFFFF_FFFFL`. AFAIK, there's no compiler or IDE support for this. The name `toUnsignedIntRangeExact` is certainly better. ------------- PR: https://git.openjdk.java.net/jdk/pull/8548