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:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#add(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *//*  w w  w.j  a v  a 2 s.co m*/
@SuppressWarnings("unchecked")
@Test
public void testAddObjectNumberClassOfT() {
    assertEquals("null", null, add(null, null, null));
    assertEquals("null", null, add("123.456", null, null));
    assertEquals("null", null, add("123.456", 1, null));
    assertEquals("null", null, add("", 10, null));
    assertEquals("null", null, add(null, 10, null));
    assertEquals("null", null, add(123.456, 10, null));
    assertEquals("123 + .456: Float", (Object) 123.456f, add(123, .456, Float.class));
    assertEquals("123 + .456: Float", (Object) Float.class, add(123, .456, Float.class).getClass());
    assertEquals("123 + .456: Float", (Object) Float.class, add(123L, .456d, Float.class).getClass());
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            assertEquals("null: default: " + type.getSimpleName(), valueOf(null, typeOfN),
                    add(null, null, typeOfN));
            assertEquals("123.456: " + type.getSimpleName(), valueOf(123 + .456, typeOfN),
                    add("123", .456, typeOfN));
            assertEquals("NaN + 123: " + type.getSimpleName(), valueOf(123, typeOfN), add("NaN", 123, typeOfN));
            assertEquals("123 + NaN: " + type.getSimpleName(), valueOf("123", typeOfN),
                    add("123", Float.NaN, typeOfN));
            assertEquals("invalid + 123: " + type.getSimpleName(), valueOf(123, typeOfN),
                    add("not a number", 123, typeOfN));
            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("-Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("-Infinity", 123, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("Infinity", 123, typeOfN));

            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 - Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.NEGATIVE_INFINITY, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 + Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.POSITIVE_INFINITY, typeOfN));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:com.example.appf.CS3570.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
        mGyroscopeEvent = event.values;/*www  .  j ava 2 s .c o  m*/
    }
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        mGravity = event.values;

    if (mGravity != null && mGyroscopeEvent != null && mGLView != null && mGLView.mRenderer.mTetra != null) {
        filter.updateFilter(mGyroscopeEvent[0], mGyroscopeEvent[1], mGyroscopeEvent[2], mGravity[0],
                mGravity[1], mGravity[2]);
        filter.computerEuler();
        azimut = (float) filter.getYaw(); // orientation contains: azimut, pitch and roll
        pitch = (float) filter.getPitch();
        roll = (float) filter.getRoll();

        if (previousAzimuth == Float.MAX_VALUE) {
            previousAzimuth = azimut;
        }
        if (previousPitch == Float.MAX_VALUE) {
            previousPitch = pitch;
        }
        if (previousRoll == Float.MAX_VALUE) {
            previousRoll = roll;
        }

        float delta_azimut = azimut - previousAzimuth;
        float delta_pitch = pitch - previousPitch;
        float delta_roll = roll - previousRoll;
        //Log.e("eee", "Azimuth: "+ delta_azimut + " pitch: " + delta_pitch + " roll: " + delta_roll);
        //Log.e("eee", " roll: " + roll);
        //Log.e("eee", "Azimuth: " + azimut + " pitch: " + pitch + " roll: " + roll);

        if (Math.abs(delta_roll) > THRESHOLD && roll != Float.NaN) {
            previousRoll = roll;
            if (cam)
                mGLView.mRenderer.mCamera.rotateX(delta_roll * 180.0 / Math.PI * ROTATE_AMPLIFY);
            //mGLView.mRenderer.mTetra.rotate((float) (delta_roll * 180.0 / Math.PI) * ROTATE_AMPLIFY, 1, 0, 0);
            else
                mGLView.mRenderer.mTetra.pure_rotate((float) ((roll + Math.PI) * 180.0 / Math.PI), 1, 0, 0);
        }

        if (Math.abs(delta_pitch) > THRESHOLD && pitch != Float.NaN) {
            previousPitch = pitch;
            if (cam)
                mGLView.mRenderer.mCamera.rotateX(delta_pitch * 180.0 / Math.PI * ROTATE_AMPLIFY);
            //Log.e("eee", "" + ((delta_pitch)* 180.0 / Math.PI) );
            else
                mGLView.mRenderer.mTetra.pure_rotate((float) ((pitch + Math.PI) * 180.0 / Math.PI), 0, 1, 0);

        }

        if (Math.abs(delta_azimut) > THRESHOLD && azimut != Float.NaN) {
            previousAzimuth = azimut;
            if (cam)
                mGLView.mRenderer.mCamera.rotateY(delta_azimut * 180.0 / Math.PI * ROTATE_AMPLIFY);
            else
                //mGLView.mRenderer.mTetra.rotate((float)(delta_azimut * 180.0/Math.PI) * ROTATE_AMPLIFY, 0, 0, 1 );
                mGLView.mRenderer.mTetra.pure_rotate((float) (azimut * 180.0 / Math.PI), 0, 0, 1);
        }

        if (out != null) {
            //Log.e("eee", "{pitch:" + pitch + "}");
            Vector3 cam_pos = mGLView.mRenderer.mCamera.get_position();
            out.println("{\"pitch\":" + pitch + ", \"roll\": " + roll + ", \"yaw\": " + azimut
                    + ", \"translation\": [" + cam_pos.getX() + ", " + cam_pos.getY() + "," + cam_pos.getZ()
                    + "]}\0");
        }
        mGLView.requestRender();
    }

}

