public RationalNumber negate() {
        long n = numerator;
        long d = divisor;
        // 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) {
                throw new NumberFormatException("Unsigned numerator is too large to negate " + numerator);
            }
        }
        return new RationalNumber(-n, d, false);
    }
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 divide both terms by a common divisor, if a
non-zero common divisor exists. However, if no such divisor exists, there is no numerically correct way to perform the negation. When a negation cannot
be performed correctly, this method throws an unchecked exception.

@return a valid instance with a negated value.
src/main/java/org/apache/commons/imaging/common/RationalNumber.java