You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/12 12:59:38 UTC
(commons-imaging) 15/22: Merge nested if clauses
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit 147555b561bc0f459b33b4db6bc102093e885a05
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 08:58:32 2024 -0400
Merge nested if clauses
---
.../commons/imaging/common/RationalNumber.java | 34 ++++++++++------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/apache/commons/imaging/common/RationalNumber.java b/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
index 32d67f67..cfdfba03 100644
--- a/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
+++ b/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
@@ -256,25 +256,23 @@ public class RationalNumber extends Number {
public RationalNumber negate() {
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,
- // the value will be too large to convert to a signed type.
- // In such a case it is necessary to adjust the numerator and denominator
- // by their greatest common divisor (gcd), if one exists.
- // If no non-zero common divisor exists, an exception is thrown.
+ // 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,
+ // the value will be too large to convert to a signed type.
+ // In such a case it is necessary to adjust the numerator and denominator
+ // by their greatest common divisor (gcd), if one exists.
+ // If no non-zero common divisor exists, an exception is thrown.
+ if (unsignedType && n >> 31 == 1) {
+ // the unsigned value is so large that the high-order bit is set
+ // it cannot be converted to a negative number. Check to see
+ // whether there is an option to reduce its magnitude.
+ final long g = gcd(numerator, divisor);
+ if (g != 0) {
+ n /= g;
+ d /= g;
+ }
if (n >> 31 == 1) {
- // the unsigned value is so large that the high-order bit is set
- // it cannot be converted to a negative number. Check to see
- // whether there is an option to reduce its magnitude.
- final long g = gcd(numerator, divisor);
- if (g != 0) {
- n /= g;
- d /= g;
- }
- if (n >> 31 == 1) {
- throw new NumberFormatException("Unsigned numerator is too large to negate " + numerator);
- }
+ throw new NumberFormatException("Unsigned numerator is too large to negate " + numerator);
}
}
return new RationalNumber(-n, d, false);