XenoAmess commented on a change in pull request #83:
URL: https://github.com/apache/commons-numbers/pull/83#discussion_r476683956
##########
File path:
commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
##########
@@ -966,23 +968,46 @@ public BigFraction divide(final BigFraction value) {
*/
@Override
public BigFraction pow(final int exponent) {
+ if (exponent == 1) {
+ return this;
+ }
if (exponent == 0) {
return ONE;
}
if (isZero()) {
- return ZERO;
+ if (exponent < 0) {
+ throw new
ArithmeticException(STRING_THE_DENOMINATOR_MUST_NOT_BE_ZERO);
+ } else {
+ return ZERO;
+ }
+ }
+ if (exponent > 0) {
+ return new BigFraction(
+ ArithmeticUtils.pow(this.numerator, exponent),
+ ArithmeticUtils.pow(this.denominator, exponent)
+ );
+ }
+ if (exponent == -1) {
+ return this.reciprocal();
+ }
+ if (exponent == Integer.MIN_VALUE) {
+ // MIN_VALUE can't be negated
+ final int temp = exponent >> 1;
Review comment:
@aherbert OK, as it will be optimized by compiler anyway
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]