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

/**
 * Compares this object against some other object. The result is <code>true</code> if and only if the argument is
 * not <code>null</code> and is a <code>Float</code> object that represents a <code>float</code> that has the
 * identical bit pattern to the bit pattern of the <code>float</code> represented by this object. For this
 * purpose, two float values are considered to be the same if and only if the method
 * {@link Float#floatToIntBits(float)}returns the same int value when applied to each.
 * <p>/*w w  w  . j a  v a 2  s.  c  o m*/
 * Note that in most cases, for two instances of class <code>Float</code>,<code>f1</code> and <code>f2</code>,
 * the value of <code>f1.equals(f2)</code> is <code>true</code> if and only if <blockquote>
 * 
 * <pre>
 *   f1.floatValue() == f2.floatValue()
 * </pre>
 * 
 * </blockquote>
 * <p>
 * also has the value <code>true</code>. However, there are two exceptions:
 * <ul>
 * <li>If <code>f1</code> and <code>f2</code> both represent <code>Float.NaN</code>, then the
 * <code>equals</code> method returns <code>true</code>, even though <code>Float.NaN==Float.NaN</code> has
 * the value <code>false</code>.
 * <li>If <code>f1</code> represents <code>+0.0f</code> while <code>f2</code> represents <code>-0.0f</code>,
 * or vice versa, the <code>equal</code> test has the value <code>false</code>, even though
 * <code>0.0f==-0.0f</code> has the value <code>true</code>.
 * </ul>
 * This definition allows hashtables to operate properly.
 * 
 * @param obj
 *            the object to be compared
 * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
 * @see java.lang.Float#floatToIntBits(float)
 */
public boolean equals(Object obj) {
    return (obj instanceof MutableFloat)
            && (Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value));
}

From source file:org.apache.lucene.index.FieldsWriter.java

final void writeField(FieldInfo fi, Fieldable field) throws IOException {
    fieldsStream.writeVInt(fi.number);/* ww w.jav a2 s  .com*/
    int bits = 0;
    if (field.isTokenized())
        bits |= FIELD_IS_TOKENIZED;
    if (field.isBinary())
        bits |= FIELD_IS_BINARY;
    if (field instanceof NumericField) {
        switch (((NumericField) field).getDataType()) {
        case INT:
            bits |= FIELD_IS_NUMERIC_INT;
            break;
        case LONG:
            bits |= FIELD_IS_NUMERIC_LONG;
            break;
        case FLOAT:
            bits |= FIELD_IS_NUMERIC_FLOAT;
            break;
        case DOUBLE:
            bits |= FIELD_IS_NUMERIC_DOUBLE;
            break;
        default:
            assert false : "Should never get here";
        }
    }
    fieldsStream.writeByte((byte) bits);

    if (field.isBinary()) {
        final byte[] data;
        final int len;
        final int offset;
        data = field.getBinaryValue();
        len = field.getBinaryLength();
        offset = field.getBinaryOffset();

        fieldsStream.writeVInt(len);
        fieldsStream.writeBytes(data, offset, len);
    } else if (field instanceof NumericField) {
        final NumericField nf = (NumericField) field;
        final Number n = nf.getNumericValue();
        switch (nf.getDataType()) {
        case INT:
            fieldsStream.writeVVInt(n.intValue());
            break;
        case LONG:
            fieldsStream.writeVVLong(n.longValue());
            break;
        case FLOAT:
            fieldsStream.writeVVVInt(Float.floatToIntBits(n.floatValue()));
            break;
        case DOUBLE:
            fieldsStream.writeVVVLong(Double.doubleToLongBits(n.doubleValue()));
            break;
        default:
            assert false : "Should never get here";
        }
    } else {
        fieldsStream.writeString(field.stringValue());
    }
}

From source file:CircleOfSquares.java

