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:org.bitpipeline.lib.owm.WeatherHistoryStationResponse.java

/** 
 * @param json a JSON object built from the response */
public WeatherHistoryStationResponse(JSONObject json) {
    super(json);/*from   w w  w . j ava  2s . co m*/

    this.stationId = json.optInt(WeatherHistoryStationResponse.JSON_STATION_ID, Integer.MIN_VALUE);

    OwmClient.HistoryType typeValue = null;
    String typeStr = json.optString(WeatherHistoryStationResponse.JSON_TYPE);
    if (typeStr != null && typeStr.length() > 0) {
        try {
            typeValue = OwmClient.HistoryType.valueOf(typeStr.trim().toUpperCase());
        } catch (IllegalArgumentException e) {
            typeValue = OwmClient.HistoryType.UNKNOWN;
        }
    }
    this.type = typeValue;

    if (this.type == OwmClient.HistoryType.TICK) {
        String calcTimeStr = json.optString(AbstractOwmResponse.JSON_CALCTIME);
        this.calctimeTick = AbstractOwmResponse.getValueFromCalcTimeStr(calcTimeStr,
                WeatherHistoryStationResponse.JSON_CALCTIME_TICK);
    } else {
        this.calctimeTick = Float.NaN;
    }

    JSONArray jsonHistory = json.optJSONArray(AbstractOwmResponse.JSON_LIST);
    if (jsonHistory == null) {
        this.history = Collections.emptyList();
    } else {
        this.history = new ArrayList<AbstractWeatherData>(jsonHistory.length());
        switch (this.type) {
        case TICK:
            for (int i = 0; i < jsonHistory.length(); i++) {
                JSONObject jsonBaseWeatherData = jsonHistory.optJSONObject(i);
                if (jsonBaseWeatherData != null) {
                    this.history.add(new WeatherData(jsonBaseWeatherData));
                }
            }
            break;
        case HOUR:
        case DAY:
            for (int i = 0; i < jsonHistory.length(); i++) {
                JSONObject jsonBaseWeatherData = jsonHistory.optJSONObject(i);
                if (jsonBaseWeatherData != null) {
                    this.history.add(new SampledWeatherData(jsonBaseWeatherData));
                }
            }
            break;
        default:
            break;
        }
    }

}

From source file:uk.ac.soton.itinnovation.ecc.service.utils.MetricCalculator.java

public static float calcORDINALMedianValuePosition(MeasurementSet mSet) {
    float result = Float.NaN;

    if (mSet != null) {
        // Check semantics before trying calculation
        Metric metric = mSet.getMetric();

        if (metric != null && metric.getMetricType() == MetricType.ORDINAL
                && !metric.getMetaType().equals("Unknown")) {
            // Initialise scale map
            HashMap<String, Integer> ordMap = new HashMap<>();

            String[] orderedItems = metric.getMetaContent().split(",");
            int index = 0;
            for (String ordItem : orderedItems) {
                ordMap.put(ordItem, index);
                ++index;/*from  ww w.java 2  s .c  om*/
            }

            // Create distribution map of values
            TreeSet<Integer> medMap = new TreeSet<>();

            for (Measurement m : mSet.getMeasurements()) {
                Integer order = ordMap.get(m.getValue());
                if (order != null)
                    medMap.add(order);
            }

            // Create sorted list of results
            ArrayList<Integer> medList = new ArrayList();
            Iterator<Integer> medIt = medMap.iterator();

            while (medIt.hasNext())
                medList.add(medIt.next());

            // If we have items to work with, find the median
            if (!medList.isEmpty()) {
                int medListSize = medList.size();

                // Single item ---------------------------------------------
                if (medListSize == 1)
                    result = medList.get(0);

                // Two items -----------------------------------------------
                else if (medListSize == 2) {
                    // If the values are the same, return the index
                    if (medList.get(0).compareTo(medList.get(1)) == 0)
                        result = medList.get(0);
                    else
                        // Otherwise return point in the middle
                        result = (float) medList.get(1) / (float) medList.get(0);
                }
                // More than two items -------------------------------------
                else {
                    int middle = medListSize / 2;

                    // Even number of items means checking centre two values
                    if (medListSize % 2 == 0) {
                        // If the values are the same, return the index
                        if (medList.get(middle).compareTo(medList.get(middle - 1)) == 0)
                            result = medList.get(middle);
                        else
                            // Otherwise return point in the middle
                            result = (float) medList.get(middle) / (float) medList.get(middle - 1);
                    }
                    // Odd number of items resolves to centre
                    else
                        result = middle;
                }
            }
        }
    }

    return result;
}

