Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

In this page you can find the example usage for java.lang Double isInfinite.

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:com.google.blockly.model.FieldNumber.java

/**
 * Sets the constraints on valid number values.
 * <p/>//  www  .  j a  va  2 s  .  com
 * Changing the constraints may trigger a {@link ChangeEvent}, even if the value does not
 * change.
 *
 * @param min The minimum allowed value, inclusive.
 * @param max The maximum allowed value, inclusive.
 * @param precision The precision of allowed values. Valid values are multiples of this number,
 *                  such as 1, 0.1, 100, or 0.125.
 */
public void setConstraints(double min, double max, double precision) {
    if (max == Double.POSITIVE_INFINITY || Double.isNaN(max)) {
        max = NO_CONSTRAINT;
    } else if (max == Double.NEGATIVE_INFINITY) {
        throw new IllegalArgumentException("Max cannot be -Inf. No valid values would exist.");
    }
    if (min == Double.NEGATIVE_INFINITY || Double.isNaN(min)) {
        min = NO_CONSTRAINT;
    } else if (min == Double.POSITIVE_INFINITY) {
        throw new IllegalArgumentException("Min cannot be Inf. No valid values would exist.");
    }
    if (precision == 0 || Double.isNaN(precision)) {
        precision = NO_CONSTRAINT;
    }
    if (Double.isInfinite(precision)) {
        throw new IllegalArgumentException("Precision cannot be infinite.");
    }
    if (!Double.isNaN(min) && !Double.isNaN(max) && min > max) {
        throw new IllegalArgumentException("Minimum value must be less than max. Found " + min + " > " + max);
    }
    if (!Double.isNaN(precision) && precision <= 0) {
        throw new IllegalArgumentException("Precision must be positive. Found " + precision);
    }

    double effectiveMin = Double.isNaN(min) ? -Double.MAX_VALUE : min;
    double effectiveMax = Double.isNaN(max) ? Double.MAX_VALUE : max;
    if (!Double.isNaN(precision)) {
        if (effectiveMin < 0) {
            double multiplier = Math.floor(-effectiveMin / precision);
            effectiveMin = precision * -multiplier;
        } else {
            double multiplier = Math.ceil(effectiveMin / precision);
            effectiveMin = precision * multiplier;
        }
        if (effectiveMax < 0) {
            double multiplier = Math.ceil(-effectiveMax / precision);
            effectiveMax = precision * -multiplier;
        } else {
            double multiplier = Math.floor(effectiveMax / precision);
            effectiveMax = precision * multiplier;

        }
        if (effectiveMin > effectiveMax) {
            throw new IllegalArgumentException("No valid value in range.");
        }
    }

    mMin = min;
    mMax = max;
    mPrecision = precision;
    mEffectiveMin = effectiveMin;
    mEffectiveMax = effectiveMax;
    mIntegerPrecision = (precision == Math.round(precision));
    if (!hasPrecision()) {
        mFormatter = NAIVE_DECIMAL_FORMAT;
    } else if (mIntegerPrecision) {
        mFormatter = INTEGER_DECIMAL_FORMAT;
    } else {
        String precisionStr = NAIVE_DECIMAL_FORMAT.format(precision);
        int decimalChar = precisionStr.indexOf('.');
        if (decimalChar == -1) {
            mFormatter = INTEGER_DECIMAL_FORMAT;
        } else {
            int significantDigits = precisionStr.length() - decimalChar;
            StringBuilder sb = new StringBuilder("0.");
            char[] sigDigitsFormat = new char[significantDigits];
            Arrays.fill(sigDigitsFormat, '#');
            sb.append(sigDigitsFormat);
            mFormatter = new DecimalFormat(sb.toString());
        }
    }

    setValueImpl(mValue, true);
}

From source file:com.joptimizer.optimizers.OptimizationRequestHandler.java

/**
 * Objective function value at X./*ww  w. j  a v a2s  .  c  o  m*/
 */
protected final boolean isInDomainF0(DoubleMatrix1D X) {
    double F0X = request.getF0().value(X.toArray());
    return !Double.isInfinite(F0X) && !Double.isNaN(F0X);
}

From source file:eagle.log.entity.filter.BooleanExpressionComparator.java

/**
 * if(Double.isInfinite(leftValue) || Double.isInfinite(rightValue)) return false;
 *
 * @param context Map[String,Double]//from w  w  w. j  a va 2  s.c  o  m
 * @return evaluation result as true (1) or false (0)
 * @throws Exception
 */
private boolean eval(Map<String, Double> context) throws Exception {
    if (filterEntity.getKeyType() != TokenType.NUMBER) {
        leftValue = eval(filterEntity.getKey(), context);
    }
    if (filterEntity.getValueType() != TokenType.NUMBER) {
        rightValue = eval(filterEntity.getValue(), context);
    }
    if (Double.isInfinite(leftValue) || Double.isInfinite(rightValue)) {
        //            if(LOG.isDebugEnabled()) {
        if (Double.isInfinite(leftValue)) {
            LOG.warn("Evaluation result of key: " + this.filterEntity.getKey() + " is " + leftValue
                    + " (Infinite), ignore");
        } else {
            LOG.warn("Evaluation result of value: " + this.filterEntity.getValue() + " is " + rightValue
                    + " (Infinite), ignore");
        }
        //            }
        return false;
    }
    return func.eval(leftValue, rightValue);
}