void ExecuteNextInstruction() {

    int a, b, result, i;
    float fa, fb, fresult;
    Float f;/*from w  w w .ja  v a2  s.  co  m*/
    int operand0, operand1;

    int nextOpCode = methodAreaMemorySection.getAtAddress(pcRegister);

    switch (nextOpCode) {

    case OpCode.BIPUSH:
        operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 1);
        stackMemorySection.setAtAddress(optopRegister, operand0);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        pcRegister += 2;
        break;

    case OpCode.FCONST_0:
        stackMemorySection.setAtAddress(optopRegister, Float.floatToIntBits((float) 0));
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "0");
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.FCONST_2:
        stackMemorySection.setAtAddress(optopRegister, Float.floatToIntBits((float) 2));
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "2");
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.FLOAD_0:
        a = stackMemorySection.getAtAddress(varsRegister);
        stackMemorySection.setAtAddress(optopRegister, a);
        fa = Float.intBitsToFloat(a);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fa));
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.FMUL:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        fa = Float.intBitsToFloat(a);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "");
        optopRegister -= 4;
        b = stackMemorySection.getAtAddress(optopRegister);
        fb = Float.intBitsToFloat(b);
        fresult = fa * fb;
        result = Float.floatToIntBits(fresult);
        stackMemorySection.setAtAddress(optopRegister, result);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fresult));
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.FSTORE_0:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "");
        stackMemorySection.setAtAddress(varsRegister, a);
        fa = Float.intBitsToFloat(a);
        stackMemorySection.setLogicalValueAtAddress(varsRegister, Float.toString(fa));
        ++pcRegister;
        break;

    case OpCode.FSUB:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        fa = Float.intBitsToFloat(a);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "");
        optopRegister -= 4;
        b = stackMemorySection.getAtAddress(optopRegister);
        fb = Float.intBitsToFloat(b);
        fresult = fb - fa;
        result = Float.floatToIntBits(fresult);
        stackMemorySection.setAtAddress(optopRegister, result);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fresult));
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.GOTO:
        operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1);
        operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2);

        int offset = (operand1 << 8) | (operand0 & 0xff);

        pcRegister += offset;
        break;

    case OpCode.IADD:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "");
        optopRegister -= 4;
        b = stackMemorySection.getAtAddress(optopRegister);
        result = a + b;
        stackMemorySection.setAtAddress(optopRegister, result);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.ICONST_M1:
        stackMemorySection.setAtAddress(optopRegister, -1);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.ICONST_0:
        stackMemorySection.setAtAddress(optopRegister, 0);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.ICONST_1:
        stackMemorySection.setAtAddress(optopRegister, 1);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.ICONST_2:
        stackMemorySection.setAtAddress(optopRegister, 2);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.IINC:
        operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 1);
        operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 2);
        a = stackMemorySection.getAtAddress(varsRegister + (operand0 * 4));
        a += operand1;
        stackMemorySection.setAtAddress(varsRegister + (operand0 * 4), a);
        pcRegister += 3;
        break;

    case OpCode.ILOAD_0:
        a = stackMemorySection.getAtAddress(varsRegister);
        stackMemorySection.setAtAddress(optopRegister, a);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.ILOAD_1:
        a = stackMemorySection.getAtAddress(varsRegister + 4);
        stackMemorySection.setAtAddress(optopRegister, a);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, StringTable.operand);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.IMUL:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "");
        optopRegister -= 4;
        b = stackMemorySection.getAtAddress(optopRegister);
        result = a * b;
        stackMemorySection.setAtAddress(optopRegister, result);
        optopRegister += 4;
        ++pcRegister;
        break;

    case OpCode.INT2BYTE:
        a = stackMemorySection.getAtAddress(optopRegister - 4);
        a = (byte) a;
        stackMemorySection.setAtAddress(optopRegister - 4, a);
        stackMemorySection.setLogicalValueAtAddress(optopRegister - 4, StringTable.operand);
        ++pcRegister;
        break;

    case OpCode.ISTORE_0:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        stackMemorySection.setLogicalValueAtAddress(optopRegister, "");
        stackMemorySection.setAtAddress(varsRegister, a);
        ++pcRegister;
        break;

    case OpCode.ISTORE_1:
        optopRegister -= 4;
        a = stackMemorySection.getAtAddress(optopRegister);
        stackMemorySection.setLogicalValueAtAddress(optopRegister + 4, "");
        stackMemorySection.setAtAddress(varsRegister + 4, a);
        ++pcRegister;
        break;
    }
}

