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:Main.java

/**
 * Converts a byte[4] binary float value to a float primitive.
 *
 * @param bytes the byte[4] containing the float value.
 * @return a float value.//  www. j  a  v  a 2 s .c o  m
 */
public static final float registersToFloat(byte[] bytes) {
    return Float.intBitsToFloat((((bytes[0] & 0xff) << 24) | ((bytes[1] & 0xff) << 16)
            | ((bytes[2] & 0xff) << 8) | (bytes[3] & 0xff)));
}

From source file:halive.shootinoutside.common.util.Vector2D.java

public static Vector2D fromJSONObject(JSONObject o) {
    float x = Float.intBitsToFloat((int) (long) o.get("x"));
    float y = Float.intBitsToFloat((int) (long) o.get("y"));
    return new Vector2D(x, y);
}

From source file:Main.java

/**
 * Converts a "float" value between endian systems.
 * @param value value to convert/*  ww  w  .  j av  a  2 s.c  o m*/
 * @return the converted value
 */
public static float swapFloat(float value) {
    return Float.intBitsToFloat(swapInteger(Float.floatToIntBits(value)));
}

From source file:Main.java

/**
 * Converts a sortable <code>int</code> back to a <code>float</code>.
 * @see #floatToSortableInt/*from www .  j a v  a  2  s  .  c o m*/
 */
public static float sortableIntToFloat(int val) {
    if (val < 0)
        val ^= 0x7fffffff;
    return Float.intBitsToFloat(val);
}

From source file:Main.java

/** Encodes the ABGR int color as a float. The high bits are masked to avoid using floats in the NaN range, which unfortunately
 * means the full range of alpha cannot be used. See {@link Float#intBitsToFloat(int)} javadocs. */
public static float intToFloatColor(int value) {
    return Float.intBitsToFloat(value & 0xfeffffff);
}

From source file:Main.java

/**
 * Reads a "float" value from a byte array at a given offset. The value is
 * converted to the opposed endian system while reading.
 * @param data source byte array/*from  w w w  .j ava  2s . c  o  m*/
 * @param offset starting offset in the byte array
 * @return the value read
 */
public static float readSwappedFloat(byte[] data, int offset) {
    return Float.intBitsToFloat(readSwappedInteger(data, offset));
}

From source file:com.facebook.tsdb.tsdash.server.model.DataPoint.java

public static double decodeValue(byte[] encoded, byte[] qualifier) {
    if (DataPointQualifier.isFloat(qualifier)) {
        if (encoded.length == 8) {
            return Float.intBitsToFloat(Bytes.toInt(encoded, 4));
        } else {/*from   w w  w .ja v  a2  s. c  o m*/
            // length is 4
            return Float.intBitsToFloat(Bytes.toInt(encoded));
        }
    }
    return Bytes.toLong(encoded);
}

From source file:Main.java

public static boolean isLikelyFloat(int value) {
    // Check for some common named float values
    // We don't check for Float.MIN_VALUE, which has an integer representation of 1
    if (value == canonicalFloatNaN || value == maxFloat || value == piFloat || value == eFloat) {
        return true;
    }/*ww w .  j  ava  2  s.  c  o  m*/

    // Check for some named integer values
    if (value == Integer.MAX_VALUE || value == Integer.MIN_VALUE) {
        return false;
    }

    // Check for likely resource id
    int packageId = value >> 24;
    int resourceType = value >> 16 & 0xff;
    int resourceId = value & 0xffff;
    if ((packageId == 0x7f || packageId == 1) && resourceType < 0x1f && resourceId < 0xfff) {
        return false;
    }

    // a non-canocical NaN is more likely to be an integer
    float floatValue = Float.intBitsToFloat(value);
    if (Float.isNaN(floatValue)) {
        return false;
    }

    // Otherwise, whichever has a shorter scientific notation representation is more likely.
    // Integer wins the tie
    String asInt = format.format(value);
    String asFloat = format.format(floatValue);

    // try to strip off any small imprecision near the end of the mantissa
    int decimalPoint = asFloat.indexOf('.');
    int exponent = asFloat.indexOf("E");
    int zeros = asFloat.indexOf("000");
    if (zeros > decimalPoint && zeros < exponent) {
        asFloat = asFloat.substring(0, zeros) + asFloat.substring(exponent);
    } else {
        int nines = asFloat.indexOf("999");
        if (nines > decimalPoint && nines < exponent) {
            asFloat = asFloat.substring(0, nines) + asFloat.substring(exponent);
        }
    }

    return asFloat.length() < asInt.length();
}

