/** * Presumes float encoded as IEEE 754 floating-point "single format" * @param bytes byte array * @return Float made from passed byte array. */ public static float toFloat(byte [] bytes) { return toFloat(bytes, 0); }
/** * Read a {@code float} value from the buffer {@code buff}. */ public float decodeFloat(byte[] buff, int offset) { return Bytes.toFloat(buff, offset); }
private static float decodeUnsignedFloat(byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT); float v = Bytes.toFloat(b, o); if (v < 0) { throw new RuntimeException(); } return v; }
public void testToFloat() throws Exception { float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; for (int i = 0; i < floats.length; i++) { byte [] b = Bytes.toBytes(floats[i]); assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } }
return Bytes.toLong(value); case 6: return Bytes.toFloat(value); case 7: return Bytes.toDouble(value);
@Override public Float decode(PositionedByteRange src) { float val = Bytes.toFloat(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
res = Bytes.toBoolean(bytes); } else if (Float.class == clazz || float.class == clazz) { res = Bytes.toFloat(bytes); } else if (Double.class == clazz || double.class == clazz) { res = Bytes.toDouble(bytes);
res = Bytes.toFloat(bytes);
@Override public float decodeFloat(byte[] b, int o, ColumnModifier columnModifier) { if (columnModifier != null) { b = columnModifier.apply(b, o, new byte[Bytes.SIZEOF_FLOAT], 0, Bytes.SIZEOF_FLOAT); } float v = Bytes.toFloat(b, o); if (v < 0) { throw new IllegalDataException(); } return v; } }
@Override public float decodeFloat(byte[] b, int o, SortOrder sortOrder) { Preconditions.checkNotNull(sortOrder); checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT); if (sortOrder == SortOrder.DESC) { b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_FLOAT], 0, Bytes.SIZEOF_FLOAT); o = 0; } float v = Bytes.toFloat(b, o); if (v < 0) { throw newIllegalDataException(); } return v; } }
return Bytes.toFloat(b);
return Bytes.toFloat(b);
/** * Read a {@code float} value from the buffer {@code buff}. */ public float decodeFloat(byte[] buff, int offset) { return Bytes.toFloat(buff, offset); }
/** * Presumes float encoded as IEEE 754 floating-point "single format" * @param bytes byte array * @return Float made from passed byte array. */ public static float toFloat(byte [] bytes) { return toFloat(bytes, 0); }
/** * Presumes float encoded as IEEE 754 floating-point "single format" * @param bytes byte array * @return Float made from passed byte array. */ public static float toFloat(byte [] bytes) { return toFloat(bytes, 0); }
/** * Presumes float encoded as IEEE 754 floating-point "single format" * @param bytes byte array * @return Float made from passed byte array. */ public static float toFloat(byte [] bytes) { return toFloat(bytes, 0); }
@Converter public static Float bytesToFloat(byte[] bytes) { return Bytes.toFloat(bytes); } }
public void testToFloat() throws Exception { float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; for (int i = 0; i < floats.length; i++) { byte [] b = Bytes.toBytes(floats[i]); assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } }
public void testToFloat() throws Exception { float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; for (int i = 0; i < floats.length; i++) { byte [] b = Bytes.toBytes(floats[i]); assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } }