Example usage for java.lang Float NEGATIVE_INFINITY

List of usage examples for java.lang Float NEGATIVE_INFINITY

Introduction

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

Prototype

float NEGATIVE_INFINITY

To view the source code for java.lang Float NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type float .

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println("NEGATIVE_INFINITY:" + Float.NEGATIVE_INFINITY);
}

From source file:Main.java

public static RectF trapToRect(float[] array) {
    RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY,
            Float.NEGATIVE_INFINITY);
    for (int i = 1; i < array.length; i += 2) {
        float x = round(array[i - 1] * 10) / 10.f;
        float y = round(array[i] * 10) / 10.f;
        r.left = (x < r.left) ? x : r.left;
        r.top = (y < r.top) ? y : r.top;
        r.right = (x > r.right) ? x : r.right;
        r.bottom = (y > r.bottom) ? y : r.bottom;
    }/*from www . j  a  v a2 s  .  c  om*/
    r.sort();
    return r;
}

From source file:Main.java

/**
 * Takes an array of 2D coordinates representing corners and returns the
 * smallest rectangle containing those coordinates.
 *
 * @param array array of 2D coordinates// w w  w. jav  a2  s.  com
 * @return smallest rectangle containing coordinates
 */
public static RectF trapToRect(float[] array) {
    RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY,
            Float.NEGATIVE_INFINITY);
    for (int i = 1; i < array.length; i += 2) {
        float x = array[i - 1];
        float y = array[i];
        r.left = (x < r.left) ? x : r.left;
        r.top = (y < r.top) ? y : r.top;
        r.right = (x > r.right) ? x : r.right;
        r.bottom = (y > r.bottom) ? y : r.bottom;
    }
    r.sort();
    return r;
}

From source file:Main.java

private static float buildFloat(int mant, int exp) {
    if (exp < -125 || mant == 0) {
        return 0.0f;
    }//from w ww . java2  s .com

    if (exp >= 128) {
        return (mant > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
    }

    if (exp == 0) {
        return mant;
    }

    if (mant >= (1 << 26)) {
        mant++; // round up trailing bits if they will be dropped.
    }

    return (float) ((exp > 0) ? mant * pow10[exp] : mant / pow10[-exp]);
}

From source file:Main.java

/**
 * Parses the supplied xsd:float string and returns its value.
 * //from ww  w .  j a v  a  2 s  .  c om
 * @param s
 *        A string representation of an xsd:float value.
 * @return The <tt>float</tt> value represented by the supplied string argument.
 * @throws NumberFormatException
 *         If the supplied string is not a valid xsd:float value.
 */
public static float parseFloat(String s) {
    if (POSITIVE_INFINITY.equals(s)) {
        return Float.POSITIVE_INFINITY;
    } else if (NEGATIVE_INFINITY.equals(s)) {
        return Float.NEGATIVE_INFINITY;
    } else if (NaN.equals(s)) {
        return Float.NaN;
    } else {
        s = trimPlusSign(s);
        return Float.parseFloat(s);
    }
}

From source file:Main.java

/**
 * Computes a float from mantissa and exponent.
 *///from  w w w  .j  a va2 s .co m
public static float buildFloat(int mant, int exp) {
    if (exp < -125 || mant == 0) {
        return 0.0f;
    }

    if (exp >= 128) {
        return (mant > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
    }

    if (exp == 0) {
        return mant;
    }

    if (mant >= (1 << 26)) {
        mant++; // round up trailing bits if they will be dropped.
    }

    return (float) ((exp > 0) ? mant * pow10[exp] : mant / pow10[-exp]);
}

From source file:org.evosuite.utils.NumberFormatter.java

/**
 * <p>// w w  w .  j a  va  2  s.  c om
 * getNumberString
 * </p>
 * 
 * @param value
 *            a {@link java.lang.Object} object.
 * @return a {@link java.lang.String} object.
 */
public static String getNumberString(Object value) {
    if (value == null)
        return "null";
    else if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) {
        // StringEscapeUtils fails to escape a single quote char
        if (Character.valueOf('\'').equals(value)) {
            return "'\\\''";
        } else {
            return "'" + StringEscapeUtils.escapeJava(Character.toString((Character) value)) + "'";
        }
    } else if (value.getClass().equals(String.class)) {
        return "\"" + StringEscapeUtils.escapeJava((String) value) + "\"";
    } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) {
        if (value.toString().equals("" + Float.NaN))
            return "Float.NaN";
        else if (value.toString().equals("" + Float.NEGATIVE_INFINITY))
            return "Float.NEGATIVE_INFINITY";
        else if (value.toString().equals("" + Float.POSITIVE_INFINITY))
            return "Float.POSITIVE_INFINITY";
        else if (((Float) value) < 0F)
            return "(" + value + "F)";
        else
            return value + "F";
    } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) {
        if (value.toString().equals("" + Double.NaN))
            return "Double.NaN";
        else if (value.toString().equals("" + Double.NEGATIVE_INFINITY))
            return "Double.NEGATIVE_INFINITY";
        else if (value.toString().equals("" + Double.POSITIVE_INFINITY))
            return "Double.POSITIVE_INFINITY";
        else if (((Double) value) < 0.0)
            return "(" + value + ")";
        else
            return value.toString();
    } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) {
        if (((Long) value) < 0)
            return "(" + value + "L)";
        else
            return value + "L";
    } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) {
        if (((Byte) value) < 0)
            return "(byte) (" + value + ")";
        else
            return "(byte)" + value;
    } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) {
        if (((Short) value) < 0)
            return "(short) (" + value + ")";
        else
            return "(short)" + value;
    } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) {
        int val = ((Integer) value).intValue();
        if (val == Integer.MAX_VALUE)
            return "Integer.MAX_VALUE";
        else if (val == Integer.MIN_VALUE)
            return "Integer.MIN_VALUE";
        else if (((Integer) value) < 0)
            return "(" + value + ")";
        else
            return "" + val;
    } else if (value.getClass().isEnum() || value instanceof Enum) {
        // java.util.concurrent.TimeUnit is an example where the enum
        // elements are anonymous inner classes, and then isEnum does
        // not return true apparently? So we check using instanceof as well.

        Class<?> clazz = value.getClass();
        String className = clazz.getSimpleName();
        while (clazz.getEnclosingClass() != null) {
            String enclosingName = clazz.getEnclosingClass().getSimpleName();
            className = enclosingName + "." + className;
            clazz = clazz.getEnclosingClass();
        }

        // We have to do this here to avoid a double colon in the TimeUnit example
        if (!className.endsWith("."))
            className += ".";
        try {
            if (value.getClass().getField(value.toString()) != null)
                return className + value;
            else if (((Enum<?>) value).name() != null)
                return className + ((Enum<?>) value).name();
            else
                return "Enum.valueOf(" + className + "class, \"" + value + "\")";
        } catch (Exception e) {
            if (((Enum<?>) value).name() != null)
                return className + ((Enum<?>) value).name();
            else
                return "Enum.valueOf(" + className + "class /* " + e + " */, \"" + value + "\")";
            // return className + "valueOf(\"" + value + "\")";
        }
    } else if (value.getClass().equals(Boolean.class)) {
        return value.toString();
    } else {
        // This should not happen
        assert (false);
        return value.toString();
    }
}

