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

/**
 * Fills the array with random floats.  Values will be between min (inclusive) and
 * max (inclusive)./*from   www. j a v  a 2s  . co  m*/
 */
public static void genRandomFloats(long seed, float min, float max, float array[], boolean includeExtremes) {
    Random r = new Random(seed);
    int minExponent = Math.min(Math.getExponent(min), 0);
    int maxExponent = Math.max(Math.getExponent(max), 0);
    if (minExponent < -6 || maxExponent > 6) {
        // Use an exponential distribution
        int exponentDiff = maxExponent - minExponent;
        for (int i = 0; i < array.length; i++) {
            float mantissa = r.nextFloat();
            int exponent = minExponent + r.nextInt(maxExponent - minExponent);
            int sign = (min >= 0) ? 1 : 1 - r.nextInt(2) * 2; // -1 or 1
            float rand = sign * mantissa * (float) Math.pow(2.0, exponent);
            if (rand < min || rand > max) {
                continue;
            }
            array[i] = rand;
        }
    } else {
        // Use a linear distribution
        for (int i = 0; i < array.length; i++) {
            float rand = r.nextFloat();
            array[i] = min + rand * (max - min);
        }
    }
    // Seed a few special numbers we want to be sure to test.
    for (int i = 0; i < sInterestingDoubles.length; i++) {
        float f = (float) sInterestingDoubles[i];
        if (min <= f && f <= max) {
            array[r.nextInt(array.length)] = f;
        }
    }
    array[r.nextInt(array.length)] = min;
    array[r.nextInt(array.length)] = max;
    if (includeExtremes) {
        array[r.nextInt(array.length)] = Float.NaN;
        array[r.nextInt(array.length)] = Float.POSITIVE_INFINITY;
        array[r.nextInt(array.length)] = Float.NEGATIVE_INFINITY;
        array[r.nextInt(array.length)] = Float.MIN_VALUE;
        array[r.nextInt(array.length)] = Float.MIN_NORMAL;
        array[r.nextInt(array.length)] = Float.MAX_VALUE;
        array[r.nextInt(array.length)] = -Float.MIN_VALUE;
        array[r.nextInt(array.length)] = -Float.MIN_NORMAL;
        array[r.nextInt(array.length)] = -Float.MAX_VALUE;
    }
}

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

@Test
public void testFromFloat() {
    final float[] testFloats = new float[] { Float16.MAX_VALUE, Float16.MIN_VALUE,

            // Interesting values from an audio perspective
            -1.0f, -0.001f, -0.0001f, 0.0f, 0.0001f, 0.001f, 1.0f, -1.1f, -0.9f, 0.9f, 1.1f,

            // Some "steady" values
            0.1f, 0.125f, 0.2f, 0.25f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.75f, 0.8f, 0.825f,

            // And some values to examine precision
            192000.0f, 41000.0f, 22050.0f, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, };

    for (final float testFloat : testFloats) {
        final Float16 f16 = new Float16(testFloat);

        final float andBack = f16.asFloat();

        log.debug("OF(" + MathFormatter.slowFloatPrint(testFloat, 16, true) + ") F16("
                + MathFormatter.slowFloatPrint(andBack, 16, true) + ")");
    }//w  ww  .ja v  a  2  s. co  m
}

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

public float toDbFromNormalisedLevel(float level) {
    // Slider is from 0 -> 1
    // special case 0
    if (level == 0.0f) {
        return Float.NEGATIVE_INFINITY;
    } else {/*from  ww w .  j ava  2  s.com*/
        return (level * totalDynamicRange) - LOWEST_NEGATIVE_DB;
    }
}

From source file:org.fnlp.nlp.similarity.train.WordClusterM.java

/**
 * merge clusters//from w ww.j  a  v  a 2  s.  c  o m
 */
