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:org.eclipse.dataset.FloatDataset.java

private List<int[]> findPositions(final float value) { // PRIM_TYPE
    IndexIterator iter = getIterator(true);
    List<int[]> posns = new ArrayList<int[]>();
    int[] pos = iter.getPos();

    if (Float.isNaN(value)) { // CLASS_TYPE // REAL_ONLY
        while (iter.hasNext()) { // REAL_ONLY
            if (Double.isNaN(data[iter.index])) { // REAL_ONLY
                posns.add(pos.clone()); // REAL_ONLY
            } // REAL_ONLY
        } // REAL_ONLY
    } else // REAL_ONLY
    {/*from w ww . j a  va  2 s .  c  o  m*/
        while (iter.hasNext()) {
            if (data[iter.index] == value) {
                posns.add(pos.clone());
            }
        }
    }
    return posns;
}

From source file:org.esa.s2tbx.dataio.s2.ortho.Sentinel2OrthoProductReader.java

private boolean isValidAngle(float value) {
    return !Float.isNaN(value) && !Float.isInfinite(value);
}

From source file:routines.system.BigDataParserUtils.java

public static short parseTo_short(float input) {
    if (Float.isNaN(input)) {
        return defaultValueShort;
    }//from  w w  w .j a va 2s .c  om
    return ((Float) input).shortValue();
}

From source file:eu.aniketos.spdm.ds.impl.BidiMultiHashMap.java

/**
 * Constructs a new, empty map with the specified initial capacity and load
 * factor./*w  ww  . ja v a2  s .co m*/
 * 
 * @param initialCapacity
 *            the initial capacity
 * @param loadFactor
 *            the load factor
 * @throws IllegalArgumentException
 *             if the initial capacity is less than one
 * @throws IllegalArgumentException
 *             if the load factor is less than or equal to zero
 */
public BidiMultiHashMap(int initialCapacity, float loadFactor) {
    super();
    if (initialCapacity < 1) {
        throw new IllegalArgumentException("Initial capacity must be greater than 0"); //$NON-NLS-1$
    }
    if (loadFactor <= 0.0f || Float.isNaN(loadFactor)) {
        throw new IllegalArgumentException("Load factor must be greater than 0"); //$NON-NLS-1$
    }
    this.loadFactor = loadFactor;
    this.keyThreshold = this.valueThreshold = this.entryThreshold = calculateThreshold(initialCapacity,
            loadFactor);
    initialCapacity = calculateNewCapacity(initialCapacity);
    this.keys = new HashEntry[initialCapacity];
    this.values = new HashEntry[initialCapacity];
    this.entries = new HashEntry[initialCapacity];
}

From source file:com.facebook.presto.operator.scalar.MathFunctions.java

@Description("round to given number of decimal places")
@ScalarFunction("round")
@SqlType(StandardTypes.REAL)/*from   ww w  . jav a2 s .  co  m*/
public static long roundFloat(@SqlType(StandardTypes.REAL) long num,
        @SqlType(StandardTypes.INTEGER) long decimals) {
    float numInFloat = intBitsToFloat((int) num);
    if (Float.isNaN(numInFloat) || Float.isInfinite(numInFloat)) {
        return num;
    }

    double factor = Math.pow(10, decimals);
    if (numInFloat < 0) {
        return floatToRawIntBits((float) -(Math.round(-numInFloat * factor) / factor));
    }

    return floatToRawIntBits((float) (Math.round(numInFloat * factor) / factor));
}

From source file:org.eclipse.dataset.FloatDataset.java

@Override
public boolean containsNans() {
    IndexIterator iter = getIterator(); // REAL_ONLY
    while (iter.hasNext()) { // REAL_ONLY
        if (Float.isNaN(data[iter.index])) // CLASS_TYPE // REAL_ONLY
            return true; // REAL_ONLY
    } // REAL_ONLY
    return false;
}

From source file:net.pms.util.Rational.java

