You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Heinrich Bohne (JIRA)" <ji...@apache.org> on 2019/07/20 00:00:36 UTC
[jira] [Created] (NUMBERS-132) ArithmeticUtils.gcd(int, int) can be
simplified by performing the gcd algorithm on negative numbers
Heinrich Bohne created NUMBERS-132:
--------------------------------------
Summary: ArithmeticUtils.gcd(int, int) can be simplified by performing the gcd algorithm on negative numbers
Key: NUMBERS-132
URL: https://issues.apache.org/jira/browse/NUMBERS-132
Project: Commons Numbers
Issue Type: Improvement
Components: core
Affects Versions: 1.0
Reporter: Heinrich Bohne
The method {{ArithmeticUtils.gcd(int, int)}} currently handles the special case of the non-negatable {{Integer.MIN_VALUE}} by converting the arguments to {{long}}s 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.
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)