[ 
https://issues.apache.org/jira/browse/NUMBERS-150?focusedWorklogId=474503&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-474503
 ]

ASF GitHub Bot logged work on NUMBERS-150:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Aug/20 20:21
            Start Date: 25/Aug/20 20:21
    Worklog Time Spent: 10m 
      Work Description: XenoAmess commented on a change in pull request #83:
URL: https://github.com/apache/commons-numbers/pull/83#discussion_r476713984



##########
File path: 
commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
##########
@@ -966,23 +966,39 @@ 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()) {
+            if (exponent < 0) {
+                throw new 
FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
+            }
             return ZERO;
         }
-
+        if (exponent > 0) {
+            return new BigFraction(this.numerator.pow(exponent),

Review comment:
       @aherbert done.

##########
File path: 
commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
##########
@@ -775,19 +775,31 @@ public Fraction divide(Fraction value) {
      */
     @Override
     public Fraction pow(final int exponent) {
+        if (exponent == 1) {
+            return this;
+        }
         if (exponent == 0) {
             return ONE;
         }
         if (isZero()) {
+            if (exponent < 0) {
+                throw new 
FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
+            }
             return ZERO;
         }
-
-        if (exponent < 0) {
-            return new Fraction(ArithmeticUtils.pow(denominator, -exponent),
-                                ArithmeticUtils.pow(numerator,   -exponent));
+        if (exponent > 0) {
+            return new Fraction(ArithmeticUtils.pow(this.numerator, exponent),

Review comment:
       @aherbert done.

##########
File path: 
commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
##########
@@ -775,19 +775,31 @@ public Fraction divide(Fraction value) {
      */
     @Override
     public Fraction pow(final int exponent) {
+        if (exponent == 1) {
+            return this;
+        }
         if (exponent == 0) {
             return ONE;
         }
         if (isZero()) {
+            if (exponent < 0) {
+                throw new 
FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
+            }
             return ZERO;
         }
-
-        if (exponent < 0) {
-            return new Fraction(ArithmeticUtils.pow(denominator, -exponent),
-                                ArithmeticUtils.pow(numerator,   -exponent));
+        if (exponent > 0) {
+            return new Fraction(ArithmeticUtils.pow(this.numerator, exponent),
+                    ArithmeticUtils.pow(this.denominator, exponent));
+        }
+        if (exponent == -1) {
+            return this.reciprocal();
+        }
+        if (exponent == Integer.MIN_VALUE) {
+            return new Fraction(ArithmeticUtils.pow(this.denominator, 
Integer.MAX_VALUE) * this.denominator,
+                    ArithmeticUtils.pow(this.numerator, Integer.MAX_VALUE) * 
this.numerator);
         }
-        return new Fraction(ArithmeticUtils.pow(numerator,   exponent),
-                            ArithmeticUtils.pow(denominator, exponent));
+        return new Fraction(ArithmeticUtils.pow(this.denominator, -exponent),
+                ArithmeticUtils.pow(this.numerator, -exponent));

Review comment:
       @aherbert done.




----------------------------------------------------------------
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 474503)
    Time Spent: 4h 10m  (was: 4h)

> Fraction.pow to correctly handle Integer.MIN_VALUE as the argument
> ------------------------------------------------------------------
>
>                 Key: NUMBERS-150
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-150
>             Project: Commons Numbers
>          Issue Type: Bug
>          Components: fraction
>            Reporter: Jin Xu
>            Priority: Major
>          Time Spent: 4h 10m
>  Remaining Estimate: 0h
>
> a bug was discovered by [NUMBERS-149].
> here is the fix pr.
> https://github.com/apache/commons-numbers/pull/83



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to