Example usage for java.lang Float isInfinite

List of usage examples for java.lang Float isInfinite

Introduction

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

Prototype

public static boolean isInfinite(float v) 

Source Link

Document

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

Usage

From source file:com.hightail.metrics.rest.NewRelicHTTPv1Reporter.java

private void doGauge(String name, Gauge gauge) {
    Object gaugeValue = gauge.getValue();
    Map<String, Object> componentMetrics = new HashMap<String, Object>();

    if (gaugeValue instanceof Number) {
        float n = ((Number) gaugeValue).floatValue();
        if (!Float.isNaN(n) && !Float.isInfinite(n)) {
            componentMetrics.put(prefix(name) + "/gauge", n);
            postToNewRelic(componentMetrics);
        }//w  ww . j  a  va2s  .c  om
    }
}

From source file:ponzu.impl.test.Verify.java

/**
 * Asserts that two floats are not equal concerning a delta. If the expected value is infinity then the delta value
 * is ignored.//from w w  w  .j av a2 s  .c om
 */
public static void assertNotEquals(String itemName, float notExpected, float actual, float delta) {
    try {
        // handle infinity specially since subtracting to infinite values gives NaN and the
        // the following test fails
        if (Float.isInfinite(notExpected) && notExpected == actual || Math.abs(notExpected - actual) <= delta) {
            Assert.fail(itemName + " should not be equal:<" + notExpected + '>');
        }
    } catch (AssertionError e) {
        throwMangledException(e);
    }
}

From source file:org.apache.vxquery.runtime.functions.cast.CastToStringOperation.java

@Override
public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
    abvsInner.reset();/*from   w w  w.j av a 2s  .  c o m*/
    float value = floatp.getFloat();

    if (!Float.isInfinite(value) && !Float.isNaN(value) && Math.abs(value) >= 0.000001
            && Math.abs(value) <= 1000000) {
        CastToDecimalOperation castToDecimal = new CastToDecimalOperation();
        castToDecimal.convertFloat(floatp, dOutInner);
        XSDecimalPointable decp = (XSDecimalPointable) XSDecimalPointable.FACTORY.createPointable();
        decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1, abvsInner.getLength());
        convertDecimal(decp, dOut);
    } else if (value == -0.0f || value == 0.0f) {
        long bits = Float.floatToIntBits(value);
        boolean negative = ((bits >> 31) == 0) ? false : true;

        if (negative) {
            FunctionHelper.writeChar('-', dOutInner);
        }
        FunctionHelper.writeCharSequence("0", dOutInner);
        sendStringDataOutput(dOut);
    } else {
        convertFloatCanonical(floatp, dOut);
    }
}

From source file:org.alfresco.repo.jscript.app.JSONConversionComponent.java

/**
 * Handles the work of converting values to JSON.
 * /*from   w ww . j av  a2 s. c  o  m*/
 * @param nodeRef NodeRef
 * @param propertyName QName
 * @param key String
 * @param value Serializable
 * @return the JSON value
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object propertyToJSON(final NodeRef nodeRef, final QName propertyName, final String key,
        final Serializable value) {
    if (value != null) {
        // Has a decorator has been registered for this property?
        if (propertyDecorators.containsKey(propertyName)) {
            JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
            if (jsonAware != null) {
                return jsonAware;
            }
        } else {
            // Built-in data type processing
            if (value instanceof Date) {
                JSONObject dateObj = new JSONObject();
                dateObj.put("value", JSONObject.escape(value.toString()));
                dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date) value)));
                return dateObj;
            } else if (value instanceof List) {
                // Convert the List to a JSON list by recursively calling propertyToJSON
                List<Object> jsonList = new ArrayList<Object>(((List<Serializable>) value).size());
                for (Serializable listItem : (List<Serializable>) value) {
                    jsonList.add(propertyToJSON(nodeRef, propertyName, key, listItem));
                }
                return jsonList;
            } else if (value instanceof Double) {
                return (Double.isInfinite((Double) value) || Double.isNaN((Double) value) ? null
                        : value.toString());
            } else if (value instanceof Float) {
                return (Float.isInfinite((Float) value) || Float.isNaN((Float) value) ? null
                        : value.toString());
            } else {
                return value.toString();
            }
        }
    }
    return null;
}

From source file:com.gs.collections.impl.test.Verify.java

/**
 * Asserts that two floats are not equal concerning a delta. If the expected value is infinity then the delta value
 * is ignored.//from   w  w  w . j a  v  a 2s .  co m
 */
public static void assertNotEquals(String itemName, float notExpected, float actual, float delta) {
    try {
        // handle infinity specially since subtracting to infinite values gives NaN and the
        // the following test fails
        //noinspection FloatingPointEquality
        if (Float.isInfinite(notExpected) && notExpected == actual || Math.abs(notExpected - actual) <= delta) {
            Assert.fail(itemName + " should not be equal:<" + notExpected + '>');
        }
    } catch (AssertionError e) {
        Verify.throwMangledException(e);
    }
}