From source file:org.broad.igv.Accumulator.java

public float getValue(WindowFunction wf) {

    switch (wf) {
    case mean:/*from  w ww . ja v  a  2  s  .  c om*/
        return mean;
    case median:
        return median;
    case min:
        return min;
    case max:
        return max;
    case percentile2:
        return percentile2;
    case percentile10:
        return percentile10;
    case percentile90:
        return percentile90;
    case percentile98:
        return percentile98;
    case count:
        return nPts;
    default:
        System.err.println("Unexpected window function: " + wf.toString());

    }
    return Float.NaN;

}

From source file:org.apache.predictionio.examples.java.recommendations.tutorial4.CollaborativeFilteringAlgorithm.java

@Override
public Float predict(CollaborativeFilteringModel model, Query query) {
    RealVector itemVector = model.itemSimilarity.get(query.iid);
    RealVector userVector = model.userHistory.get(query.uid);
    if (itemVector == null) {
        // cold start item, can't be handled by this algo, return hard code value.
        return Float.NaN;
    } else if (userVector == null) {
        // new user, can't be handled by this algo, return hard code value.
        return Float.NaN;
    } else {/*from w w w .j a  va2  s  . c o m*/
        //logger.info("(" + query.uid + "," + query.iid + ")");
        //logger.info(itemVector.toString());
        //logger.info(userVector.toString());
        double accum = 0.0;
        double accumSim = 0.0;
        for (int i = 0; i < itemVector.getDimension(); i++) {
            double weight = itemVector.getEntry(i);
            double rating = userVector.getEntry(i);
            if ((weight != 0) && (rating != 0)) {
                accum += weight * rating;
                accumSim += Math.abs(weight);
            }
        }

        if (accumSim == 0.0) {
            return Float.NaN;
        } else {
            return (float) (accum / accumSim);
        }
    }
}

From source file:com.choicemaker.cm.modelmaker.gui.panels.HoldVsAccuracyPlotPanel.java