From source file:test.uk.co.modularaudio.util.audio.math.DbToLevelChecker.java

public void go() throws Exception {
    final MixdownSliderDbToLevelComputer dbc = new MixdownSliderDbToLevelComputer(100);

    final float[] testValues = new float[] { 10.0f, 0.0f, -88.0f, -89.0f, -89.9f, -89.9999f, -90.0f,
            Float.NEGATIVE_INFINITY, -6.01f };

    for (final float v : testValues) {
        final float step = dbc.toStepFromDb(v);
        log.debug("Value (" + MathFormatter.fastFloatPrint(v, NUM_DEC, true) + ") -> step("
                + MathFormatter.fastFloatPrint(step, NUM_DEC, true) + ")");
        final float nv = dbc.toNormalisedSliderLevelFromDb(v);

        log.debug("Value (" + MathFormatter.fastFloatPrint(v, NUM_DEC, true) + ") -> ("
                + MathFormatter.fastFloatPrint(nv, NUM_DEC, true) + ")");

        final float abv = dbc.toDbFromNormalisedLevel(nv);

        log.debug("AndBa (" + MathFormatter.fastFloatPrint(nv, NUM_DEC, true) + ") -> ("
                + MathFormatter.fastFloatPrint(abv, NUM_DEC, true) + ")");
    }//from  w w w . j av  a2  s  . co  m
}

From source file:kishida.cnn.layers.MaxPoolingLayer.java

/** (max) */
@Override//from w ww  .j  ava 2 s .  co m
public float[] forward(float[] data) {
    IntStream.range(0, inputChannels).parallel().forEach(ch -> {
        for (int x = 0; x < outputWidth; ++x) {
            for (int y = 0; y < outputHeight; ++y) {
                float max = Float.NEGATIVE_INFINITY;
                for (int i = 0; i < size; ++i) {
                    int xx = x * stride + i - size / 2;
                    if (xx < 0 || xx >= inputWidth) {
                        continue;
                    }
                    for (int j = 0; j < size; ++j) {
                        int yy = y * stride + j - size / 2;
                        if (yy < 0 || yy >= inputHeight) {
                            continue;
                        }
                        float d = data[ch * inputWidth * inputHeight + xx * inputHeight + yy];
                        if (max < d) {
                            max = d;
                        }
                    }
                }
                result[ch * outputWidth * outputHeight + x * outputHeight + y] = max;
            }
        }
    });
    return result;
}

From source file:com.graphhopper.apache.commons.collections.IntDoubleBinaryHeap.java

public IntDoubleBinaryHeap(int initialCapacity) {
    //+1 as element 0 is noop
    elements = new int[initialCapacity + 1];
    keys = new float[initialCapacity + 1];
    // make minimum to avoid zero array check in while loop
    keys[0] = Float.NEGATIVE_INFINITY;
}