[ https://issues.apache.org/jira/browse/NUMBERS-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Heinrich Bohne resolved NUMBERS-132. ------------------------------------ Resolution: Fixed Fix Version/s: 1.0 > 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 > Priority: Minor > Fix For: 1.0 > > Time Spent: 0.5h > Remaining Estimate: 0h > > 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)