Example usage for java.lang Float POSITIVE_INFINITY

List of usage examples for java.lang Float POSITIVE_INFINITY

Introduction

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

Prototype

float POSITIVE_INFINITY

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

Click Source Link

Document

A constant holding the positive infinity of type float .

Usage

From source file:com.orthancserver.DicomDecoder.java

private String[] SortSlicesBy3D(OrthancConnection c, JSONArray instances) throws IOException {
    ArrayList<Slice> slices = new ArrayList<Slice>();
    float normal[] = null;

    float minDistance = Float.POSITIVE_INFINITY;
    float maxDistance = Float.NEGATIVE_INFINITY;

    for (int i = 0; i < instances.size(); i++) {
        String uuid = (String) instances.get(i);
        JSONObject instance = (JSONObject) c.ReadJson("/instances/" + uuid + "/tags?simplify");
        if (!instance.containsKey("ImageOrientationPatient") || !instance.containsKey("ImagePositionPatient")) {
            return null;
        }/*from   w ww  .  ja va2  s .c o m*/

        if (i == 0) {
            String[] tokens = ((String) instance.get("ImageOrientationPatient")).split("\\\\");
            if (tokens.length != 6) {
                return null;
            }

            float cosines[] = new float[6];
            for (int j = 0; j < 6; j++) {
                cosines[j] = Float.parseFloat(tokens[j]);
            }

            normal = new float[] { cosines[1] * cosines[5] - cosines[2] * cosines[4],
                    cosines[2] * cosines[3] - cosines[0] * cosines[5],
                    cosines[0] * cosines[4] - cosines[1] * cosines[3] };
        }

        String[] tokens = ((String) instance.get("ImagePositionPatient")).split("\\\\");
        if (tokens.length != 3) {
            return null;
        }

        float distance = 0;
        for (int j = 0; j < 3; j++) {
            distance += normal[j] * Float.parseFloat(tokens[j]);
        }

        minDistance = Math.min(minDistance, distance);
        maxDistance = Math.max(minDistance, distance);
        slices.add(new Slice(distance, uuid));
    }

    if (maxDistance - minDistance < 0.001) {
        return null;
    }

    return SortSlices(slices);
}

From source file:net.iponweb.hadoop.streaming.avro.IOWJsonDecoder.java

@Override
public float readFloat() throws IOException {
    advance(Symbol.FLOAT);//from  ww  w  .ja  v  a 2 s  .  c o  m
    if (in.getCurrentToken().isNumeric()) {
        float result = in.getFloatValue();
        in.nextToken();
        return result;
    } else {
        try {
            String s = in.getText();
            in.nextToken();
            if (s.equals("NaN")) {
                return Float.NaN;
            } else if (s.equals("-Inf")) {
                return Float.NEGATIVE_INFINITY;
            } else if (s.equals("+Inf")) {
                return Float.POSITIVE_INFINITY;
            } else {
                return Float.parseFloat(s);
            }
        } catch (Exception e) {
            throw error("float (" + e.getMessage() + ")");
        }
    }
}

From source file:org.apache.hadoop.util.Progress.java

/** Called during execution on a leaf node to set its progress. */
public synchronized void set(float progress) {
    if (Float.isNaN(progress)) {
        progress = 0;// w  w w  .ja va2 s.  com
        LOG.debug("Illegal progress value found, progress is Float.NaN. " + "Progress will be changed to 0");
    } else if (progress == Float.NEGATIVE_INFINITY) {
        progress = 0;
        LOG.debug("Illegal progress value found, progress is "
                + "Float.NEGATIVE_INFINITY. Progress will be changed to 0");
    } else if (progress < 0) {
        progress = 0;
        LOG.debug("Illegal progress value found, progress is less than 0." + " Progress will be changed to 0");
    } else if (progress > 1) {
        progress = 1;
        LOG.debug(
                "Illegal progress value found, progress is larger than 1." + " Progress will be changed to 1");
    } else if (progress == Float.POSITIVE_INFINITY) {
        progress = 1;
        LOG.debug("Illegal progress value found, progress is "
                + "Float.POSITIVE_INFINITY. Progress will be changed to 1");
    }
    this.progress = progress;
}

From source file:org.mtransit.android.ui.view.map.impl.GridClusteringStrategy.java

@Override
public float getMinZoomLevelNotClustered(IMarker marker) {
    if (!markers.containsKey(marker)) {
        throw new UnsupportedOperationException("marker is not visible or is a cluster");
    }// w  w  w  .ja v a 2s  .c  o  m
    int zoom = 0;
    while (zoom <= 25 && hasCollision(marker, zoom)) {
        zoom++;
    }
    if (zoom > 25) {
        return Float.POSITIVE_INFINITY;
    }
    return zoom;
}

From source file:src.game.common.Spacing.java

