Example usage for java.lang Float NaN

List of usage examples for java.lang Float NaN

Introduction

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

Prototype

float NaN

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

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value 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 w w  w .j av a  2s  .  c  o 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:de.betterform.xml.xforms.xpath.saxon.function.xpath.FileSize.java

public Item evaluateItem(XPathContext xpathContext) throws XPathException {
    if (argument.length != 1) {
        throw new XPathException("There must be 1 argument (filename) for this function");
    }//from   w  w w  . j av  a 2 s .  c  o m

    final Expression keyExpression = argument[0];
    final String filename = keyExpression.evaluateAsString(xpathContext).toString();

    if (filename == null) {
        return new FloatValue(Float.NaN);
    }
    try {
        Container container = getContainer(xpathContext);
        return new FloatValue(new URI(container.getProcessor().getBaseURI()).resolve(filename).toURL()
                .openConnection().getContentLength());
    } catch (Exception e) {
        LOGGER.error("Unable to retrieve file size", e);
        return new FloatValue(Float.NaN);
    }
}

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) + ")");
    }/*from  www .  j a  v  a 2 s .  c  o m*/
}

From source file:hivemall.common.ConversionState.java

public ConversionState(boolean conversionCheck, double convergenceRate) {
    this.conversionCheck = conversionCheck;
    this.convergenceRate = convergenceRate;
    this.readyToFinishIterations = false;
    this.totalErrors = 0.d;
    this.currLosses = 0.d;
    this.prevLosses = Double.POSITIVE_INFINITY;
    this.curIter = 0;
    this.curEta = Float.NaN;
}

From source file:juicebox.matrix.InMemoryMatrix.java

public void fill(float value) {
    Arrays.fill(data, value);

    // Invalidate bounds
    lowerValue = Float.NaN;
    upperValue = Float.NaN;
}

From source file:Main.java

/**
 * Determines the minimum and maximum values in the <tt>array</tt>. Calls {@link #minMax(float[], float)} with <tt>Float.NaN</tt> as the
 * <tt>noDataValue</tt>.//from w w w .  j a  v a 2 s .  co m
 * 
 * @param array
 * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
 * @see #minMax(float[], float)
 */
public static float[] minMax(float[] array) {
    return minMax(array, Float.NaN);
}

From source file:juicebox.matrix.InMemoryMatrix.java

@Override
public float getEntry(int row, int col) {

    int idx = row * dim + col;
    return idx < data.length ? data[idx] : Float.NaN;
}

From source file:eu.itesla_project.modelica_export.records.LoadRecord.java

public LoadRecord(Load load, ConnectBusInfo busInfo, float SNREF, SourceEngine sourceEngine) {
    this.load = load;
    this.busInfo = busInfo;
    this.loadId = load.getId();
    this.busConnected = busInfo.isConnected();
    this.p0 = this.load.getP0();
    this.q0 = this.load.getQ0();
    this.busVoltage = Float.NaN;
    this.busAngle = Float.NaN;
    this.sourceEngine = sourceEngine;

    if (this.busConnected) {
        if (load.getTerminal().getBusView().getBus() != null) {
            if (!Float.isNaN(load.getTerminal().getBusView().getBus().getV()))
                busVoltage = load.getTerminal().getBusView().getBus().getV()
                        / load.getTerminal().getVoltageLevel().getNominalV();

            if (!Float.isNaN(load.getTerminal().getBusView().getBus().getAngle()))
                busAngle = load.getTerminal().getBusView().getBus().getAngle();
        }//from  w  w  w.  j  av a 2  s.  c  o  m

        addLfParameters();
    } else {
        _log.warn("Load " + this.getModelicaName() + " disconnected.");
        this.addValue(StaticData.COMMENT + " Load " + this.getModelicaName() + " disconnected.");
    }

    if (this.busVoltage == 0) {
        _log.info("Voltage 0");
    }
}

From source file:org.transitime.avl.AvlCsvRecord.java