From source file:edu.ucsc.barrel.cdf_gen.SpectrumExtract.java

private static float[] binvert(float[] start, float f) {
    int size = start.length, bad_vals = 0;

    float[] iter1 = new float[size];
    float[] iter2 = new float[size];

    //first iteration of Newton-Raphson  
    for (int i = 0; i < size; i++) {
        if (start[i] < 0) {
            iter1[i] = Float.NaN;
        } else {//from w ww. ja  v a  2s. c o  m
            iter1[i] = (start[i] + f * start[i]) / (1.0f + f * (1.0f + (float) Math.log(start[i])));
            if (iter1[i] < 0) {
                iter1[i] = Float.NaN;
            }
        }
    }

    //second iteration of Newton-Raphson  
    for (int i = 0; i < size; i++) {
        if (Float.isNaN(iter1[i])) {
            bad_vals++;
        } else {
            iter2[i] = (start[i] + f * iter1[i]) / (1.0f + f * (1.0f + (float) Math.log(iter1[i])));
            if (Float.isInfinite(iter2[i]) || iter2[i] < 0) {
                bad_vals++;
                iter2[i] = Float.NaN;
            }
        }
    }

    //turn bad values into negatives ascending to zero
    if (bad_vals > 0) {
        for (int i = 0; i < size; i++) {
            if (Float.isNaN(iter2[i])) {
                bad_vals--;
                iter2[i] = 0 - bad_vals;
            }
        }
    }

    return iter2;
}

From source file:org.apache.vxquery.runtime.functions.cast.CastToStringOperation.java

public void convertFloatCanonical(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
    abvsInner.reset();//from ww w .  j ava  2 s  .  c o  m
    float value = floatp.getFloat();

    if (Float.isInfinite(value)) {
        if (value == Float.NEGATIVE_INFINITY) {
            FunctionHelper.writeCharSequence("-", dOutInner);
        }
        FunctionHelper.writeCharSequence("INF", dOutInner);
    } else if (Float.isNaN(value)) {
        FunctionHelper.writeCharSequence("NaN", dOutInner);
    } else {
        dOut.write(returnTag);
        dOut.writeUTF(Float.toString(value));
        return;
    }
    sendStringDataOutput(dOut);
}

From source file:org.caleydo.core.util.impute.KNNImpute.java

/**
 * @return/*ww w .ja  v  a2s.  c  o  m*/
 */
private boolean toomanyNaNsInAColumn() {
    float colmax = desc.getColmax();
    if (Float.isInfinite(colmax) || Float.isNaN(colmax))
        return false;
    int max = Math.round(colmax * genes.size());
    for (int i = 0; i < samples; ++i) {
        int nans = getSample(i).getNans();
        if (nans > max)
            return true;
    }
    return false;
}

From source file:org.caleydo.view.bicluster.elem.GLRootElement.java

/**
 *
 * @param isDimensionThresholds//  w  w  w  . j a v  a2  s.  c  o m
 * @param thresholds
 *            bicluster id x threshold
 */
public void setThresholds(EDimension dimension, Map<Integer, Float> thresholds) {
    float thresh = Float.NEGATIVE_INFINITY;
    for (NormalClusterElement elem : allNormalClusters()) {
        int number = elem.getBiClusterNumber();
        if (thresholds.containsKey(number)) {
            float t = thresholds.get(number);
            if (Float.isInfinite(thresh))
                thresh = t;
            if (t != thresh)
                thresh = Float.NaN;
            elem.setThreshold(dimension, t, MyUnboundSpinner.UNBOUND, EThresholdMode.ABS);
        }
    }
    if (!Float.isNaN(thresh) && !Float.isInfinite(thresh)) { // all the same set that in the parameter toolbar
        this.toolbarParam.setThreshold(dimension, thresh);
    }
    updateAllEdges();
}

From source file:jp.co.acroquest.jsonic.Formatter.java

public boolean format(final JSON json, final Context context, final Object src, final Object o,
        final OutputSource out) throws Exception {
    NumberFormat f = context.getNumberFormat();
    float[] array = (float[]) o;
    out.append('[');
    for (int i = 0; i < array.length; i++) {
        if (Float.isNaN(array[i]) || Float.isInfinite(array[i])) {
            if (context.getMode() != Mode.SCRIPT) {
                out.append('"');
                out.append(Float.toString(array[i]));
                out.append('"');
            } else if (Double.isNaN(array[i])) {
                out.append("Number.NaN");
            } else {
                out.append("Number.");
                out.append((array[i] > 0) ? "POSITIVE" : "NEGATIVE");
                out.append("_INFINITY");
            }/*from   w  w w .j ava2  s  . co m*/
        } else if (f != null) {
            StringFormatter.serialize(context, f.format(array[i]), out);
        } else {
            out.append(String.valueOf(array[i]));
        }
        if (i != array.length - 1) {
            out.append(',');
            if (context.isPrettyPrint())
                out.append(' ');
        }
    }
    out.append(']');
    return true;
}