public static Tile nearestOpenTile(Box2D area, Target client, World world) {
    final Vec3D p = client.position(pA);
    final Tile o = world.tileAt(p.x, p.y);
    float minDist = Float.POSITIVE_INFINITY;
    Tile nearest = null;//from   w  ww  .  j  av a2s.c o m
    int numTries = 0;
    while (nearest == null && numTries++ < (CLUSTER_SIZE / 2)) {
        for (Tile t : perimeter(area, world)) {
            if (t == null || t.blocked())
                continue;
            if (t != o && t.inside().size() > 0)
                continue;
            final float dist = distance(o, t);
            if (dist < minDist) {
                minDist = dist;
                nearest = t;
            }
        }
        area.expandBy(1);
    }
    return nearest;
}

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());
        }/*from w  w  w .j a va2s . co  m*/
        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: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:org.shaman.terrain.polygonal.GraphToHeightmap.java

private void addPerlinNoise() {
    float[] perlinFactors = new float[NOISE_OCTAVES];
    Noise[] noiseGenerators = new Noise[NOISE_OCTAVES];
    for (int i = 0; i < NOISE_OCTAVES; ++i) {
        noiseGenerators[i] = new Noise(rand.nextLong());
        perlinFactors[i] = (float) (BASE_FREQUENCY * Math.pow(NOISE_OCTAVE_FACTOR, i));
    }/*  w  ww.  j  av a  2 s  . co  m*/
    Heightmap values = new Heightmap(size);
    float min = Float.POSITIVE_INFINITY;
    float max = Float.NEGATIVE_INFINITY;
    for (int x = 0; x < size; ++x) {
        for (int y = 0; y < size; ++y) {
            float roughness = noise[x][y][1];
            //multi-fractal perlin noise
            double perlin = 0;
            for (int i = 0; i < NOISE_OCTAVES; ++i) {
                perlin += noiseGenerators[i].noise(perlinFactors[i] * x, perlinFactors[i] * y)
                        / Math.pow(NOISE_OCTAVE_FACTOR, i * (1 - roughness));
            }
            values.setHeightAt(x, y, (float) perlin);
            min = (float) Math.min(perlin, min);
            max = (float) Math.max(perlin, max);
        }
    }
    float factor = 1f / (max - min);
    for (int x = 0; x < size; ++x) {
        for (int y = 0; y < size; ++y) {
            float amplitude = noise[x][y][0];
            float perlin = (values.getHeightAt(x, y) - min) * factor;
            perlin *= amplitude * PERLIN_NOISE_SCALE;
            heightmap.adjustHeightAt(x, y, perlin);
        }
    }
    LOG.info("perlin noise added");
}

From source file:wqm.radio.StationManager.java

public boolean acceptCalibrationPhase(HttpSession session, boolean endsPhase, Station station,
        AtlasSensor sensor, int phaseID) {
    return acceptCalibrationPhase(session, endsPhase, station, sensor, phaseID, Float.POSITIVE_INFINITY,
            Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
}

From source file:ExposedFloat.java

public boolean action(Event evt, Object arg) {

    if (evt.target instanceof Button) {
        String bname = (String) arg;
        if (bname.equals(incrementButtonString)) {

            ++value;/*from www  . ja  v a2  s  . c  o m*/
        } else if (bname.equals(decrementButtonString)) {

            --value;
        } else if (bname.equals(multByZeroButtonString)) {

            value *= (float) 0.0;
        } else if (bname.equals(piButtonString)) {

            value = (float) Math.PI;
        } else if (bname.equals(positiveInfinityButtonString)) {

            value = Float.POSITIVE_INFINITY;
        } else if (bname.equals(negativeInfinityButtonString)) {

            value = Float.NEGATIVE_INFINITY;
        } else if (bname.equals(maximumButtonString)) {

            value = Float.MAX_VALUE;
        } else if (bname.equals(minimumButtonString)) {

            value = Float.MIN_VALUE;
        } else if (bname.equals(notANumberButtonString)) {

            value = Float.NaN;
        } else if (bname.equals(changeSignButtonString)) {

            value *= -1.0;
        } else if (bname.equals(doubleButtonString)) {

            value *= 2.0;
        } else if (bname.equals(halveButtonString)) {

            value /= 2.0;
        }
        updateNumberFields();
        enableDisableButton(maximumButton, Float.MAX_VALUE);
        enableDisableButton(minimumButton, Float.MIN_VALUE);
        enableDisableButton(positiveInfinityButton, Float.POSITIVE_INFINITY);
        enableDisableButton(negativeInfinityButton, Float.NEGATIVE_INFINITY);
        enableDisableButton(piButton, (float) Math.PI);
        enableDisableButton(notANumberButton, Float.NaN);
        if (!notANumberButton.isEnabled()) {
            if (!Float.isNaN(value)) {
                notANumberButton.enable();
            }
        } else if (Float.isNaN(value)) {
            notANumberButton.disable();
        }
    }
    return true;
}