Description
The method ArithmeticUtils.gcd(int, int) currently handles the special case of the non-negatable Integer.MIN_VALUE by converting the arguments to longs if one of them is Integer.MIN_VALUE and performing two iterations of the regular euclidean algorithm before handing the resulting values over to a helper method that performs the binary gcd algorithm.
However, the tactic used by gcd(long, long) is much more elegant: It just converts positive arguments to their negative counterparts, thereby avoiding the risk of overflow completely without having to make exceptions for special cases and resorting to other data types.
The method gcd(int, int) would likely be much more compact if it also were to apply this technique.
Attachments
Issue Links
- links to