From source file:MutableFloat.java

/**
 * Returns a suitable hashcode for this mutable.
 * 
 * @return a suitable hashcode
 */
public int hashCode() {
    return Float.floatToIntBits(value);
}

From source file:com.tibbo.linkserver.plugin.device.file.item.NumericItem.java

public short[] valueToShorts(Number value) {
    if (dataType == 2 || dataType == 3) {
        return (new short[] { toShort(value) });
    }/*ww  w .j  a  v a  2 s.c  o m*/
    if (dataType == 16) {
        short s = toShort(value);
        return (new short[] {
                (short) ((s / 1000) % 10 << 12 | (s / 100) % 10 << 8 | (s / 10) % 10 << 4 | s % 10) });
    }
    if (dataType == 4 || dataType == 5) {
        int i = toInt(value);
        return (new short[] { (short) (i >> 16), (short) i });
    }
    if (dataType == 6 || dataType == 7) {
        int i = toInt(value);
        return (new short[] { (short) i, (short) (i >> 16) });
    }
    if (dataType == 8) {
        int i = Float.floatToIntBits(value.floatValue());
        return (new short[] { (short) (i >> 16), (short) i });
    }
    if (dataType == 9) {
        int i = Float.floatToIntBits(value.floatValue());
        return (new short[] { (short) i, (short) (i >> 16) });
    }
    if (dataType == 17) {
        int i = toInt(value);
        return (new short[] {
                (short) ((i / 0x989680) % 10 << 12 | (i / 0xf4240) % 10 << 8 | (i / 0x186a0) % 10 << 4
                        | (i / 10000) % 10),
                (short) ((i / 1000) % 10 << 12 | (i / 100) % 10 << 8 | (i / 10) % 10 << 4 | i % 10) });
    }
    if (dataType == 10 || dataType == 11) {
        long l = value.longValue();
        return (new short[] { (short) (int) (l >> 48), (short) (int) (l >> 32), (short) (int) (l >> 16),
                (short) (int) l });
    }
    if (dataType == 12 || dataType == 13) {
        long l = value.longValue();
        return (new short[] { (short) (int) l, (short) (int) (l >> 16), (short) (int) (l >> 32),
                (short) (int) (l >> 48) });
    }
    if (dataType == 14) {
        long l = Double.doubleToLongBits(value.doubleValue());
        return (new short[] { (short) (int) (l >> 48), (short) (int) (l >> 32), (short) (int) (l >> 16),
                (short) (int) l });
    }
    if (dataType == 15) {
        long l = Double.doubleToLongBits(value.doubleValue());
        return (new short[] { (short) (int) l, (short) (int) (l >> 16), (short) (int) (l >> 32),
                (short) (int) (l >> 48) });
    } else {
        throw new RuntimeException(
                (new StringBuilder()).append("Unsupported data type: ").append(dataType).toString());
    }
}

From source file:ArrayByte.java

public void writeFloat(float v) {
    writeInt(Float.floatToIntBits(v));
}

From source file:com.facebook.presto.accumulo.io.AccumuloRecordCursor.java