From source file:Main.java

/**
 * Returns a floating-point power of two in the normal range.
 *//* w ww  . j ava2  s  . c om*/
static float powerOfTwoF(int n) {
    assert (n >= FloatConsts.MIN_EXPONENT && n <= FloatConsts.MAX_EXPONENT);
    return Float.intBitsToFloat(
            ((n + FloatConsts.EXP_BIAS) << (FloatConsts.SIGNIFICAND_WIDTH - 1)) & FloatConsts.EXP_BIT_MASK);
}

From source file:Main.java

static void marshalIn(org.omg.CORBA.portable.OutputStream s, TypeCode typeCode, long l, Object o) {
    switch (typeCode.kind().value()) {
    case TCKind._tk_null:
    case TCKind._tk_void:
    case TCKind._tk_native:
        // nothing to write
        break;/*w w w . ja v a  2s .co m*/

    case TCKind._tk_short:
        s.write_short((short) (l & 0xFFFFL));
        break;

    case TCKind._tk_ushort:
        s.write_ushort((short) (l & 0xFFFFL));
        break;

    case TCKind._tk_enum:
    case TCKind._tk_long:
        s.write_long((int) (l & 0xFFFFFFFFL));
        break;

    case TCKind._tk_ulong:
        s.write_ulong((int) (l & 0xFFFFFFFFL));
        break;

    case TCKind._tk_float:
        s.write_float(Float.intBitsToFloat((int) (l & 0xFFFFFFFFL)));
        break;

    case TCKind._tk_double:
        s.write_double(Double.longBitsToDouble(l));
        break;

    case TCKind._tk_boolean:
        if (l == 0)
            s.write_boolean(false);
        else
            s.write_boolean(true);
        break;

    case TCKind._tk_char:
        s.write_char((char) (l & 0xFFFFL));
        break;

    case TCKind._tk_octet:
        s.write_octet((byte) (l & 0xFFL));
        break;

    case TCKind._tk_any:
        s.write_any((Any) o);
        break;

    case TCKind._tk_TypeCode:
        s.write_TypeCode((TypeCode) o);
        break;

    case TCKind._tk_Principal:
        s.write_Principal((Principal) o);
        break;

    case TCKind._tk_objref:
        s.write_Object((org.omg.CORBA.Object) o);
        break;

    case TCKind._tk_longlong:
        s.write_longlong(l);
        break;

    case TCKind._tk_ulonglong:
        s.write_ulonglong(l);
        break;

    case TCKind._tk_wchar:
        s.write_wchar((char) (l & 0xFFFFL));
        break;

    case TCKind._tk_string:
        s.write_string((String) o);
        break;

    case TCKind._tk_wstring:
        s.write_wstring((String) o);
        break;

    case TCKind._tk_value:
    case TCKind._tk_value_box:
        ((org.omg.CORBA_2_3.portable.OutputStream) s).write_value((Serializable) o);
        break;

    case TCKind._tk_fixed:
        // _REVISIT_ As soon as the java-rtf adds digits and scale parameters to
        // OutputStream, this check will be unnecessary
        if (s instanceof CDROutputStream) {
            try {
                ((CDROutputStream) s).write_fixed((BigDecimal) o, typeCode.fixed_digits(),
                        typeCode.fixed_scale());
            } catch (BadKind badKind) { // impossible
            }
        } else {
            s.write_fixed((BigDecimal) o);
        }
        break;

    case TCKind._tk_struct:
    case TCKind._tk_union:
    case TCKind._tk_sequence:
    case TCKind._tk_array:
    case TCKind._tk_alias:
    case TCKind._tk_except:
        ((Streamable) o)._write(s);
        break;

    case TCKind._tk_abstract_interface:
        ((org.omg.CORBA_2_3.portable.OutputStream) s).write_abstract_interface(o);
        break;

    case TCKind._tk_longdouble:
        // Unspecified for Java
    default:
        ORBUtilSystemException wrapper = ORBUtilSystemException.get((com.sun.corba.se.spi.orb.ORB) s.orb(),
                CORBALogDomains.RPC_PRESENTATION);
        throw wrapper.typecodeNotSupported();
    }
}