Example usage for java.lang Number doubleValue

List of usage examples for java.lang Number doubleValue

Introduction

In this page you can find the example usage for java.lang Number doubleValue.

Prototype

public abstract double doubleValue();

Source Link

Document

Returns the value of the specified number as a double .

Usage

From source file:de.christianseipl.utilities.maputils.MapMath.java

/**
 * Multipliziert alle Werte der Map mit {@code _factor}.
 * /*from   w ww  .j  a  v a2 s.  c  o m*/
 * @param <K> ein beliebiger Objekttyp
 * @param _map
 * @param _factor
 * @return Eine neue Map mit dem Produkt aus der alten Map und {@code
 *         _factor}.
 */
public static <K> Map<K, Double> times(Map<? extends K, ? extends Number> _map, final double _factor) {
    return operateOnMap(_map, new NumberTransformer<K, Double>() {

        @Override
        public Double transform(K _key, Number _number) {
            return _number.doubleValue() * _factor;
        }

    });
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns {@code true} if the two numbers are equal; {@code false}
 * otherwise.// ww  w.  j a v a  2 s .com
 * 
 * @param a the first number
 * @param b the second number
 * @return {@code true} if the two numbers are equal; {@code false}
 *         otherwise
 */
public static boolean equals(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        return a.doubleValue() == b.doubleValue();
    } else {
        return a.longValue() == b.longValue();
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns {@code true} if the first number is less than the second;
 * {@code false} otherwise./* ww w  .  j  a  va  2s. c o m*/
 * 
 * @param a the first number
 * @param b the second number
 * @return {@code true} if the first number is less than the second;
 *         {@code false} otherwise
 */
public static boolean lessThan(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        return a.doubleValue() < b.doubleValue();
    } else {
        return a.longValue() < b.longValue();
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns {@code true} if the first number is greater than the second;
 * {@code false} otherwise./*from  w  w w.j  a v  a 2  s.c  o m*/
 * 
 * @param a the first number
 * @param b the second number
 * @return {@code true} if the first number is greater than the second;
 *         {@code false} otherwise
 */
public static boolean greaterThan(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        return a.doubleValue() > b.doubleValue();
    } else {
        return a.longValue() > b.longValue();
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the value of adding the two numbers
 * //from   w  ww .  jav a 2  s. co m
 * @param a the first number
 * @param b the second number
 * @return the value of adding the two numbers
 */
public static Number add(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        return a.doubleValue() + b.doubleValue();
    } else {
        return a.longValue() + b.longValue();
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the value of subtracting the first from the second number.
 * /*from w ww .  j  a  v  a 2 s  .c o m*/
 * @param a the first number
 * @param b the second number
 * @return the value of subtracting the first from the second number
 */
public static Number sub(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        return a.doubleValue() - b.doubleValue();
    } else {
        return a.longValue() - b.longValue();
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the value of multiplying the two numbers.
 * //from www. jav  a  2  s .  c o  m
 * @param a the first number
 * @param b the second number
 * @return the value of multiplying the two numbers
 */
public static Number mul(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        return a.doubleValue() * b.doubleValue();
    } else {
        return a.longValue() * b.longValue();
    }
}

From source file:de.christianseipl.utilities.maputils.MapMath.java

/**
 * Dividiert jedes Element der Map {@code _this} durch den entsprechenden
 * Wert der Map {@code _that}. Das Ergebnis wird im Rckgabewert abgelegt.
 * //from w w w .  ja va2 s  .c o m
 * @param <K> ein beliebiger Objekttyp
 *            
 * @param _this
 *            Dividend
 * @param _that
 *            Divisor
 * @return Eine neue Map mit den Quotienten.
 */
public static <K> Map<K, Double> divide(Map<? extends K, ? extends Number> _this,
        final Map<? extends K, ? extends Number> _that) {

    areKeysEqual(_this, _that);

    return operateOnMap(_this, new NumberTransformer<K, Double>() {

        @Override
        public Double transform(K _key, Number _number) {
            return _number.doubleValue() / _that.get(_key).doubleValue();
        }

    });
}

From source file:de.christianseipl.utilities.maputils.MapMath.java

/**
 * Multipliziert die Werte zweier Maps paarweise miteinander und gibt eine
 * neue Map zurck./*from w ww. ja v a 2 s . c o  m*/
 * 
 * @param <K> ein beliebiger Objekttyp
 *            
 * @param _this
 *            Erster Faktor
 * @param _that
 *            Zweiter Faktor
 * @return Eine neue Map mit dem paarweisen Produkt der beiden Faktoren.
 */
public static <K> Map<K, Double> times(Map<? extends K, ? extends Number> _this,
        final Map<? extends K, ? extends Number> _that) {

    areKeysEqual(_this, _that);

    return operateOnMap(_this, new NumberTransformer<K, Double>() {

        @Override
        public Double transform(K _key, Number _number) {
            return _number.doubleValue() * _that.get(_key).doubleValue();
        }

    });
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the value of dividing the first number by the second.  If the
 * second argument is {@code 0} and function protection is enabled, this
 * function returns {@code 1} regardless of the first argument's value.
 * /*w w w.ja v a2  s  .  c om*/
 * @param a the first number
 * @param b the second number
 * @return the value of dividing the first number by the second
 */
public static Number div(Number a, Number b) {
    if (isFloatingPoint(a) || isFloatingPoint(b)) {
        if ((Math.abs(b.doubleValue()) < Settings.EPS) && Settings.isProtectedFunctions()) {
            return 1.0;
        } else {
            return a.doubleValue() / b.doubleValue();
        }
    } else {
        if ((b.longValue() == 0) && Settings.isProtectedFunctions()) {
            return 1L;
        } else {
            return a.longValue() / b.longValue();
        }
    }
}