From source file:com.facebook.react.views.drawer.ReactDrawerLayoutManager.java

@ReactProp(name = "drawerWidth", defaultFloat = Float.NaN)
public void getDrawerWidth(ReactDrawerLayout view, float width) {
    int widthInPx = Float.isNaN(width) ? ReactDrawerLayout.DEFAULT_DRAWER_WIDTH
            : Math.round(PixelUtil.toPixelFromDIP(width));
    view.setDrawerWidth(widthInPx);/*from w w w . j a  va  2 s  . c  om*/
}

From source file:uk.ac.diamond.scisoft.analysis.io.SRSLoaderTest.java

/**
 * This method tests for SciSoft trac #496
 *///w  ww . ja  va 2  s  .  c o m
@Test
public void testSS49() {
    try {
        DataHolder dh;
        String testfile1 = "testfiles/gda/analysis/io/SRSLoaderTest/96356.dat";
        dh = new SRSLoader(testfile1).loadFile();

        // now the file is loaded, check to make sure that it holds the right data
        assertEquals("There is not the correct number of axis in the file", 7, dh.size());
        int dt = dh.getDataset(6).getDtype();
        if (dt == Dataset.FLOAT32)
            assertEquals("The file does not contain NANs", Float.NaN, dh.getDataset(6).getDouble(1), 10.);
        if (dt == Dataset.FLOAT64)
            assertEquals("The file does not contain NANs", Double.NaN, dh.getDataset(6).getDouble(1), 10.);
        assertEquals("The file does not contain data as well", 0.1, dh.getDataset(0).getDouble(1), 1.);
    } catch (ScanFileHolderException e) {
        fail("Couldn't load the file");
    }

}

From source file:juicebox.matrix.SymmetricMatrix.java

public float getColumnMean(int j) {
    float sum = 0;
    int count = 0;
    for (int i = 0; i < dim; i++) {
        float value = getEntry(i, j);
        if (!Float.isNaN(value)) {
            sum += value;/* w  w  w.  jav a 2 s.co  m*/
            count++;
        }
    }
    return count == 0 ? Float.NaN : sum / count;
}

From source file:org.esa.snap.core.jexp.impl.ExtMath.java

/**
 * Computes the signum of a given number. The method returns
 * <ul>//from w w  w .j av a  2s  . co m
 * <li>-1, if a is negative</li>
 * <li>+1, if a is positive</li>
 * <li>0, if a is zero</li>
 * <li>NaN, if a is NaN.</li>
 * </ul>
 *
 * @param a the number
 *
 * @return the signum of a
 */
public static float sign(float a) {
    if (Float.isNaN(a)) {
        return Float.NaN;
    }
    return a == 0.0f ? 0.0f : (a < 0.0f ? -1.0f : 1.0f);
}