private void display() {
    com.choicemaker.cm.modelmaker.stats.Statistics stats = parent.getModelMaker().getStatistics();
    StatPoint ptb = new StatPoint();
    ptb.humanReview = 0f;/*www . java 2s .com*/
    stats.computeStatPoint(ptb);
    float from = Math.max(0.001f,
            Math.min(0.1f, Float.isNaN(ptb.falseNegatives) || Float.isNaN(ptb.falsePositives) ? Float.MAX_VALUE
                    : Math.max(ptb.falseNegatives, ptb.falsePositives)));
    int numPoints = 101;
    float step = from / (numPoints - 1);
    errorRates = new float[numPoints];
    for (int i = 0; i < numPoints; ++i) {
        errorRates[i] = from - i * step;
    }
    dirty = false;
    if (parent.isEvaluated()) {
        reset();
        float[][] res = stats.getHoldPercentageVsAccuracy(errorRates);
        final int len = res.length;
        float lastX = Float.NaN;
        for (int i = 0; i < len; ++i) {
            final float hr = 100 * res[i][1];
            final float x = 100f - 100 * res[i][0];
            if (!Float.isNaN(x) && x != lastX && !Float.isNaN(hr)) {
                data.add(x, hr);
                lastX = x;
            }
        }
    }
    accuracyData = stats.getHoldPercentageVsAccuracy(accErrs);
    accuracyTable.refresh(accuracyData);
    StatPoint pt = new StatPoint();
    hrData = new float[hrs.length][4];
    for (int i = 0; i < hrs.length; ++i) {
        pt.reset();
        pt.humanReview = hrs[i];
        stats.computeStatPoint(pt);
        hrData[i][0] = hrs[i];
        hrData[i][1] = 1f - (pt.falseNegatives + pt.falsePositives) / 2;
        hrData[i][2] = pt.differThreshold;
        hrData[i][3] = pt.matchThreshold;
    }
    hrTable.refresh(hrData);
    accuracyTable.setEnabled(true);
    hrTable.setEnabled(true);
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat32EncodeNaN() throws IOException {
    StringWriter out = new StringWriter();
    JsonGenerator g = f.createGenerator(out);

    JsonValueHandler.FLOAT32.writeValue(Float.NaN, g);
    g.flush();/*from  w  w  w . j a va 2s  .  c  o  m*/
    assertEquals("\"NaN\"", out.toString());
}

From source file:p5e610.graphview.series.LineGraphSeries.java

/**
 * plots the series//from w  w w .j  a v a2 s  .c  o  m
 * draws the line and the background
 *
 * @param graphView graphview
 * @param canvas canvas
 * @param isSecondScale flag if it is the second scale
 */
@Override
public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) {
    resetDataPoints();

    // get data
    double maxY = Double.NEGATIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double minX = Double.POSITIVE_INFINITY;

    boolean minXSet = graphView.getViewport().getMinX(false) != null;
    boolean maxXSet = graphView.getViewport().getMaxX(false) != null;
    boolean minYSet = graphView.getViewport().getMinY(false) != null;
    boolean maxYSet = graphView.getViewport().getMaxY(false) != null;

    if (minXSet)
        minX = graphView.getViewport().getMinX(false);
    if (maxXSet) {
        maxX = graphView.getViewport().getMaxX(false);
    }
    if (minYSet) {
        minY = graphView.getViewport().getMinY(false);
    }
    if (maxYSet) {
        maxY = graphView.getViewport().getMaxY(false);
    }

    for (E val : mData) {
        double currX = val.getX();
        double currY = val.getY();

        if (currX > maxX && !maxXSet)
            maxX = currX;
        if (currY > maxY && !maxYSet)
            maxY = currY;
        if (currX < minX && !minXSet)
            minX = currX;
        if (currY < minY && !minYSet)
            minY = currY;
    }

    Iterator<E> values = getValues(minX, maxX);

    // draw background
    double lastEndY = 0;
    double lastEndX = 0;

    // draw data
    mPaint.setStrokeWidth(mStyles.thickness);
    mPaint.setColor(getColor());
    mPaintBackground.setColor(mStyles.backgroundColor);

    Paint paint;
    if (mCustomPaint != null) {
        paint = mCustomPaint;
    } else {
        paint = mPaint;
    }

    mPath.reset();

    if (mStyles.drawBackground) {
        mPathBackground.reset();
    }

    double diffY = maxY - minY;
    double diffX = maxX - minX;

    float graphHeight = graphView.getGraphContentHeight();
    float graphWidth = graphView.getGraphContentWidth();
    float graphLeft = graphView.getGraphContentLeft();
    float graphTop = graphView.getGraphContentTop();

    lastEndY = 0;
    lastEndX = 0;

    // needed to end the path for background
    double lastUsedEndX = 0;
    double lastUsedEndY = 0;
    float firstX = -1;
    float firstY = -1;
    float lastRenderedX = Float.NaN;
    int i = 0;
    float lastAnimationReferenceX = graphLeft;

    boolean sameXSkip = false;
    float minYOnSameX = 0f;
    float maxYOnSameX = 0f;

    while (values.hasNext()) {
        E value = values.next();

        double valY = value.getY() - minY;
        double ratY = valY / diffY;
        double y = graphHeight * ratY;

        double valueX = value.getX();
        double valX = valueX - minX;
        double ratX = valX / diffX;
        double x = graphWidth * ratX;

        double orgX = x;
        double orgY = y;

        if (i > 0) {
            // overdraw
            boolean isOverdrawY = false;
            boolean isOverdrawEndPoint = false;
            boolean skipDraw = false;

            if (x > graphWidth) { // end right
                double b = ((graphWidth - lastEndX) * (y - lastEndY) / (x - lastEndX));
                y = lastEndY + b;
                x = graphWidth;
                isOverdrawEndPoint = true;
            }
            if (y < 0) { // end bottom
                // skip when previous and this point is out of bound
                if (lastEndY < 0) {
                    skipDraw = true;
                } else {
                    double b = ((0 - lastEndY) * (x - lastEndX) / (y - lastEndY));
                    x = lastEndX + b;
                }
                y = 0;
                isOverdrawY = isOverdrawEndPoint = true;
            }
            if (y > graphHeight) { // end top
                // skip when previous and this point is out of bound
                if (lastEndY > graphHeight) {
                    skipDraw = true;
                } else {
                    double b = ((graphHeight - lastEndY) * (x - lastEndX) / (y - lastEndY));
                    x = lastEndX + b;
                }
                y = graphHeight;
                isOverdrawY = isOverdrawEndPoint = true;
            }
            if (lastEndX < 0) { // start left
                double b = ((0 - x) * (y - lastEndY) / (lastEndX - x));
                lastEndY = y - b;
                lastEndX = 0;
            }

            // we need to save the X before it will be corrected when overdraw y
            float orgStartX = (float) lastEndX + (graphLeft + 1);

            if (lastEndY < 0) { // start bottom
                if (!skipDraw) {
                    double b = ((0 - y) * (x - lastEndX) / (lastEndY - y));
                    lastEndX = x - b;
                }
                lastEndY = 0;
                isOverdrawY = true;
            }
            if (lastEndY > graphHeight) { // start top
                // skip when previous and this point is out of bound
                if (!skipDraw) {
                    double b = ((graphHeight - y) * (x - lastEndX) / (lastEndY - y));
                    lastEndX = x - b;
                }
                lastEndY = graphHeight;
                isOverdrawY = true;
            }

            float startX = (float) lastEndX + (graphLeft + 1);
            float startY = (float) (graphTop - lastEndY) + graphHeight;
            float endX = (float) x + (graphLeft + 1);
            float endY = (float) (graphTop - y) + graphHeight;
            float startXAnimated = startX;
            float endXAnimated = endX;

            //                if (endX < startX) {
            //                    // dont draw from right to left
            //                    skipDraw = true;
            //                }

            // NaN can happen when previous and current value is out of y bounds
            if (!skipDraw && !Float.isNaN(startY) && !Float.isNaN(endY)) {
                // animation
                if (mAnimated) {
                    if ((Double.isNaN(mLastAnimatedValue) || mLastAnimatedValue < valueX)) {
                        long currentTime = System.currentTimeMillis();
                        if (mAnimationStart == 0) {
                            // start animation
                            mAnimationStart = currentTime;
                            mAnimationStartFrameNo = 0;
                        } else {
                            // anti-lag: wait a few frames
                            if (mAnimationStartFrameNo < 15) {
                                // second time
                                mAnimationStart = currentTime;
                                mAnimationStartFrameNo++;
                            }
                        }
                        float timeFactor = (float) (currentTime - mAnimationStart) / ANIMATION_DURATION;
                        float factor = mAnimationInterpolator.getInterpolation(timeFactor);
                        if (timeFactor <= 1.0) {
                            startXAnimated = (startX - lastAnimationReferenceX) * factor
                                    + lastAnimationReferenceX;
                            startXAnimated = Math.max(startXAnimated, lastAnimationReferenceX);
                            endXAnimated = (endX - lastAnimationReferenceX) * factor + lastAnimationReferenceX;
                            ViewCompat.postInvalidateOnAnimation(graphView);
                        } else {
                            // animation finished
                            mLastAnimatedValue = valueX;
                        }
                    } else {
                        lastAnimationReferenceX = endX;
                    }
                }

                // draw data point
                if (!isOverdrawEndPoint) {
                    if (mStyles.drawDataPoints) {
                        // draw first datapoint
                        Paint.Style prevStyle = paint.getStyle();
                        paint.setStyle(Paint.Style.FILL);
                        canvas.drawCircle(endXAnimated, endY, mStyles.dataPointsRadius, paint);
                        paint.setStyle(prevStyle);
                    }
                    registerDataPoint(endX, endY, value);
                }

                if (mDrawAsPath) {
                    mPath.moveTo(startXAnimated, startY);
                }
                // performance opt.
                if (Float.isNaN(lastRenderedX) || Math.abs(endX - lastRenderedX) > .3f) {
                    if (mDrawAsPath) {
                        mPath.lineTo(endXAnimated, endY);
                    } else {
                        // render vertical lines that were skipped
                        if (sameXSkip) {
                            sameXSkip = false;
                            renderLine(canvas,
                                    new float[] { lastRenderedX, minYOnSameX, lastRenderedX, maxYOnSameX },
                                    paint);
                        }
                        renderLine(canvas, new float[] { startXAnimated, startY, endXAnimated, endY }, paint);
                    }
                    lastRenderedX = endX;
                } else {
                    // rendering on same x position
                    // save min+max y position and render it as line
                    if (sameXSkip) {
                        minYOnSameX = Math.min(minYOnSameX, endY);
                        maxYOnSameX = Math.max(maxYOnSameX, endY);
                    } else {
                        // first
                        sameXSkip = true;
                        minYOnSameX = Math.min(startY, endY);
                        maxYOnSameX = Math.max(startY, endY);
                    }
                }

            }

            if (mStyles.drawBackground) {
                if (isOverdrawY) {
                    // start draw original x
                    if (firstX == -1) {
                        firstX = orgStartX;
                        firstY = startY;
                        mPathBackground.moveTo(orgStartX, startY);
                    }
                    // from original start to new start
                    mPathBackground.lineTo(startXAnimated, startY);
                }
                if (firstX == -1) {
                    firstX = startXAnimated;
                    firstY = startY;
                    mPathBackground.moveTo(startXAnimated, startY);
                }
                mPathBackground.lineTo(startXAnimated, startY);
                mPathBackground.lineTo(endXAnimated, endY);
            }

            lastUsedEndX = endXAnimated;
            lastUsedEndY = endY;
        } else if (mStyles.drawDataPoints) {
            //fix: last value not drawn as datapoint. Draw first point here, and then on every step the end values (above)
            float first_X = (float) x + (graphLeft + 1);
            float first_Y = (float) (graphTop - y) + graphHeight;

            if (first_X >= graphLeft && first_Y <= (graphTop + graphHeight)) {
                if (mAnimated && (Double.isNaN(mLastAnimatedValue) || mLastAnimatedValue < valueX)) {
                    long currentTime = System.currentTimeMillis();
                    if (mAnimationStart == 0) {
                        // start animation
                        mAnimationStart = currentTime;
                    }
                    float timeFactor = (float) (currentTime - mAnimationStart) / ANIMATION_DURATION;
                    float factor = mAnimationInterpolator.getInterpolation(timeFactor);
                    if (timeFactor <= 1.0) {
                        first_X = (first_X - lastAnimationReferenceX) * factor + lastAnimationReferenceX;
                        ViewCompat.postInvalidateOnAnimation(graphView);
                    } else {
                        // animation finished
                        mLastAnimatedValue = valueX;
                    }
                }

                Paint.Style prevStyle = paint.getStyle();
                paint.setStyle(Paint.Style.FILL);
                canvas.drawCircle(first_X, first_Y, mStyles.dataPointsRadius, paint);
                paint.setStyle(prevStyle);
            }
        }
        lastEndY = orgY;
        lastEndX = orgX;
        i++;
    }

    if (mDrawAsPath) {
        // draw at the end
        canvas.drawPath(mPath, paint);
    }

    if (mStyles.drawBackground && firstX != -1) {
        // end / close path
        if (lastUsedEndY != graphHeight + graphTop) {
            // dont draw line to same point, otherwise the path is completely broken
            mPathBackground.lineTo((float) lastUsedEndX, graphHeight + graphTop);
        }
        mPathBackground.lineTo(firstX, graphHeight + graphTop);
        if (firstY != graphHeight + graphTop) {
            // dont draw line to same point, otherwise the path is completely broken
            mPathBackground.lineTo(firstX, firstY);
        }
        //mPathBackground.close();
        canvas.drawPath(mPathBackground, mPaintBackground);
    }
}