/**
 * Returns a {@link Rational} whose value is {@code (this - value)}.
 *
 * @param value the value to be subtracted from this {@link Rational}.
 * @return The subtraction result./* w  w  w.  jav  a 2s  .c  om*/
 */
@Nonnull
public Rational subtract(float value) {
    if (isNaN() || Float.isNaN(value)) {
        return NaN;
    }

    return add(-value);
}

From source file:org.broad.igv.cbio.GeneNetwork.java

public ScoreData collectScoreData(String name, List<Track> tracks, Iterable<String> attributes) {
    int zoom = 0;

    List<NamedFeature> features = FeatureDB.getFeaturesList(name, Integer.MAX_VALUE);

    //If we are viewing a gene list, use the frame
    List<ReferenceFrame> frames = Globals.isHeadless() ? null : FrameManager.getFrames();
    ReferenceFrame frame = Globals.isHeadless() ? null : FrameManager.getDefaultFrame();
    if (frames != null) {
        for (ReferenceFrame frm : frames) {
            if (frm.getName().equalsIgnoreCase(name)) {
                frame = frm;//from   w ww .j  a v  a2 s.  c o  m
            }
        }
    }
    String frameName = frame != null ? frame.getName() : null;

    ScoreData<String, Float> results = new ScoreData(RegionScoreType.values().length);

    int initCapacity = tracks.size() / 10;

    //The names of all samples these tracks cover
    Set<String> allSamples = new HashSet<String>(initCapacity);

    //Each track/feature pair represents a region of a sample.
    //We store whether that sample has been altered in ANY way
    Set<String> anyAlteration = new HashSet<String>(initCapacity);

    //Set of samples which have data for this type
    Set<String> samplesForType = new HashSet<String>(initCapacity);
    //Set of samples which have been altered, using this type.
    Set<String> alteredSamplesForType = new HashSet<String>(initCapacity);

    for (String attr : attributes) {
        if (!bounds.containsKey(attr)) {
            throw new IllegalArgumentException("Have no bounds for " + attr);
        }

        RegionScoreType type = attributeMap.get(attr);
        float[] curBounds = bounds.get(attr);

        samplesForType.clear();
        alteredSamplesForType.clear();

        for (NamedFeature feat : features) {
            if (!name.equalsIgnoreCase(feat.getName())) {
                continue;
            }
            int featStart = feat.getStart();
            int featEnd = feat.getEnd();
            for (Track track : tracks) {
                if (!track.isVisible()) {
                    continue;
                }
                String sample = track.getSample();

                //If track is wrong type, or if sample has already been marked altered,
                //no further information can be gained
                if (!track.isRegionScoreType(type) || alteredSamplesForType.contains(sample)) {
                    //if(alteredSamplesForType.contains(sample)) assert samplesForType.contains(sample);
                    continue;
                }

                samplesForType.add(sample);

                float score = track.getRegionScore(feat.getChr(), featStart, featEnd, zoom, type, frameName,
                        tracks);

                if (score >= curBounds[0] && score <= curBounds[1] && !Float.isNaN(score)) {
                    alteredSamplesForType.add(sample);
                }
            }
        }

        allSamples.addAll(samplesForType);
        anyAlteration.addAll(alteredSamplesForType);

        float fractionAltered = ((float) alteredSamplesForType.size()) / samplesForType.size();
        results.put(attr, fractionAltered);
    }

    results.setPercentAltered(((float) anyAlteration.size()) / allSamples.size());
    return results;

}

From source file:org.eclipse.dataset.FloatDataset.java

@Override
public boolean containsInvalidNumbers() {
    IndexIterator iter = getIterator(); // REAL_ONLY
    while (iter.hasNext()) { // REAL_ONLY
        float x = data[iter.index]; // PRIM_TYPE // REAL_ONLY
        if (Float.isNaN(x) || Float.isInfinite(x)) // CLASS_TYPE // REAL_ONLY
            return true; // REAL_ONLY
    } // REAL_ONLY
    return false;
}