@Override
public long getLong(int field) {
    checkFieldType(field, BIGINT, DATE, INTEGER, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT);
    Type type = getType(field);/*from w  w  w .  j ava 2 s  .  c  om*/
    if (type.equals(BIGINT)) {
        return serializer.getLong(fieldToColumnName[field]);
    } else if (type.equals(DATE)) {
        return MILLISECONDS.toDays(serializer.getDate(fieldToColumnName[field]).getTime());
    } else if (type.equals(INTEGER)) {
        return serializer.getInt(fieldToColumnName[field]);
    } else if (type.equals(REAL)) {
        return Float.floatToIntBits(serializer.getFloat(fieldToColumnName[field]));
    } else if (type.equals(SMALLINT)) {
        return serializer.getShort(fieldToColumnName[field]);
    } else if (type.equals(TIME)) {
        return serializer.getTime(fieldToColumnName[field]).getTime();
    } else if (type.equals(TIMESTAMP)) {
        return serializer.getTimestamp(fieldToColumnName[field]).getTime();
    } else if (type.equals(TINYINT)) {
        return serializer.getByte(fieldToColumnName[field]);
    } else {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported type " + getType(field));
    }
}

From source file:ObjectUtils.java

/**
 * Return the same value as <code>{@link Float#hashCode()}</code>.
 * @see Float#hashCode()//from w w  w.  j a  va 2 s  . c  om
 */
public static int hashCode(float flt) {
    return Float.floatToIntBits(flt);
}

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

public static DataTable fromStrings(List<String[]> rows, VariableType[] colTypes, String[] colNames,
        boolean hasHeaderRow) {
    if (rows == null || rows.size() == 0)
        return empty(colTypes, colNames);
    if (rows.size() == 1 && hasHeaderRow) {
        return empty(colTypes, colNames);
    }/*from  w w w  .  j  a v a 2  s  .  c  o  m*/

    if (hasHeaderRow && colNames == null) {
        colNames = rows.get(0);
    }

    int dim = rows.get(0).length;
    if (colTypes == null) {
        colTypes = getDefaultColTypes(dim);
    }
    if (colNames == null) {
        colNames = getDefaultColNames(colTypes, dim);
    }
    StringTable[] colStringToIntMap = new StringTable[colTypes.length];
    // don't waste space on string tables unless we need to
    for (int j = 0; j < colTypes.length; j++) {
        if (colTypes[j] == CATEGORICAL_STRING || colTypes[j] == TARGET_CATEGORICAL_STRING) {
            colStringToIntMap[j] = new StringTable();
        }
    }
    // process strings into ints using appropriate conversion
    List<int[]> rows2 = new ArrayList<>();
    for (int i = hasHeaderRow ? 1 : 0; i < rows.size(); i++) {
        String[] row = rows.get(i);
        int[] rowAsInts = new int[row.length];
        for (int j = 0; j < row.length; j++) {
            int col = 0;
            VariableType colType = colTypes[j];
            String colValue = row[j];
            switch (colType) {
            case CATEGORICAL_INT:
            case NUMERICAL_INT:
            case UNUSED_INT:
            case TARGET_CATEGORICAL_INT:
                if (!UNKNOWN_VALUE_STRINGS.contains(row[j])) {
                    col = Integer.valueOf(colValue);
                }
                break;
            case CATEGORICAL_STRING:
            case TARGET_CATEGORICAL_STRING:
            case UNUSED_STRING:
                if (!UNKNOWN_VALUE_STRINGS.contains(row[j])) {
                    col = colStringToIntMap[j].add(colValue);
                }
                break;
            case NUMERICAL_FLOAT:
            case UNUSED_FLOAT:
                if (!UNKNOWN_VALUE_STRINGS.contains(row[j])) {
                    col = Float.floatToIntBits(Float.valueOf(colValue));
                }
                break;
            }
            rowAsInts[j] = col;
        }
        rows2.add(rowAsInts);
    }
    DataTable t = new DataTable(rows2, colTypes, colNames, null);
    t.colStringToIntMap = colStringToIntMap;
    return t;
}

From source file:com.sindicetech.siren.search.node.NodeTermQuery.java

/** Returns a hash code value for this object. */
@Override//from w  w w.  j  a v  a2  s . c  o  m
public int hashCode() {
    return Float.floatToIntBits(this.getBoost()) ^ term.hashCode() ^ levelConstraint ^ upperBound ^ lowerBound;
}