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

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

Introduction

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

Prototype

public Fraction abs() 

Source Link

Document

Returns the absolute value of this fraction.

Usage

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

public static NumberObj abs(NumberObj num) {
    if (num.equals(NaN)) {
        return NaN;
    }/*  w w  w. ja va 2 s  .c o  m*/
    if (num.equals(POSITIVE_INFINITY)) {
        return POSITIVE_INFINITY;
    }
    if (num.equals(NEGATIVE_INFINITY)) {
        return NEGATIVE_INFINITY;
    }

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