gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r707773546



##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
         return gcd(b, a % b);
     }
 
+    /**
+     * Negates the value of the RationalNumber. If the numerator of this
+     * instance has its high-order bit set, then its value is too large
+     * to be treated as a Java 32-bit signed integer.  In such a case, the
+     * only way that a RationalNumber instance can be negated is to
+     * sacrifice one bit of precision by dividing both the numerator and
+     * the denominator by 2. However, if that computation would result

Review comment:
       done

##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
         return gcd(b, a % b);
     }
 
+    /**
+     * Negates the value of the RationalNumber. If the numerator of this
+     * instance has its high-order bit set, then its value is too large
+     * to be treated as a Java 32-bit signed integer.  In such a case, the
+     * only way that a RationalNumber instance can be negated is to
+     * sacrifice one bit of precision by dividing both the numerator and
+     * the denominator by 2. However, if that computation would result
+     * in a zero denominator, then the value cannot be negated and an
+     * exception is thrown.
+     * @return a valid instance with a negated value.
+     */
     public RationalNumber negate() {
-        return new RationalNumber(-numerator, divisor);
+        long n = numerator;
+        long d = divisor;
+        if (unsignedType) {
+            // An instance of an unsigned type can be negated if and only if
+            // its high-order bit (the sign bit) is clear. If the bit is set,
+            // it is necessary to adjust the

Review comment:
       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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to