Example usage for java.lang Float floatToIntBits

List of usage examples for java.lang Float floatToIntBits

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static int floatToIntBits(float value) 

Source Link

Document

Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout.

Usage

From source file:de.bund.bfr.knime.pmm.common.math.ParameterOptimizer.java

public void optimize(AtomicInteger progress, int nParameterSpace, int nLevenberg, boolean stopWhenSuccessful) {
    List<Double> paramMin = new ArrayList<>();
    List<Integer> paramStepCount = new ArrayList<>();
    List<Double> paramStepSize = new ArrayList<>();
    int maxCounter = 1;
    int paramsWithRange = 0;
    int maxStepCount = 10;

    for (int i = 0; i < parameters.size(); i++) {
        Double min = minParameterValues.get(i);
        Double max = maxParameterValues.get(i);

        if (min != null && max != null) {
            paramsWithRange++;//from  w  ww. ja v a2s  . co m
        }
    }

    if (paramsWithRange != 0) {
        maxStepCount = (int) Math.pow(nParameterSpace, 1.0 / paramsWithRange);
        maxStepCount = Math.max(maxStepCount, 2);
        maxStepCount = Math.min(maxStepCount, 10);
    }

    for (int i = 0; i < parameters.size(); i++) {
        Double min = minParameterValues.get(i);
        Double max = maxParameterValues.get(i);

        if (min != null && max != null) {
            paramMin.add(min);
            paramStepCount.add(maxStepCount);
            maxCounter *= maxStepCount;

            if (max > min) {
                paramStepSize.add((max - min) / (maxStepCount - 1));
            } else {
                paramStepSize.add(1.0);
            }
        } else if (min != null) {
            if (min != 0.0) {
                paramMin.add(min);
            } else {
                paramMin.add(MathUtilities.EPSILON);
            }

            paramStepCount.add(1);
            paramStepSize.add(1.0);
        } else if (max != null) {
            if (max != 0.0) {
                paramMin.add(max);
            } else {
                paramMin.add(-MathUtilities.EPSILON);
            }

            paramStepCount.add(1);
            paramStepSize.add(1.0);
        } else {
            paramMin.add(MathUtilities.EPSILON);
            paramStepCount.add(1);
            paramStepSize.add(1.0);
        }
    }

    List<List<Double>> bestValues = new ArrayList<>();
    List<Double> bestError = new ArrayList<>();

    for (int i = 0; i < nLevenberg; i++) {
        bestValues.add(new ArrayList<>(Collections.nCopies(parameters.size(), i + 1.0)));
        bestError.add(Double.POSITIVE_INFINITY);
    }

    List<Integer> paramStepIndex = new ArrayList<>(Collections.nCopies(parameters.size(), 0));
    boolean done = false;
    int counter = 0;

    while (!done) {
        progress.set(Float.floatToIntBits((float) counter / (float) maxCounter));
        counter++;

        List<Double> values = new ArrayList<>();
        double error = 0.0;

        for (int i = 0; i < parameters.size(); i++) {
            double value = paramMin.get(i) + paramStepIndex.get(i) * paramStepSize.get(i);

            values.add(value);
            parser.setVarValue(parameters.get(i), value);
        }

        for (int i = 0; i < targetValues.size(); i++) {
            for (int j = 0; j < arguments.size(); j++) {
                parser.setVarValue(arguments.get(j), argumentValues.get(j).get(i));
            }

            try {
                double value = (Double) parser.evaluate(function);
                double diff = targetValues.get(i) - value;

                error += diff * diff;
            } catch (ParseException e) {
                e.printStackTrace();
            } catch (ClassCastException e) {
                error = Double.POSITIVE_INFINITY;
                break;
            }
        }

        for (int i = nLevenberg; i >= 0; i--) {
            if (i == 0 || !(error < bestError.get(i - 1))) {
                if (i != nLevenberg) {
                    bestError.add(i, error);
                    bestValues.add(i, values);
                    bestError.remove(nLevenberg);
                    bestValues.remove(nLevenberg);
                }

                break;
            }
        }

        for (int i = 0;; i++) {
            if (i >= parameters.size()) {
                done = true;
                break;
            }

            paramStepIndex.set(i, paramStepIndex.get(i) + 1);

            if (paramStepIndex.get(i) >= paramStepCount.get(i)) {
                paramStepIndex.set(i, 0);
            } else {
                break;
            }
        }
    }

    successful = false;

    for (List<Double> startValues : bestValues) {
        try {
            optimize(startValues);

            double cost = optimizerValues.getCost();

            if (!successful || cost * cost < sse) {
                useCurrentResults(startValues);

                if (rSquare != 0.0) {
                    successful = true;

                    if (stopWhenSuccessful) {
                        break;
                    }
                }
            }
        } catch (TooManyEvaluationsException e) {
            break;
        } catch (ConvergenceException e) {
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:uk.co.modularaudio.mads.base.stereo_compressor.ui.StereoCompressorMadUiInstance.java

public void sendRelease(final float desiredRelease) {
    final long value = Float.floatToIntBits(desiredRelease);
    sendTemporalValueToInstance(StereoCompressorIOQueueBridge.COMMAND_IN_RELEASE_MILLIS, value);
}

From source file:com.meetup.memcached.NativeHandler.java

protected static byte[] encode(float value) throws Exception {
    return encode((int) Float.floatToIntBits(value));
}

From source file:org.geowebcache.grid.BoundingBox.java

@Override
public int hashCode() {
    return Float.floatToIntBits((float) coords[0]) ^ Float.floatToIntBits((float) coords[1]);
}

From source file:com.sindicetech.siren.search.spans.TermSpanQuery.java

@Override
public int hashCode() {
    return Float.floatToIntBits(this.getBoost()) ^ term.hashCode() ^ levelConstraint ^ upperBound ^ lowerBound;
}

From source file:uk.co.modularaudio.mads.base.stereo_compressor.ui.StereoCompressorMadUiInstance.java

public void sendGain(final float desiredGain) {
    final long value = Float.floatToIntBits(desiredGain);
    sendTemporalValueToInstance(StereoCompressorIOQueueBridge.COMMAND_IN_MAKEUP_GAIN, value);
}

From source file:io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory.java

@Override
public int hashCode() {
    int result = name != null ? name.hashCode() : 0;
    result = 31 * result + (fieldName != null ? fieldName.hashCode() : 0);
    result = 31 * result + resolution;/*from   w  ww  .ja  v a 2  s. c  om*/
    result = 31 * result + numBuckets;
    result = 31 * result + (lowerLimit != +0.0f ? Float.floatToIntBits(lowerLimit) : 0);
    result = 31 * result + (upperLimit != +0.0f ? Float.floatToIntBits(upperLimit) : 0);
    return result;
}

From source file:org.springmodules.util.ObjectsTests.java

public void testNullSafeHashCodeWithFloatArray() {
    int expected = 31 * 7 + Float.floatToIntBits(9.6f);
    expected = 31 * expected + Float.floatToIntBits(7.4f);

    float[] array = { 9.6f, 7.4f };
    int actual = Objects.nullSafeHashCode(array);

    assertEquals(expected, actual);/*from  ww  w.  j av  a 2s .  co m*/
}

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:uk.co.modularaudio.mads.base.scopen.ui.ScopeNMadUiInstance.java

public void setCaptureTimeMillis(final float captureMillis) {
    final int intBits = Float.floatToIntBits(captureMillis);
    sendTemporalValueToInstance(ScopeNIOQueueBridge.COMMAND_IN_CAPTURE_MILLIS, intBits);

    final int newCaptureSamples = AudioTimingUtils.getNumSamplesForMillisAtSampleRate(sampleRate,
            captureMillis);//from   w  w w .j a  va2s. c  o  m
    //      log.trace( "New capture num samples is " + newCaptureSamples +
    //            " previous was " + captureLengthSamples );

    for (final ScopeNCaptureLengthListener cll : captureLengthListeners) {
        cll.receiveCaptureLengthMillis(captureMillis);
        cll.receiveCaptureLengthSamples(newCaptureSamples);
    }

}