/** Encodes the ABGR int color as a float. The alpha is compressed to 0-254 to avoid using bits in the NaN range (see * {@link Float#intBitsToFloat(int)} javadocs). Rendering which uses colors encoded as floats should expand the 0-254 back to * 0-255. */ public static float intToFloatColor (int value) { return Float.intBitsToFloat(value & 0xfeffffff); }
/** * to int. * * @param b byte array. * @param off offset. * @return int. */ public static float bytes2float(byte[] b, int off) { int i = ((b[off + 3] & 0xFF) << 0) + ((b[off + 2] & 0xFF) << 8) + ((b[off + 1] & 0xFF) << 16) + ((b[off + 0]) << 24); return Float.intBitsToFloat(i); }
/** * to int. * * @param b byte array. * @param off offset. * @return int. */ public static float bytes2float(byte[] b, int off) { int i = ((b[off + 3] & 0xFF) << 0) + ((b[off + 2] & 0xFF) << 8) + ((b[off + 1] & 0xFF) << 16) + ((b[off + 0]) << 24); return Float.intBitsToFloat(i); }
/** Encodes the ABGR int color as a float. The alpha is compressed to 0-254 to avoid using bits in the NaN range (see * {@link Float#intBitsToFloat(int)} javadocs). Rendering which uses colors encoded as floats should expand the 0-254 back to * 0-255. */ public static float intToFloatColor (int value) { return Float.intBitsToFloat(value & 0xfeffffff); }
/** * Gets a 32-bit floating point number at the current {@code readerIndex} * in Little Endian Byte Order and increases the {@code readerIndex} * by {@code 4} in this buffer. * * @throws IndexOutOfBoundsException * if {@code this.readableBytes} is less than {@code 4} */ public float readFloatLE() { return Float.intBitsToFloat(readIntLE()); }
@Override public float getFloat(int index) { return Float.intBitsToFloat(getInt(index)); }
@Override public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
@Override public float getFloat(int index) { return Float.intBitsToFloat(getInt(index)); }
@Override public float readFloat() { return Float.intBitsToFloat(readInt()); }
@Override public final float getFloat(int index) { return Float.intBitsToFloat(getInt(index)); }
@Override public float readFloat() { return Float.intBitsToFloat(readInt()); }
/** * Converts a "float" value between endian systems. * @param value value to convert * @return the converted value */ public static float swapFloat(final float value) { return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) ); }
/** * Gets a 32-bit floating point number at the specified absolute * {@code index} in this buffer in Little Endian Byte Order. * This method does not modify {@code readerIndex} or * {@code writerIndex} of this buffer. * * @throws IndexOutOfBoundsException * if the specified {@code index} is less than {@code 0} or * {@code index + 4} is greater than {@code this.capacity} */ public float getFloatLE(int index) { return Float.intBitsToFloat(getIntLE(index)); }
/** * 将一个4位字节数组转换为浮点数。<br> * 注意,函数中不会对字节数组长度进行判断,请自行保证传入参数的正确性。 * * @param b 字节数组 * @return 浮点数 */ public static float bytesToFloat(byte[] b) { return Float.intBitsToFloat(bytesToInt(b)); }
/** * Reads a {@code float} as specified by {@link DataInputStream#readFloat()}, except using * little-endian byte order. * * @return the next four bytes of the input stream, interpreted as a {@code float} in * little-endian byte order * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // to skip some bytes @Override public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
private void initializeData(DataOutputStream out) throws IOException { /* Write out various test values NORMALLY */ out.write(new byte[] {-100, 100}); out.writeBoolean(true); out.writeBoolean(false); out.writeByte(100); out.writeByte(-100); out.writeByte((byte) 200); out.writeChar('a'); out.writeShort((short) -30000); out.writeShort((short) 50000); out.writeInt(0xCAFEBABE); out.writeLong(0xDEADBEEFCAFEBABEL); out.writeUTF("Herby Derby"); out.writeFloat(Float.intBitsToFloat(0xCAFEBABE)); out.writeDouble(Double.longBitsToDouble(0xDEADBEEFCAFEBABEL)); }
public void testNewDataInput_readFloat() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals(Float.intBitsToFloat(0x12345678), in.readFloat(), 0.0); assertEquals(Float.intBitsToFloat(0x76543210), in.readFloat(), 0.0); }
public void testNewDataOutput_writeFloat() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeFloat(Float.intBitsToFloat(0x12345678)); out.writeFloat(Float.intBitsToFloat(0x76543210)); assertEquals(bytes, out.toByteArray()); }
public void testFloat() { TestHasher hasher = new TestHasher(); hasher.putFloat(Float.intBitsToFloat(0x04030201)); hasher.assertBytes(new byte[] {1, 2, 3, 4}); }
public void testFloat() { Sink sink = new Sink(4); sink.putFloat(Float.intBitsToFloat(0x04030201)); HashCode unused = sink.hash(); sink.assertInvariants(4); sink.assertBytes(new byte[] {1, 2, 3, 4}); }