java.lang.Float.intBitsToFloat()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(269)

本文整理了Java中java.lang.Float.intBitsToFloat()方法的一些代码示例,展示了Float.intBitsToFloat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Float.intBitsToFloat()方法的具体详情如下:
包路径:java.lang.Float
类名称:Float
方法名:intBitsToFloat

Float.intBitsToFloat介绍

[英]Returns the IEEE 754 single precision float corresponding to the given bits.
[中]返回与给定位对应的{$0$}单精度浮点。

代码示例

代码示例来源:origin: libgdx/libgdx

/** 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);
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * 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);
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * 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);
}

代码示例来源:origin: libgdx/libgdx

/** 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);
}

代码示例来源:origin: netty/netty

/**
 * 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());
}

代码示例来源:origin: netty/netty

@Override
public float getFloat(int index) {
  return Float.intBitsToFloat(getInt(index));
}

代码示例来源:origin: netty/netty

@Override
public float readFloat() throws IOException {
  return Float.intBitsToFloat(readInt());
}

代码示例来源:origin: netty/netty

@Override
public float getFloat(int index) {
  return Float.intBitsToFloat(getInt(index));
}

代码示例来源:origin: netty/netty

@Override
public float readFloat() {
  return Float.intBitsToFloat(readInt());
}

代码示例来源:origin: netty/netty

@Override
public final float getFloat(int index) {
  return Float.intBitsToFloat(getInt(index));
}

代码示例来源:origin: netty/netty

@Override
public float readFloat() {
  return Float.intBitsToFloat(readInt());
}

代码示例来源:origin: commons-io/commons-io

/**
 * 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 ) ) );
}

代码示例来源:origin: netty/netty

/**
 * 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));
}

代码示例来源:origin: hankcs/HanLP

/**
 * 将一个4位字节数组转换为浮点数。<br>
 * 注意,函数中不会对字节数组长度进行判断,请自行保证传入参数的正确性。
 *
 * @param b 字节数组
 * @return 浮点数
 */
public static float bytesToFloat(byte[] b)
{
  return Float.intBitsToFloat(bytesToInt(b));
}

代码示例来源:origin: google/guava

/**
 * 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());
}

代码示例来源:origin: google/guava

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));
}

代码示例来源:origin: google/guava

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);
}

代码示例来源:origin: google/guava

public void testNewDataOutput_writeFloat() {
 ByteArrayDataOutput out = ByteStreams.newDataOutput();
 out.writeFloat(Float.intBitsToFloat(0x12345678));
 out.writeFloat(Float.intBitsToFloat(0x76543210));
 assertEquals(bytes, out.toByteArray());
}

代码示例来源:origin: google/guava

public void testFloat() {
 TestHasher hasher = new TestHasher();
 hasher.putFloat(Float.intBitsToFloat(0x04030201));
 hasher.assertBytes(new byte[] {1, 2, 3, 4});
}

代码示例来源:origin: google/guava

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});
}

相关文章