I have suggestion regarding what to do with the special cases Integer.MIN_VALUE and Long.MIN_VALUE in the methods from ArithmeticUtils that calculate the greatest common divisor of two ints or longs. Currently, these methods throw an ArithmeticException if the GCD of the arguments is 2^31 or 2^63, respectively. However, what if, instead, these methods simply returned -2^31 and -2^63 in these special cases? I think this would have several advantages:
- By returning -2^31 and -2^63, the methods will /always/ return a unique "representation" of the GCD, even if this representation may, under one predictable circumstance, not be the GCD itself but its additive inverse. An exception, on the other hand, implies that the GCD cannot be represented and is therefore less useful. - Throwing an exception is more expensive than returning -2^31 or -2^63. - If the distinction between the GCD and its additive inverse matters to the caller, the caller would have to handle the case of Integer.MIN_VALUE or Long.MIN_VALUE separately in any case, whether the method throws an exception or returns -2^31 or -2^63. There may, however, be cases, where this distinction does not matter, for example, if the caller just wants to check if two numbers are coprime or not (in fact, there already is such a case, namely in the constructor Fraction(int, int) from the fraction module). An exception would then force the caller to handle the case separately, whereas this would not be necessary if the method returned -2^31 or -2^63. - The practice of returning Integer.MIN_VALUE and Long.MIN_VALUE in place of 2^31 and 2^63 is precedented in the Java library itself: Math.abs(int) and Math.abs(long) return the respective min values if the argument is that min value, so a similar design in the gcd methods would be more consistent with the Java API than throwing an exception. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org