Example usage for java.lang Float floatToRawIntBits

List of usage examples for java.lang Float floatToRawIntBits

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native int floatToRawIntBits(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, preserving Not-a-Number (NaN) values.

Usage

From source file:gdsc.core.utils.FloatEquality.java

/**
 * Compute the number of representable floats until a difference in significant digits
 * <p>/*  ww  w . jav  a 2 s  . c  om*/
 * The number of floats are computed between Math.power(10, sig) and 1 + Math.power(10, sig)
 * 
 * @param significantDigits
 *            The significant digits
 * @return The number of representable floats (Units in the Last Place)
 */
public static int getUlps(int significantDigits) {
    int value1 = (int) Math.pow(10.0, significantDigits - 1);
    int value2 = value1 + 1;
    int ulps = Float.floatToRawIntBits((float) value2) - Float.floatToRawIntBits((float) value1);
    return (ulps < 0) ? 0 : ulps;
}

From source file:gdsc.core.utils.FloatEquality.java

/**
 * Compute the number of bits variation using integer comparisons.
 * //from ww  w.ja  v  a 2s .c  o  m
 * @param A
 * @param B
 * 
 * @return How many representable floats we are between A and B
 */
public static int complement(float A, float B) {
    int aInt = Float.floatToRawIntBits(A);
    // Make aInt lexicographically ordered as a twos-complement int
    if (aInt < 0)
        aInt = 0x80000000 - aInt;
    // Make bInt lexicographically ordered as a twos-complement int
    int bInt = Float.floatToRawIntBits(B);
    if (bInt < 0)
        bInt = 0x80000000 - bInt;
    return Math.abs(aInt - bInt);
}

From source file:gdsc.core.utils.FloatEquality.java

/**
 * Compute the number of bits variation using integer comparisons.
 * /*from   ww  w .  j  av a 2 s. c om*/
 * @param A
 * @param B
 * 
 * @return How many representable floats we are between A and B
 */
public static int signedComplement(float A, float B) {
    int aInt = Float.floatToRawIntBits(A);
    // Make aInt lexicographically ordered as a twos-complement int
    if (aInt < 0)
        aInt = 0x80000000 - aInt;
    // Make bInt lexicographically ordered as a twos-complement int
    int bInt = Float.floatToRawIntBits(B);
    if (bInt < 0)
        bInt = 0x80000000 - bInt;
    return aInt - bInt;
}

From source file:dk.dma.enav.model.geometry.Position.java

/**
 * Packs the position into a long (losing some precision). Can be read later by {@link #fromPackedLong(long)}
 * //from  www . j  a  v  a 2s . com
 * @return the packet long
 */
public long toPackedLong() {
    float lat = (float) getLatitude();
    float lon = (float) getLongitude();
    return ((long) Float.floatToRawIntBits(lat) << 32) + Float.floatToRawIntBits(lon);
}

From source file:me.piebridge.prevent.ui.PreventActivity.java

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (Float.floatToRawIntBits(positionOffset) == 0) {
        checkSelection(position);/*from   w  w  w  .  j  av a  2s .  co  m*/
    }
}

From source file:com.xingcloud.xa.hbase.util.ByteUtils.java

/**
 * @param f float value//w ww  .j a v  a  2 s. c  om
 * @return the float represented as byte []
 */
public static byte[] toBytes(final float f) {
    // Encode it as int
    return ByteUtils.toBytes(Float.floatToRawIntBits(f));
}

From source file:com.secupwn.aimsicd.ui.activities.MainActivity.java

@Override
public void processFinish(float[] location) {
    log.info("processFinish - location[0]=" + location[0] + " location[1]=" + location[1]);

    if (Float.floatToRawIntBits(location[0]) == 0 && Float.floatToRawIntBits(location[1]) != 0) {
        Helpers.msgLong(this, getString(R.string.contacting_opencellid_for_data));
        Helpers.getOpenCellData(this, mAimsicdService.getCell(), RequestTask.DBE_DOWNLOAD_REQUEST,
                mAimsicdService);/*from   w  ww. j a  v a  2s . com*/
    } else {
        Helpers.msgLong(this, getString(R.string.unable_to_determine_last_location));
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.util.StatHelper.java

/**
 * Converts a primitive float into an array of bytes
 *
 * @param data      a primitive float/*from  w w  w . j a v a2  s  .  c om*/
 * @return          a byte array
 */
public static byte[] toByteArrays(float data) {
    return toByteArrays(Float.floatToRawIntBits(data));
}

From source file:com.idylwood.utils.MathUtils.java

public static final float abs(final float f) {
    return Float.intBitsToFloat(Integer.MAX_VALUE & Float.floatToRawIntBits(f));
}

From source file:cn.iie.haiep.hbase.value.Bytes.java

/**
 * @param bytes byte array/*  www . j av a2  s.co  m*/
 * @param offset offset to write to
 * @param f float value
 * @return New offset in <code>bytes</code>
 */
public static int putFloat(byte[] bytes, int offset, float f) {
    return putInt(bytes, offset, Float.floatToRawIntBits(f));
}