API Reference › Builtin functions › float_bits
function

float_bits

float_bits(x) -> int / float_from_bits(bits) -> float

float_bits(x) returns the 32 bits of a float as an int, and float_from_bits(bits) reads them back. double_bits / double_from_bits do the same for a double with a long. Use them where a float has to travel as raw data: a file format, a network packet, or a words buffer shared with code that still stores bit patterns.

Parameters

xthe float to encode (float_bits), or the bits to decode (float_from_bits)

Example

program Bits {
  entry {
    print(float_bits(1.0))             # 1065353216 (0x3F800000)
    print(float_from_bits(0x40000000)) # 2.0
  }
}
← All symbols