Hacker News new | ask | show | jobs
by morelisp 1326 days ago
The solution here is not really interesting except from a language design perspective. Go avoids this problem by having the maximum array length be int, but doing the math in uint. This won’t work in languages that lack uints (Java) or have maximum array sizes in uint (C/C++).
1 comments

Java lacks a distinct uint type, but (since Java 8) allows you to perform unsigned operations on a regular int, effectively treating it as a uint.

It doesn't help that almost nobody knows this, though.

At the point where you're writing `>>>` to, ironically, do proper arithmetic - you should probably write a correct version without a shift instead.