From source file:com.streamsets.pipeline.stage.it.AvroToParquetHiveIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] {
            // Primitive types
            { "\"boolean\"", true, true, "BOOLEAN", Types.BOOLEAN, "0" },
            { "\"int\"", Integer.MIN_VALUE, Integer.MIN_VALUE, "INT", Types.INTEGER, "0" },
            { "\"long\"", Long.MAX_VALUE, Long.MAX_VALUE, "BIGINT", Types.BIGINT, "0" },
            // From some reason type is FLOAT, but returned object is double
            { "\"float\"", Float.NaN, Double.NaN, "FLOAT", Types.FLOAT, "0" },
            { "\"double\"", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, "DOUBLE", Types.DOUBLE, "0" },
            { "\"bytes\"", ByteBuffer.wrap(new byte[] { (byte) 0x00, (byte) 0xFF }),
                    new byte[] { (byte) 0x00, (byte) 0xFF }, "BINARY", Types.BINARY, "1.0" },
            { "\"string\"", new Utf8("StreamSets"), "StreamSets", "STRING", Types.VARCHAR, "1.0" },

            // Complex types are skipped for now

            // Logical types
            { DECIMAL.toString(), ByteBuffer.wrap(new byte[] { (byte) 0x0F }), new BigDecimal("2"), "DECIMAL",
                    Types.DECIMAL, "0" },
            { DATE.toString(), 17039, new java.sql.Date(116, 7, 26), "DATE", Types.DATE, "1.2" }, });
}

From source file:com.taobao.weex.utils.WXUtils.java

public static float getFloat(Object value) {
    return getFloat(value, Float.NaN);
}

From source file:org.apache.flink.graph.library.metric.undirected.VertexMetricsTest.java

@Test
public void testWithEmptyGraph() throws Exception {
    Result expectedResult;//from   ww w . j  a va  2s. c om

    expectedResult = new Result(0, 0, 0, 0, 0);

    Result withoutZeroDegreeVertices = new VertexMetrics<LongValue, NullValue, NullValue>()
            .setIncludeZeroDegreeVertices(false).run(emptyGraph).execute();

    assertEquals(expectedResult, withoutZeroDegreeVertices);
    assertEquals(Float.NaN, withoutZeroDegreeVertices.getAverageDegree(), ACCURACY);
    assertEquals(Float.NaN, withoutZeroDegreeVertices.getDensity(), ACCURACY);

    expectedResult = new Result(3, 0, 0, 0, 0);

    Result withZeroDegreeVertices = new VertexMetrics<LongValue, NullValue, NullValue>()
            .setIncludeZeroDegreeVertices(true).run(emptyGraph).execute();

    assertEquals(expectedResult, withZeroDegreeVertices);
    assertEquals(0.0f, withZeroDegreeVertices.getAverageDegree(), ACCURACY);
    assertEquals(0.0f, withZeroDegreeVertices.getDensity(), ACCURACY);
}

From source file:org.apache.flink.graph.library.metric.directed.VertexMetricsTest.java

@Test
public void testWithEmptyGraph() throws Exception {
    Result expectedResult;/*from  w w  w .j  a  v a2 s.c om*/

    expectedResult = new Result(0, 0, 0, 0, 0, 0, 0, 0);

    Result withoutZeroDegreeVertices = new VertexMetrics<LongValue, NullValue, NullValue>()
            .setIncludeZeroDegreeVertices(false).run(emptyGraph).execute();

    assertEquals(expectedResult, withoutZeroDegreeVertices);
    assertEquals(Float.NaN, withoutZeroDegreeVertices.getAverageDegree(), ACCURACY);
    assertEquals(Float.NaN, withoutZeroDegreeVertices.getDensity(), ACCURACY);

    expectedResult = new Result(3, 0, 0, 0, 0, 0, 0, 0);

    Result withZeroDegreeVertices = new VertexMetrics<LongValue, NullValue, NullValue>()
            .setIncludeZeroDegreeVertices(true).run(emptyGraph).execute();

    assertEquals(expectedResult, withZeroDegreeVertices);
    assertEquals(0.0f, withZeroDegreeVertices.getAverageDegree(), ACCURACY);
    assertEquals(0.0f, withZeroDegreeVertices.getDensity(), ACCURACY);
}