public void mergeCluster() {
    maxc1 = -1;
    maxc2 = -1;
    maxL = Float.NEGATIVE_INFINITY;
    TIntIterator it1 = slots.iterator();

    while (it1.hasNext()) {
        int i = it1.next();
        TIntIterator it2 = slots.iterator();
        //         System.out.print(i+": ");
        while (it2.hasNext()) {
            int j = it2.next();

            if (i >= j)
                continue;
            //            System.out.print(j+" ");
            Multiplesolve c = new Multiplesolve(i, j);
            count.incrementAndGet();
            pool.execute(c);
        }
        //         System.out.println();
    }

    while (count.get() != 0) {//?  
        try {
            Thread.sleep(slotsize * slotsize / 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    merge(maxc1, maxc2);
}

From source file:Main.java

/**
 * Returns the floating-point value adjacent to <code>f</code> in
 * the direction of negative infinity.  This method is
 * semantically equivalent to <code>nextAfter(f,
 * Float.NEGATIVE_INFINITY)</code>; however, a
 * <code>nextDown</code> implementation may run faster than its
 * equivalent <code>nextAfter</code> call.
 *
 * <p>Special Cases:/*w  w w.  j a  v a 2  s  .  c  o m*/
 * <ul>
 * <li> If the argument is NaN, the result is NaN.
 *
 * <li> If the argument is negative infinity, the result is
 * negative infinity.
 *
 * <li> If the argument is zero, the result is
 * <code>-Float.MIN_VALUE</code>
 *
 * </ul>
 *
 * @param f  starting floating-point value
 * @return The adjacent floating-point value closer to negative
 * infinity.
 * @author Joseph D. Darcy
 */
public static double nextDown(float f) {
    if (isNaN(f) || f == Float.NEGATIVE_INFINITY)
        return f;
    else {
        if (f == 0.0f)
            return -Float.MIN_VALUE;
        else
            return Float.intBitsToFloat(Float.floatToRawIntBits(f) + ((f > 0.0f) ? -1 : +1));
    }
}

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

public float toNormalisedSliderLevelFromDb(float db) {
    if (db == Float.NEGATIVE_INFINITY) {
        return 0.0f;
    } else {/*  w w  w  . j a v a  2s  .  c  om*/
        return (db + LOWEST_NEGATIVE_DB) / totalDynamicRange;
    }
}

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

@Override
public float toDbFromNormalisedLevel(final float level) {
    // Slider is from 0 -> 1
    // special case 0
    if (level == 0.0f) {
        return Float.NEGATIVE_INFINITY;
    } else {//w ww  .  j  a  va2s  . c  o  m
        // Take off one step for -INF
        int scaledIntVal = (int) (level * numTotalSteps) - 1;

        if (scaledIntVal < numCompressedSteps) {
            // Map to compressed values
            return compressedLowestDb + ((float) scaledIntVal / numCompressedSteps) * compressedDynamicRange;
        } else {
            // Take off num compressed values, and map to linear values
            scaledIntVal -= numCompressedSteps;
            final float outputDb = linearLowestDb
                    + (((float) scaledIntVal / numLinearSteps) * linearDynamicRange);
            return outputDb;
        }
    }
}

From source file:uk.co.modularaudio.util.audio.controlinterpolation.CDSpringAndDamperDouble24Interpolator.java

public CDSpringAndDamperDouble24Interpolator() {
    curState.x = 0.0;/*from   w  w w .  j  a  v  a2  s .  c  o m*/
    curState.v = 0.0;
    this.lowerBound = Float.NEGATIVE_INFINITY;
    this.upperBound = Float.POSITIVE_INFINITY;
    deltaTimestep = INTEGRATION_TIMESTEP_FOR_48K;
}

From source file:uk.co.modularaudio.util.audio.controlinterpolation.CDSpringAndDamperDouble12Interpolator.java

public CDSpringAndDamperDouble12Interpolator() {
    curState.x = 0.0;/*from   w ww. j  a v  a  2 s.c  om*/
    curState.v = 0.0;
    this.lowerBound = Float.NEGATIVE_INFINITY;
    this.upperBound = Float.POSITIVE_INFINITY;
    deltaTimestep = INTEGRATION_TIMESTEP_FOR_48K;
}

From source file:io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory.java

@JsonCreator
public ApproximateHistogramAggregatorFactory(@JsonProperty("name") String name,
        @JsonProperty("fieldName") String fieldName, @JsonProperty("resolution") Integer resolution,
        @JsonProperty("numBuckets") Integer numBuckets, @JsonProperty("lowerLimit") Float lowerLimit,
        @JsonProperty("upperLimit") Float upperLimit

) {//from   ww  w  . j  av a 2s  . c om
    this.name = name;
    this.fieldName = fieldName;
    this.resolution = resolution == null ? ApproximateHistogram.DEFAULT_HISTOGRAM_SIZE : resolution;
    this.numBuckets = numBuckets == null ? ApproximateHistogram.DEFAULT_BUCKET_SIZE : numBuckets;
    this.lowerLimit = lowerLimit == null ? Float.NEGATIVE_INFINITY : lowerLimit;
    this.upperLimit = upperLimit == null ? Float.POSITIVE_INFINITY : upperLimit;

    Preconditions.checkArgument(this.resolution > 0, "resolution must be greater than 1");
    Preconditions.checkArgument(this.numBuckets > 0, "numBuckets must be greater than 1");
    Preconditions.checkArgument(this.upperLimit > this.lowerLimit,
            "upperLimit must be greater than lowerLimit");
}