From source file:com.androzic.location.LocationService.java

@Override
public void onLocationChanged(final Location location) {
    tics++;/*from   w  w w . j a v a 2s  . co  m*/

    boolean fromGps = false;
    boolean sendUpdate = false;

    long time = SystemClock.elapsedRealtime();

    // Log.i(TAG, "Location arrived: "+location.toString());

    if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) {
        if (useNetwork && (gpsStatus == GPS_OFF
                || (gpsStatus == GPS_SEARCHING && time > lastLocationMillis + gpsLocationTimeout))) {
            Log.d(TAG, "New location");
            lastKnownLocation = location;
            lastLocationMillis = time;
            isContinous = false;
            sendUpdate = true;
        } else {
            return;
        }
    } else {
        fromGps = true;

        Log.d(TAG, "Fix arrived");

        long prevLocationMillis = lastLocationMillis;
        float prevSpeed = lastKnownLocation.getSpeed();

        lastKnownLocation = location;
        lastLocationMillis = time;
        sendUpdate = true;

        if (!Float.isNaN(nmeaGeoidHeight)) {
            location.setAltitude(location.getAltitude() + nmeaGeoidHeight);
        }

        if (justStarted) {
            justStarted = prevSpeed == 0;
        } else if (lastKnownLocation.getSpeed() > 0) {
            // filter speed outrages
            double a = 2 * 9.8 * (lastLocationMillis - prevLocationMillis) / 1000;
            if (Math.abs(lastKnownLocation.getSpeed() - prevSpeed) > a)
                lastKnownLocation.setSpeed(prevSpeed);
        }

        // smooth speed
        float smoothspeed = 0;
        float curspeed = lastKnownLocation.getSpeed();
        for (int i = speed.length - 1; i > 1; i--) {
            smoothspeed += speed[i];
            speed[i] = speed[i - 1];
        }
        smoothspeed += speed[1];
        if (speed[1] < speed[0] && speed[0] > curspeed) {
            speed[0] = (speed[1] + curspeed) / 2;
        }
        smoothspeed += speed[0];
        speed[1] = speed[0];
        lastKnownLocation.setSpeed(speed[1]);
        speed[0] = curspeed;
        if (speed[0] == 0 && speed[1] == 0)
            smoothspeed = 0;
        else
            smoothspeed = smoothspeed / speed.length;

        // average speed
        float avspeed = 0;
        for (int i = speedav.length - 1; i >= 0; i--) {
            avspeed += speedav[i];
        }
        avspeed = avspeed / speedav.length;
        if (tics % pause == 0) {
            if (avspeed > 0) {
                float diff = curspeed / avspeed;
                if (0.95 < diff && diff < 1.05) {
                    for (int i = speedav.length - 1; i > 0; i--) {
                        speedav[i] = speedav[i - 1];
                    }
                    speedav[0] = curspeed;
                }
            }
            float fluct = 0;
            for (int i = speedavex.length - 1; i > 0; i--) {
                fluct += speedavex[i] / curspeed;
                speedavex[i] = speedavex[i - 1];
            }
            fluct += speedavex[0] / curspeed;
            speedavex[0] = curspeed;
            fluct = fluct / speedavex.length;
            if (0.95 < fluct && fluct < 1.05) {
                for (int i = speedav.length - 1; i >= 0; i--) {
                    speedav[i] = speedavex[i];
                }
                if (pause < 5)
                    pause++;
            }
        }

        smoothSpeed = smoothspeed;
        avgSpeed = avspeed;
    }

    /*
     * lastKnownLocation.setSpeed(20); lastKnownLocation.setBearing(55);
     * lastKnownLocation.setAltitude(169);
     * lastKnownLocation.setLatitude(55.852527);
     * lastKnownLocation.setLongitude(29.451150);
     */

    if (sendUpdate)
        updateLocation();

    isContinous = fromGps;
}