From source file:com.epam.catgenome.manager.bed.parser.NggbBedCodec.java

private void parseAndSetScore(String[] tokens, int tokenCount, NggbSimpleBedFeature feature) {
    if (tokenCount > SCORE_OFFSET && NumberUtils.isNumber(tokens[SCORE_OFFSET])) {
        try {//from ww  w  .  ja  va  2  s .c  om
            float score = Float.parseFloat(tokens[SCORE_OFFSET]);
            feature.setScore(score);
        } catch (NumberFormatException numberFormatException) {
            feature.setScore(Float.NaN);
        }
    }
}

From source file:au.org.ala.layers.grid.GridCacheBuilder.java

static public float getNextValue(RandomAccessFile raf, Grid g) {
    float f = Float.NaN;
    try {//w  ww  . j a  v  a2s .  co m
        int size;
        byte[] b;
        if (g.datatype.charAt(0) == 'B') {//"BYTE")) {
            f = raf.readByte();
        } else if (g.datatype.charAt(0) == 'U') {//equalsIgnoreCase("UBYTE")) {
            f = raf.readByte();
            if (f < 0) {
                f += 256;
            }
        } else if (g.datatype.charAt(0) == 'S') {//equalsIgnoreCase("SHORT")) {
            size = 2;
            b = new byte[size];
            raf.read(b);
            if (g.byteorderLSB) {
                f = (short) (((0xFF & b[1]) << 8) | (b[0] & 0xFF));
            } else {
                f = (short) (((0xFF & b[0]) << 8) | (b[1] & 0xFF));
            }
        } else if (g.datatype.charAt(0) == 'I') {//equalsIgnoreCase("INT")) {
            size = 4;
            b = new byte[size];
            raf.read(b);
            if (g.byteorderLSB) {
                f = ((0xFF & b[3]) << 24) | ((0xFF & b[2]) << 16) + ((0xFF & b[1]) << 8) + (b[0] & 0xFF);
            } else {
                f = ((0xFF & b[0]) << 24)
                        | ((0xFF & b[1]) << 16) + ((0xFF & b[2]) << 8) + ((0xFF & b[3]) & 0xFF);
            }
        } else if (g.datatype.charAt(0) == 'L') {//equalsIgnoreCase("LONG")) {
            size = 8;
            b = new byte[size];
            raf.read(b);
            if (g.byteorderLSB) {
                f = ((long) (0xFF & b[7]) << 56) + ((long) (0xFF & b[6]) << 48) + ((long) (0xFF & b[5]) << 40)
                        + ((long) (0xFF & b[4]) << 32) + ((long) (0xFF & b[3]) << 24)
                        + ((long) (0xFF & b[2]) << 16) + ((long) (0xFF & b[1]) << 8) + (0xFF & b[0]);
            } else {
                f = ((long) (0xFF & b[0]) << 56) + ((long) (0xFF & b[1]) << 48) + ((long) (0xFF & b[2]) << 40)
                        + ((long) (0xFF & b[3]) << 32) + ((long) (0xFF & b[4]) << 24)
                        + ((long) (0xFF & b[5]) << 16) + ((long) (0xFF & b[6]) << 8) + (0xFF & b[7]);
            }
        } else if (g.datatype.charAt(0) == 'F') {//.equalsIgnoreCase("FLOAT")) {
            size = 4;
            b = new byte[size];
            raf.read(b);
            ByteBuffer bb = ByteBuffer.wrap(b);
            if (g.byteorderLSB) {
                bb.order(ByteOrder.LITTLE_ENDIAN);
            }
            f = bb.getFloat();

        } else if (g.datatype.charAt(0) == 'D') {//.equalsIgnoreCase("DOUBLE")) {
            size = 8;
            b = new byte[8];
            raf.read(b);
            ByteBuffer bb = ByteBuffer.wrap(b);
            if (g.byteorderLSB) {
                bb.order(ByteOrder.LITTLE_ENDIAN);
            }
            f = (float) bb.getDouble();
        }
        //replace not a number            
        if ((float) f == (float) g.nodatavalue) {
            f = Float.NaN;
        }
    } catch (Exception e) {
    }
    return f;
}

From source file:io.anserini.search.SearchCollection.java

public <K> ScoredDocuments search(IndexSearcher searcher, K qid, String queryString) throws IOException {
    Query query = AnalyzerUtils.buildBagOfWordsQuery(FIELD_BODY, analyzer, queryString);

    TopDocs rs = new TopDocs(0, new ScoreDoc[] {}, Float.NaN);
    if (!(isRerank && args.rerankcutoff <= 0)) {
        if (args.arbitraryScoreTieBreak) {// Figure out how to break the scoring ties.
            rs = searcher.search(query, isRerank ? args.rerankcutoff : args.hits);
        } else {/*from   w  w w  .ja  va 2  s  .c om*/
            rs = searcher.search(query, isRerank ? args.rerankcutoff : args.hits, BREAK_SCORE_TIES_BY_DOCID,
                    true, true);
        }
    }

    List<String> queryTokens = AnalyzerUtils.tokenize(analyzer, queryString);
    RerankerContext context = new RerankerContext<>(searcher, qid, query, queryString, queryTokens, null, args);

    return cascade.run(ScoredDocuments.fromTopDocs(rs, searcher), context);
}