Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

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

Prototype

public static boolean isNaN(float v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:com.frank.search.solr.repository.query.SolrQueryCreator.java

private Criteria appendBoost(Criteria criteria, BindableSolrParameter parameter) {
    if (!Float.isNaN(parameter.getBoost())) {
        criteria.boost(parameter.getBoost());
    }/*from w  ww .ja v a 2s .c  o  m*/
    return criteria;
}

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;// w  w w . j ava  2  s  .c om
    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:au.org.ala.layers.grid.GridCacheBuilder.java

private static void writeGroupGRI(File file, ArrayList<Grid> group) {
    Grid g = group.get(0);// w  w  w  .j  av a  2 s  .  co  m
    RandomAccessFile[] raf = new RandomAccessFile[group.size()];
    RandomAccessFile output = null;

    try {
        output = new RandomAccessFile(file, "rw");

        for (int i = 0; i < group.size(); i++) {
            raf[i] = new RandomAccessFile(group.get(i).filename + ".gri", "r");
        }

        int length = g.ncols * g.nrows;
        int size = 4;
        byte[] b = new byte[size * group.size() * g.ncols];
        float noDataValue = Float.MAX_VALUE * -1;

        byte[] bi = new byte[g.ncols * 8];
        float[][] rows = new float[group.size()][g.ncols];

        for (int i = 0; i < g.nrows; i++) {
            //read
            for (int j = 0; j < raf.length; j++) {
                nextRowOfFloats(rows[j], group.get(j).datatype, group.get(j).byteorderLSB, g.ncols, raf[j], bi,
                        (float) g.nodatavalue);
            }

            //write
            ByteBuffer bb = ByteBuffer.wrap(b);
            bb.order(ByteOrder.LITTLE_ENDIAN);

            for (int k = 0; k < g.ncols; k++) {
                for (int j = 0; j < raf.length; j++) {
                    //float f = getNextValue(raf[j], group.get(j));
                    float f = rows[j][k];
                    if (Float.isNaN(f)) {
                        bb.putFloat(noDataValue);
                    } else {
                        bb.putFloat(f);
                    }
                }
            }
            output.write(b);
        }
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
        for (int i = 0; i < raf.length; i++) {
            if (raf[i] != null) {
                try {
                    raf[i].close();
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
    }
}

From source file:Armadillo.Analytics.Base.Precision.java

/**
 * Returns true if both arguments are equal or within the range of allowed
 * error (inclusive)./*from www  . j  a v a  2s.  co  m*/
 * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
 * (or fewer) floating point numbers between them, i.e. two adjacent floating
 * point numbers are considered equal.
 * Adapted from <a
 * href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm">
 * Bruce Dawson</a>
 *
 * @param x first value
 * @param y second value
 * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
 * values between {@code x} and {@code y}.
 * @return {@code true} if there are fewer than {@code maxUlps} floating
 * point values between {@code x} and {@code y}.
 * @since 2.2
 */
public static boolean equals(float x, float y, int maxUlps) {
    int xInt = Float.floatToIntBits(x);
    int yInt = Float.floatToIntBits(y);

    // Make lexicographically ordered as a two's-complement integer.
    if (xInt < 0) {
        xInt = SGN_MASK_FLOAT - xInt;
    }
    if (yInt < 0) {
        yInt = SGN_MASK_FLOAT - yInt;
    }

    final boolean isEqual = FastMath.abs(xInt - yInt) <= maxUlps;

    return isEqual && !Float.isNaN(x) && !Float.isNaN(y);
}

From source file:com.uphyca.stetho_realm.Database.java

private List<Object> flattenRows(Table table, int limit, boolean addRowIndex) {
    Util.throwIfNot(limit >= 0);
    final List<Object> flatList = new ArrayList<>();
    long numColumns = table.getColumnCount();

    final RowFetcher rowFetcher = RowFetcher.getInstance();
    for (long row = 0; row < limit && row < table.size(); row++) {
        final RowWrapper rowData = RowWrapper.wrap(rowFetcher.getRow(table, row));
        if (addRowIndex) {
            flatList.add(rowData.getIndex());
        }//  w  w  w  . j a  v a  2s.  c  om
        for (int column = 0; column < numColumns; column++) {
            switch (rowData.getColumnType(column)) {
            case INTEGER:
                flatList.add(rowData.getLong(column));
                break;
            case BOOLEAN:
                flatList.add(rowData.getBoolean(column));
                break;
            case STRING:
                flatList.add(rowData.getString(column));
                break;
            case BINARY:
                flatList.add(rowData.getBinaryByteArray(column));
                break;
            case FLOAT:
                final float aFloat = rowData.getFloat(column);
                if (Float.isNaN(aFloat)) {
                    flatList.add("NaN");
                } else if (aFloat == Float.POSITIVE_INFINITY) {
                    flatList.add("Infinity");
                } else if (aFloat == Float.NEGATIVE_INFINITY) {
                    flatList.add("-Infinity");
                } else {
                    flatList.add(aFloat);
                }
                break;
            case DOUBLE:
                final double aDouble = rowData.getDouble(column);
                if (Double.isNaN(aDouble)) {
                    flatList.add("NaN");
                } else if (aDouble == Double.POSITIVE_INFINITY) {
                    flatList.add("Infinity");
                } else if (aDouble == Double.NEGATIVE_INFINITY) {
                    flatList.add("-Infinity");
                } else {
                    flatList.add(aDouble);
                }
                break;
            case DATE:
                flatList.add(rowData.getDate(column));
                break;
            case LINK:
                flatList.add(rowData.getLink(column));
                break;
            case LINK_LIST:
                flatList.add(rowData.getLinkList(column));
                break;
            default:
                flatList.add("unknown column type: " + rowData.getColumnType(column));
                break;
            }
        }
    }

    if (limit < table.size()) {
        for (int column = 0; column < numColumns; column++) {
            flatList.add("{truncated}");
        }
    }

    return flatList;
}

From source file:com.tmall.wireless.tangram3.structure.card.GridCard.java

private void convertChildLayoutHelper(@Nullable RangeGridLayoutHelper gridHelper, GridCard parentCard) {
    for (int i = 0, size = parentCard.getChildren().size(); i < size; i++) {
        Range<Integer> range = parentCard.getChildren().keyAt(i);
        Card child = parentCard.getChildren().valueAt(i);
        Style style = child.style;
        if (style instanceof GridStyle && child instanceof GridCard) {
            final GridStyle gridStyle = (GridStyle) style;
            final GridCard gridCard = (GridCard) child;
            if (!gridCard.getChildren().isEmpty()) {
                convertChildLayoutHelper(gridHelper, gridCard);
            }// w ww  . j a  v  a 2 s.  co  m
            GridRangeStyle rangeStyle = new GridRangeStyle();
            int totalColumn = gridCard.mColumn;
            if (gridStyle.column > 0) {
                totalColumn = gridStyle.column;
                rangeStyle.setSpanCount(gridStyle.column);
            } else {
                rangeStyle.setSpanCount(totalColumn);
            }

            rangeStyle.setSpanSizeLookup(new CellSpanSizeLookup(gridCard.getCells(), totalColumn));

            rangeStyle.setVGap(gridStyle.vGap);
            rangeStyle.setHGap(gridStyle.hGap);
            rangeStyle.setAutoExpand(gridStyle.autoExpand);

            if (gridStyle.cols != null && gridStyle.cols.length > 0) {
                rangeStyle.setWeights(gridStyle.cols);
            }

            if (!Float.isNaN(gridStyle.aspectRatio)) {
                rangeStyle.setAspectRatio(gridStyle.aspectRatio);
            }

            rangeStyle.setBgColor(style.bgColor);
            rangeStyle.setMargin(style.margin[Style.MARGIN_LEFT_INDEX], style.margin[Style.MARGIN_TOP_INDEX],
                    style.margin[Style.MARGIN_RIGHT_INDEX], style.margin[Style.MARGIN_BOTTOM_INDEX]);
            rangeStyle.setPadding(style.padding[Style.MARGIN_LEFT_INDEX], style.padding[Style.MARGIN_TOP_INDEX],
                    style.padding[Style.MARGIN_RIGHT_INDEX], style.padding[Style.MARGIN_BOTTOM_INDEX]);
            if (!TextUtils.isEmpty(style.bgImgUrl)) {
                if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                    final CardSupport support = serviceManager.getService(CardSupport.class);
                    rangeStyle.setLayoutViewBindListener(new BindListener(style) {
                        @Override
                        public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onBindBackgroundView(layoutView, gridCard);
                        }
                    });
                    rangeStyle.setLayoutViewUnBindListener(new UnbindListener(style) {
                        @Override
                        public void onUnbind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onUnbindBackgroundView(layoutView, gridCard);
                        }
                    });
                } else {
                    rangeStyle.setLayoutViewBindListener(new BindListener(style));
                    rangeStyle.setLayoutViewUnBindListener(new UnbindListener(style));
                }
            } else {
                rangeStyle.setLayoutViewBindListener(null);
                rangeStyle.setLayoutViewUnBindListener(null);
            }

            gridHelper.addRangeStyle(range.getLower().intValue(), range.getUpper().intValue(), rangeStyle);
        }
    }
}

From source file:org.nd4j.linalg.util.ArrayUtil.java

public static short fromFloat(float v) {
    if (Float.isNaN(v))
        return (short) 0x7fff;
    if (v == Float.POSITIVE_INFINITY)
        return (short) 0x7c00;
    if (v == Float.NEGATIVE_INFINITY)
        return (short) 0xfc00;
    if (v == 0.0f)
        return (short) 0x0000;
    if (v == -0.0f)
        return (short) 0x8000;
    if (v > 65504.0f)
        return 0x7bff; // max value supported by half float
    if (v < -65504.0f)
        return (short) (0x7bff | 0x8000);
    if (v > 0.0f && v < 5.96046E-8f)
        return 0x0001;
    if (v < 0.0f && v > -5.96046E-8f)
        return (short) 0x8001;

    final int f = Float.floatToIntBits(v);

    return (short) (((f >> 16) & 0x8000) | ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00)
            | ((f >> 13) & 0x03ff));
}

From source file:com.github.vanroy.springdata.jest.CriteriaQueryProcessor.java

private void addBoost(QueryBuilder query, float boost) {
    if (Float.isNaN(boost)) {
        return;// w w  w .j  a va2 s  .  co  m
    }
    if (query instanceof BoostableQueryBuilder) {
        ((BoostableQueryBuilder) query).boost(boost);
    }
}

From source file:de.dfki.asr.compass.model.SceneNode.java

public void setLocalRotation(final Quat4f rotation) {
    Quat4f incoming = rotation;/*  www. ja  v a  2  s  . c o  m*/
    if (Float.isNaN(rotation.w)) {
        incoming = new Quat4f(0.f, 0.f, 0.f, 1.0f);
    }
    incoming.normalize();
    localOrientation.setLocalRotation(incoming);
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerAdapter.java

boolean isEnableMultiScr() {
    return !Float.isNaN(multiScrRatio) && multiScrRatio < 1f;
}