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

public static String toBitString(final float f) {
    final char[] bit = new char[32];
    final int ff = Float.floatToIntBits(f);
    int mask = 1;
    for (int i = 0; i < 32; i++) {
        final int bitval = ff & mask;
        if (bitval == 0) {
            bit[31 - i] = '0';
        } else {/*from w w w . j  av a 2 s  .c  o  m*/
            bit[31 - i] = '1';
        }
        mask <<= 1;
    }
    return String.valueOf(bit);
}

From source file:Main.java

static void unmarshalIn(org.omg.CORBA.portable.InputStream s, TypeCode typeCode, long[] la, Object[] oa) {
    int type = typeCode.kind().value();
    long l = 0;// w  w w.ja v  a 2  s  . c o m
    Object o = oa[0];

    switch (type) {
    case TCKind._tk_null:
    case TCKind._tk_void:
    case TCKind._tk_native:
        // Nothing to read
        break;

    case TCKind._tk_short:
        l = s.read_short() & 0xFFFFL;
        break;

    case TCKind._tk_ushort:
        l = s.read_ushort() & 0xFFFFL;
        break;

    case TCKind._tk_enum:
    case TCKind._tk_long:
        l = s.read_long() & 0xFFFFFFFFL;
        break;

    case TCKind._tk_ulong:
        l = s.read_ulong() & 0xFFFFFFFFL;
        break;

    case TCKind._tk_float:
        l = Float.floatToIntBits(s.read_float()) & 0xFFFFFFFFL;
        break;

    case TCKind._tk_double:
        l = Double.doubleToLongBits(s.read_double());
        break;

    case TCKind._tk_char:
        l = s.read_char() & 0xFFFFL;
        break;

    case TCKind._tk_octet:
        l = s.read_octet() & 0xFFL;
        break;

    case TCKind._tk_boolean:
        if (s.read_boolean())
            l = 1;
        else
            l = 0;
        break;

    case TCKind._tk_any:
        o = s.read_any();
        break;

    case TCKind._tk_TypeCode:
        o = s.read_TypeCode();
        break;

    case TCKind._tk_Principal:
        o = s.read_Principal();
        break;

    case TCKind._tk_objref:
        if (o instanceof Streamable)
            ((Streamable) o)._read(s);
        else
            o = s.read_Object();
        break;

    case TCKind._tk_longlong:
        l = s.read_longlong();
        break;

    case TCKind._tk_ulonglong:
        l = s.read_ulonglong();
        break;

    case TCKind._tk_wchar:
        l = s.read_wchar() & 0xFFFFL;
        break;

    case TCKind._tk_string:
        o = s.read_string();
        break;

    case TCKind._tk_wstring:
        o = s.read_wstring();
        break;

    case TCKind._tk_value:
    case TCKind._tk_value_box:
        o = ((org.omg.CORBA_2_3.portable.InputStream) s).read_value();
        break;

    case TCKind._tk_fixed:
        try {
            // _REVISIT_ As soon as the java-rtf adds digits and scale parameters to
            // InputStream, this check will be unnecessary
            if (s instanceof CDRInputStream) {
                o = ((CDRInputStream) s).read_fixed(typeCode.fixed_digits(), typeCode.fixed_scale());
            } else {
                BigDecimal bigDecimal = s.read_fixed();
                o = bigDecimal.movePointLeft((int) typeCode.fixed_scale());
            }
        } catch (BadKind badKind) { // impossible
        }
        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)._read(s);
        break;

    case TCKind._tk_abstract_interface:
        o = ((org.omg.CORBA_2_3.portable.InputStream) s).read_abstract_interface();
        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();
    }

    oa[0] = o;
    la[0] = l;
}

From source file:VASSAL.tools.HashCode.java

public static final int hash(final float value) {
    return Float.floatToIntBits(value);
}

From source file:Main.java

/**
 * Writes a "float" value to an OutputStream. The value is
 * converted to the opposed endian system while writing.
 * @param output target OutputStream//www  .  j  a va  2s . c  o  m
 * @param value value to write
 * @throws IOException in case of an I/O problem
 */
public static void writeSwappedFloat(OutputStream output, float value) throws IOException {
    writeSwappedInteger(output, Float.floatToIntBits(value));
}

From source file:Main.java

public static byte[] floatToBytesBE(float f, byte[] bytes, int off) {
    return intToBytesBE(Float.floatToIntBits(f), bytes, off);
}

From source file:Main.java

public static byte[] floatToBytesLE(float f, byte[] bytes, int off) {
    return intToBytesLE(Float.floatToIntBits(f), bytes, off);
}

From source file:Main.java

public static byte[] float2bytesBE(float val, byte[] b, int off) {
    return int2bytesBE(Float.floatToIntBits(val), b, off);
}

From source file:Main.java

public static byte[] float2bytesLE(float val, byte[] b, int off) {
    return int2bytesLE(Float.floatToIntBits(val), b, off);
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Unique.java

/**
 * Uniques the data, duplicates are removed based on bitwise comparison of data.
 * @param data float[] the data to unique
 * @return the float[] uniqued data/*from ww w  . j  av a2s .co m*/
 */
public static float[] bitwise(float[] data) {
    Validate.notNull(data);
    int n = data.length;
    float[] sorteddata = Sort.stateless(data);
    int j = 0;
    for (int i = 1; i < n; i++) {
        if (Float.floatToIntBits(sorteddata[i]) != Float.floatToIntBits(sorteddata[j])) {
            j++;
            sorteddata[j] = sorteddata[i];
        }
    }
    return Arrays.copyOf(sorteddata, j + 1);
}

From source file:Primitives.java

/**
 * Test the equality of two doubles by converting their values into IEEE 754
 * floating-point "single precision" bit layouts.
 * /*from   ww w.j  av  a2s  .  co  m*/
 * @param a
 *          Float to check equality with.
 * @param b
 *          Float to check equality with.
 * @return True if a equals b.
 */
public static boolean equals(final float a, final float b) {
    return Float.floatToIntBits(a) == Float.floatToIntBits(b);
}