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:org.paxle.se.index.lucene.impl.Converter.java

private static Number field2number(Fieldable lfield, org.paxle.core.doc.Field<?> pfield) {
    final long num;
    if (pfield.isIndex()) {
        num = PaxleNumberTools.stringToLong(lfield.stringValue());
    } else {/*w  w  w .  j a  v a 2s.  com*/
        num = PaxleNumberTools.toLong(lfield.binaryValue());
    }

    if (Double.class.isAssignableFrom(pfield.getType())) {
        return Double.valueOf(Double.longBitsToDouble(num));
    } else if (Float.class.isAssignableFrom(pfield.getType())) {
        return Float.valueOf(Float.intBitsToFloat((int) num));
    } else {
        return Long.valueOf(num);
    }
}

From source file:org.apache.hadoop.hive.serde2.lazybinary.fast.LazyBinaryDeserializeRead.java

@Override
public float readFloat() throws IOException {
    // Last item -- ok to be at end.
    if (offset + 4 > end) {
        warnBeyondEof();/*from ww w  .  java2s .  c om*/
    }
    float result = Float.intBitsToFloat(LazyBinaryUtils.byteArrayToInt(bytes, offset));
    offset += 4;

    // Move past this NOT NULL field.
    fieldIndex++;

    // Every 8 fields we read a new NULL byte.
    if (fieldIndex < fieldCount) {
        if ((fieldIndex % 8) == 0) {
            // Get next null byte.
            if (offset >= end) {
                warnBeyondEof();
            }
            nullByte = bytes[offset++];
        }
    }

    return result;
}

From source file:org.elasticsearch.index.engine.internal.InternalEngine.java

public void fillHashMap() {
    IndexSearcher indexSearcher = null;//ww  w .ja v a  2s.  c o m
    if (searcherManager == null) {
        throw new EngineClosedException(shardId);
    }
    try {
        indexSearcher = searcherManager.acquire();
    } catch (Throwable ex) {
        logger.error("failed to acquire searcher, source {}", ex);
        throw new EngineException(shardId, ex.getMessage());
    }

    if (indexWriter == null) {
        throw new EngineClosedException(shardId, failedEngine);
    }

    // load features now
    IndexReader reader = indexSearcher.getIndexReader();
    org.apache.lucene.util.Bits liveDocs = MultiFields.getLiveDocs(reader);

    int maxDoc = indexSearcher.getIndexReader().maxDoc();

    try {
        for (int idoc = 0; idoc < maxDoc; idoc++) {
            if (liveDocs != null && !liveDocs.get(idoc))
                continue;
            org.elasticsearch.index.fieldvisitor.FieldsVisitor visitor = new AllFieldsVisitor();
            reader.document(idoc, visitor);
            String key = visitor.uid().toString();
            String[] values = null;
            try {
                values = visitor.source().toUtf8().split("\"");
            } catch (Throwable e) {
                continue;
            }
            if (values.length < 5) {
                continue;
            }

            byte[] feature = Base64.decodeBase64(values[3]);
            int length = feature.length / 4;
            float[] value = new float[length];

            for (int i = 0; i < length; i++) {
                int j = i * 4;
                int asInt = (feature[j + 0] & 0xFF) | ((feature[j + 1] & 0xFF) << 8)
                        | ((feature[j + 2] & 0xFF) << 16) | ((feature[j + 3] & 0xFF) << 24);
                value[i] = Float.intBitsToFloat(asInt);
            }
            features.put(key, value);

        }
    } catch (Throwable ex) {
        logger.error("failed to read document, source {}", ex);
        throw new EngineClosedException(shardId, failedEngine);
    }
}

From source file:org.deeplearning4j.models.embeddings.loader.WordVectorSerializer.java

/**
 * Read a string from a data input stream Credit to:
 * https://github.com/NLPchina/Word2VEC_java/blob/master/src/com/ansj/vec/Word2VEC.java
 *
 * @param b// www. ja va 2 s .c  o m
 * @return
 * @throws IOException
 */
public static float getFloat(byte[] b) {
    int accum = 0;
    accum = accum | (b[0] & 0xff) << 0;
    accum = accum | (b[1] & 0xff) << 8;
    accum = accum | (b[2] & 0xff) << 16;
    accum = accum | (b[3] & 0xff) << 24;
    return Float.intBitsToFloat(accum);
}

