Example usage for java.lang Float intBitsToFloat

List of usage examples for java.lang Float intBitsToFloat

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native float intBitsToFloat(int bits);

Source Link

Document

Returns the float value corresponding to a given bit representation.

Usage

From source file:haven.Utils.java

public static float hfdec(short bits) {
    int b = ((int) bits) & 0xffff;
    int e = (b & 0x7c00) >> 10;
    int m = b & 0x03ff;
    int ee;/*w w w  .  j  a  va  2 s  .  c  om*/
    if (e == 0) {
        if (m == 0) {
            ee = 0;
        } else {
            int n = Integer.numberOfLeadingZeros(m) - 22;
            ee = (-15 - n) + 127;
            m = (m << (n + 1)) & 0x03ff;
        }
    } else if (e == 0x1f) {
        ee = 0xff;
    } else {
        ee = e - 15 + 127;
    }
    int f32 = ((b & 0x8000) << 16) | (ee << 23) | (m << 13);
    return (Float.intBitsToFloat(f32));
}

From source file:dk.statsbiblioteket.util.LineReader.java

@Override
public float readFloat() throws IOException {
    return Float.intBitsToFloat(readInt());
}

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

/**
 * Presumes float encoded as IEEE 754 floating-point "single format"
 * @param bytes array to convert//from  ww  w  . j a  va 2 s  . com
 * @param offset offset into array
 * @return Float made from passed byte array.
 */
public static float toFloat(byte[] bytes, int offset) {
    return Float.intBitsToFloat(toInt(bytes, offset, SIZEOF_INT));
}

From source file:us.parr.animl.data.DataTable.java

public static int numericalFloatPartition(List<int[]> rows, int splitVariable, double splitValue, int low,
        int high) {
    int i = low - 1;
    int j = high + 1;
    int n = rows.size();
    while (true) {
        do {/* w w w  .ja v a2s.  co m*/
            i++;
        } while (i < n && Float.intBitsToFloat(rows.get(i)[splitVariable]) < splitValue);
        do {
            j--;
        } while (j >= 0 && Float.intBitsToFloat(rows.get(j)[splitVariable]) >= splitValue);
        if (i >= j) {
            return i;
        }
        // swap elements at i and j
        int[] savei = rows.get(i);
        rows.set(i, rows.get(j));
        rows.set(j, savei);
    }
}

From source file:kx.c.java

float re() {
    return Float.intBitsToFloat(ri());
}

From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java

/**
 * Returns four bytes from the buffer as a float
 */
public float getFloat() {
    return Float.intBitsToFloat(getInt32());
}

From source file:us.parr.animl.data.DataTable.java

public static float getAsFloat(int a) {
    return Float.intBitsToFloat(a);
}

From source file:us.parr.animl.data.DataTable.java

public void sortBy(int colIndex) {
    switch (colTypes[colIndex]) {
    case CATEGORICAL_INT:
    case NUMERICAL_INT:
    case CATEGORICAL_STRING: // strings are encoded as ints
    case TARGET_CATEGORICAL_STRING:
    case TARGET_CATEGORICAL_INT:
    case UNUSED_INT:
    case UNUSED_STRING:
        Collections.sort(rows, (ra, rb) -> {
            return Integer.compare(ra[colIndex], rb[colIndex]);
        });/*from www.  j a  v a  2 s .  c  om*/
        break;
    case NUMERICAL_FLOAT:
    case UNUSED_FLOAT:
        Collections.sort(rows, (ra, rb) -> {
            return Float.compare(Float.intBitsToFloat(ra[colIndex]), Float.intBitsToFloat(rb[colIndex]));
        });
        break;
    }
}

From source file:ml.shifu.shifu.udf.NormalizeUDF.java

public static float toFloat(int hbits) {
    int mant = hbits & 0x03ff; // 10 bits mantissa
    int exp = hbits & 0x7c00; // 5 bits exponent
    if (exp == 0x7c00) // NaN/Inf
        exp = 0x3fc00; // -> NaN/Inf
    else if (exp != 0) // normalized value
    {//from w w w.j  a  v  a 2 s  .co  m
        exp += 0x1c000; // exp - 15 + 127
        if (mant == 0 && exp > 0x1c400) // smooth transition
            return Float.intBitsToFloat((hbits & 0x8000) << 16 | exp << 13 | 0x3ff);
    } else if (mant != 0) // && exp==0 -> subnormal
    {
        exp = 0x1c400; // make it normal
        do {
            mant <<= 1; // mantissa * 2
            exp -= 0x400; // decrease exp by 1
        } while ((mant & 0x400) == 0); // while not normal
        mant &= 0x3ff; // discard subnormal bit
    } // else +/-0 -> +/-0
    return Float.intBitsToFloat( // combine all parts
            (hbits & 0x8000) << 16 // sign << ( 31 - 15 )
                    | (exp | mant) << 13); // value << ( 23 - 10 )
}

From source file:us.parr.animl.data.DataTable.java

/** Return an object representing the true value of 'value'
 *  relative to colj in table 'data'.//from ww  w . ja  v  a 2  s .c  o  m
 */
public static Object getValue(DataTable data, int value, int colj) {
    switch (data.colTypes[colj]) {
    case CATEGORICAL_INT:
    case NUMERICAL_INT:
    case TARGET_CATEGORICAL_INT:
    case UNUSED_INT:
        return value;
    case CATEGORICAL_STRING:
    case TARGET_CATEGORICAL_STRING:
    case UNUSED_STRING:
        return data.colStringToIntMap[colj].get(value);
    case NUMERICAL_FLOAT:
    case UNUSED_FLOAT:
        return Float.intBitsToFloat(value);
    default:
        throw new IllegalArgumentException(data.colNames[colj] + " has invalid type: " + data.colTypes[colj]);
    }
}