/**
 * Returns AvlReport that the line in the CSV file represents.
 * <p>/*from www  .ja va2s  .co m*/
 * CSV columns include vehicleId, time (in epoch msec or as date string as
 * in "9-14-2015 12:53:01"), latitude, longitude, speed (optional), heading
 * (optional), assignmentId, and assignmentType (optional, but can be
 * BLOCK_ID, ROUTE_ID, TRIP_ID, or TRIP_SHORT_NAME).
 * 
 * @param record
 * @param fileName
 * @return AvlReport, or null if could not be parsed.
 */
public static AvlReport getAvlReport(CSVRecord record, String fileName) throws ParseException {
    AvlCsvRecord avlCsvRecord = new AvlCsvRecord(record, fileName);

    // Obtain the required values
    String vehicleId = avlCsvRecord.getRequiredValue(record, "vehicleId");

    String timeStr = avlCsvRecord.getRequiredValue(record, "time");

    // Process time
    long time = 0L;
    if (timeStr.contains(":")) {
        // Time is in the format "MM-dd-yyyy HH:mm:ss z" then use Time.parse()
        time = Time.parse(timeStr).getTime();
    } else {
        // Time is already an epoch time long
        time = Long.parseLong(timeStr);
    }

    String latStr = avlCsvRecord.getRequiredValue(record, "latitude");
    double lat = Double.parseDouble(latStr);

    String lonStr = avlCsvRecord.getRequiredValue(record, "longitude");
    double lon = Double.parseDouble(lonStr);

    String speedStr = avlCsvRecord.getOptionalValue(record, "speed");
    float speed = speedStr == null ? Float.NaN : Float.parseFloat(speedStr);

    String headingStr = avlCsvRecord.getOptionalValue(record, "heading");
    float heading = headingStr == null ? Float.NaN : Float.parseFloat(headingStr);

    // Obtain the optional values
    String leadVehicleId = avlCsvRecord.getOptionalValue(record, "leadVehicleId");
    String driverId = avlCsvRecord.getOptionalValue(record, "driverId");
    String licensePlate = avlCsvRecord.getOptionalValue(record, "licensePlate");

    String passengerFullnessStr = avlCsvRecord.getOptionalValue(record, "passengerFullness");
    float passengerFullness = passengerFullnessStr == null ? Float.NaN : Float.parseFloat(passengerFullnessStr);

    String passengerCountStr = avlCsvRecord.getOptionalValue(record, "passengerCount");
    Integer passengerCount = passengerCountStr == null ? null : Integer.parseInt(passengerCountStr);

    // Create the avlReport
    AvlReport avlReport = new AvlReport(vehicleId, time, lat, lon, speed, heading, "CSV", leadVehicleId,
            driverId, licensePlate, passengerCount, passengerFullness);

    // Assignment info
    String assignmentId = avlCsvRecord.getOptionalValue(record, "assignmentId");
    String assignmentTypeStr = avlCsvRecord.getOptionalValue(record, "assignmentType");
    AssignmentType assignmentType;
    if (assignmentId != null && assignmentTypeStr != null) {
        if (assignmentTypeStr.equals("BLOCK_ID"))
            assignmentType = AssignmentType.BLOCK_ID;
        else if (assignmentTypeStr.equals("ROUTE_ID"))
            assignmentType = AssignmentType.ROUTE_ID;
        else if (assignmentTypeStr.equals("TRIP_ID"))
            assignmentType = AssignmentType.TRIP_ID;
        else if (assignmentTypeStr.equals("TRIP_SHORT_NAME"))
            assignmentType = AssignmentType.TRIP_SHORT_NAME;
        else
            assignmentType = AssignmentType.UNSET;
        avlReport.setAssignment(assignmentId, assignmentType);
    }

    return avlReport;
}

From source file:juicebox.matrix.InMemoryMatrix.java

public void setEntry(int row, int col, float value) {

    int idx = row * dim + col;
    data[idx] = value;// ww w .j  av a  2  s  .c o  m

    // Invalidate bounds
    lowerValue = Float.NaN;
    upperValue = Float.NaN;

}