From source file:org.eclipsetrader.directa.internal.core.connector.BackfillConnector.java

private float getFloat(byte arr[], int start) {
    int i = 0;// w  ww  .  j a v  a2  s . co  m
    int len = 4;
    int cnt = 0;
    int tmp[] = new int[len];
    for (i = start; i < start + len; i++) {
        tmp[cnt] = arr[i];
        cnt++;
    }

    int accum = 0;
    i = 0;
    for (int shiftBy = 0; shiftBy < 32; shiftBy += 8) {
        accum = (int) (accum | (long) (tmp[i] & 0xff) << shiftBy);
        i++;
    }

    return Float.intBitsToFloat(accum);
}

From source file:haven.Utils.java

public static float float32d(byte[] buf, int off) {
    return (Float.intBitsToFloat(int32d(buf, off)));
}

From source file:haven.Utils.java

public static void float9995d(int word, float[] ret) {
    int xb = (word & 0x7f800000) >> 23, xs = ((word & 0x80000000) >> 31) & 1, yb = (word & 0x003fc000) >> 14,
            ys = ((word & 0x00400000) >> 22) & 1, zb = (word & 0x00001fd0) >> 5,
            zs = ((word & 0x00002000) >> 13) & 1;
    int me = (word & 0x1f) - 15;
    int xe = Integer.numberOfLeadingZeros(xb), ye = Integer.numberOfLeadingZeros(yb),
            ze = Integer.numberOfLeadingZeros(zb);
    if (xe == 32)
        ret[0] = 0;//from   w  w  w . j  a v a2  s  . c  om
    else
        ret[0] = Float
                .intBitsToFloat((xs << 31) | ((me - (xe - 24) + 126) << 23) | ((xb << (xe - 8)) & 0x007fffff));
    if (ye == 32)
        ret[1] = 0;
    else
        ret[1] = Float
                .intBitsToFloat((ys << 31) | ((me - (ye - 24) + 126) << 23) | ((yb << (ye - 8)) & 0x007fffff));
    if (ze == 32)
        ret[2] = 0;
    else
        ret[2] = Float
                .intBitsToFloat((zs << 31) | ((me - (ze - 24) + 126) << 23) | ((zb << (ze - 8)) & 0x007fffff));
}

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:parser.axml.ManifestParser.java

private String makeAttributeValue(AXMLParser parser, int index) {
    final int type = parser.getAttributeValueType(index);
    final int data = parser.getAttributeValue(index);

    if (type == TYPE_STRING) {
        return parser.getAttributeValueString(index);
    }/*from   w ww.  j a  va  2  s .c  om*/
    if (type == TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TYPE_REFERENCE) {
        if (data >>> 24 == 1 || m_arsc == null)
            return String.format("@%s%08X", getPackage(data), data);

        String name = new ARSCParser().parser(m_arsc, data);
        if (name != null)
            return name;
        else
            return String.format("@%08X", data);
    }
    if (type == TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & COMPLEX_UNIT_MASK];
    }
    if (type == TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & COMPLEX_UNIT_MASK];
    }
    if (type >= TYPE_FIRST_COLOR_INT && type <= TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TYPE_FIRST_INT && type <= TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);

}

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

private NumericField loadNumericField(FieldInfo fi, int numeric) throws IOException {
    assert numeric != 0;
    switch (numeric) {
    case FieldsWriter.FIELD_IS_NUMERIC_INT:
        return new NumericField(fi.name, Field.Store.YES, fi.isIndexed).setIntValue(fieldsStream.readVVInt());
    case FieldsWriter.FIELD_IS_NUMERIC_LONG:
        return new NumericField(fi.name, Field.Store.YES, fi.isIndexed).setLongValue(fieldsStream.readVVLong());
    case FieldsWriter.FIELD_IS_NUMERIC_FLOAT:
        return new NumericField(fi.name, Field.Store.YES, fi.isIndexed)
                .setFloatValue(Float.intBitsToFloat(fieldsStream.readVVVInt()));
    case FieldsWriter.FIELD_IS_NUMERIC_DOUBLE:
        return new NumericField(fi.name, Field.Store.YES, fi.isIndexed)
                .setDoubleValue(Double.longBitsToDouble(fieldsStream.readVVVLong()));
    default://  ww w.j ava  2s  .  co  m
        throw new FieldReaderException("Invalid numeric type: " + Integer.toHexString(numeric));
    }
}