Example usage for org.apache.commons.math3.fraction Fraction negate

List of usage examples for org.apache.commons.math3.fraction Fraction negate

Introduction

In this page you can find the example usage for org.apache.commons.math3.fraction Fraction negate.

Prototype

public Fraction negate() 

Source Link

Document

Return the additive inverse of this fraction.

Usage

From source file:unikl.disco.misc.NumberObj.java

public static NumberObj negate(NumberObj num) {
    if (num.equals(NaN)) {
        return NaN;
    }/*from   ww w .j a v  a  2 s.co  m*/
    if (num.equals(POSITIVE_INFINITY)) {
        return NEGATIVE_INFINITY;
    }
    if (num.equals(NEGATIVE_INFINITY)) {
        return POSITIVE_INFINITY;
    }

    switch (num.getType()) {
    case DOUBLE:
        Double double_value = (Double) num.getValue();
        return new NumberObj(-(double_value.doubleValue()));
    case RATIONAL:
        Fraction frac = (Fraction) num.getValue();
        return new NumberObj(frac.negate());
    default:
        return new NumberObj(0.0);
    }
}