From source file:dr.math.distributions.TruncatedDistribution.java

@Override
protected double getInitialDomain(double v) {
    if (!Double.isInfinite(lower) && !Double.isInfinite(upper)) {
        return (upper + lower) / 2;
    } else if (!Double.isInfinite(upper)) {
        return upper / 2;
    } else if (!Double.isInfinite(lower)) {
        return lower * 2;
    }/*from   ww w.j  a v a2  s  .  c om*/
    return v;
}

From source file:org.dawnsci.common.richbeans.beans.BeanUI.java

private static boolean isInfinity(Object ob) {
    if (!(ob instanceof Double))
        return false;
    return Double.isInfinite(((Double) ob).doubleValue());
}

From source file:com.joptimizer.optimizers.LPPrimalDualMethod.java

public LPPrimalDualMethod(double minLBValue, double maxUBValue) {
    if (Double.isNaN(minLBValue) || Double.isInfinite(minLBValue)) {
        throw new IllegalArgumentException(
                "The field minLBValue must not be set to Double.NaN or Double.NEGATIVE_INFINITY");
    }//  w  ww. j  a  va2  s.c om
    if (Double.isNaN(maxUBValue) || Double.isInfinite(maxUBValue)) {
        throw new IllegalArgumentException(
                "The field maxUBValue must not be set to Double.NaN or Double.POSITIVE_INFINITY");
    }
    this.minLBValue = minLBValue;
    this.maxUBValue = maxUBValue;
}

From source file:edu.jhuapl.bsp.detector.OpenMath.java

public static double mean(double[] in) {
    if (in != null && in.length > 0) {
        double sum = 0;
        for (int i = 0; i < in.length; i++) {
            sum += in[i];/*w  ww  . j a  v a2  s .c  o m*/
        }
        double result = sum / in.length;
        if (Double.isNaN(result) || Double.isInfinite(result)) {
            return 0;
        } else {
            return result;
        }
    }
    return 0;
}

From source file:playground.johannes.coopsim.eval.JointActivityEvaluator2.java

@Override
public double evaluate(Trajectory trajectory) {
    double score = 0;

    String type = ((Activity) trajectory.getElements().get(2)).getType();
    List<Person> alterList = alters.get(trajectory.getPerson());

    int n = tracker.metAlters(trajectory.getPerson(), alterList);
    if (n >= 1 && V_star > 0) {
        double f_star = 0;

        if (type.equals(ActivityType.visit.name())) {
            f_star = fVisit;/*from w  w w  .jav  a  2 s .c o m*/
        } else if (type.equals(ActivityType.culture.name())) {
            f_star = fCulture;
        } else if (type.equals(ActivityType.gastro.name())) {
            f_star = fGastro;
        } else if (type.equals(ActivityType.home.name())) {
            f_star = 0;
        } else {
            throw new IllegalArgumentException(
                    String.format("Unknown activity type in joint activity scoring (%1$s).", type));
        }

        if (f_star > 0) {
            // round f_start to a realizable value
            double n_star = Math.round(f_star * alterList.size());
            n_star = Math.max(n_star, 1);
            f_star = n_star / (double) alterList.size();

            double f = n / (double) alterList.size();

            //            V_star = V_star/Math.log(2) * Math.log(f_star + 1);
            score = -(V_star / (f_star * f_star)) * Math.pow((f - f_star), 2) + V_star;

            if (Double.isNaN(score)) {
                throw new RuntimeException("Joint score is NaN.");
            } else if (Double.isInfinite(score)) {
                throw new RuntimeException("Joint score is infty.");
            }
        } else {
            score = 0;
        }
    } else {
        score = 0;
    }

    if (isLogging && !type.equals(ActivityType.home.name())) {
        stats.addValue(score);
        if (type.equals(ActivityType.visit.name())) {
            visitStats.addValue(score);
        } else if (type.equals(ActivityType.culture.name())) {
            cultureStats.addValue(score);
        } else if (type.equals(ActivityType.gastro.name())) {
            gastroStats.addValue(score);
        }
    }

    return score;
}

From source file:com.bmwcarit.barefoot.markov.StateCandidate.java

/**
 * Gets a JSON representation of the state candidate.
 *
 * @return JSON representation of the state candidate.
 * @throws JSONException thrown on JSON extraction or parsing error.
 *///from www .j ava2 s.c o  m
public JSONObject toJSON() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("id", id);
    json.put("filtprob", Double.isInfinite(filtprob) ? "Infinity" : filtprob);
    json.put("seqprob", Double.isInfinite(seqprob) ? "-Infinity" : seqprob);
    if (transition != null) {
        json.put("transition", transition().toJSON());
    }
    return json;
}

From source file:com.joptimizer.optimizers.LPOptimizationRequest.java

public void setUb(DoubleMatrix1D ub) {
    for (int i = 0; i < ub.size(); i++) {
        double ubi = ub.getQuick(i);
        if (Double.isNaN(ubi) || Double.isInfinite(ubi)) {
            throw new IllegalArgumentException(
                    "The upper bounds can not be set to Double.NaN or Double.INFINITY");
        }/*from  ww w . j a  v  a2s .  co m*/
    }
    this.ub = ub;
}