2.3. Math bit helpers

The MATH_BITS module provides bit manipulation functions for floating point numbers, including type punning between integer and float representations, and efficient integer math operations like int_bits_to_float and float_bits_to_int.

All functions and symbols are in “math_bits” module, use require to get access to it.

require daslib/math_bits

Example:

require daslib/math_bits

    [export]
    def main() {
        let f = uint_bits_to_float(0x3F800000u)
        print("uint_bits_to_float(0x3F800000) = {f}\n")
        let back = float_bits_to_uint(1.0)
        print("float_bits_to_uint(1.0) = {back}\n")
    }
    // output:
    // uint_bits_to_float(0x3F800000) = 1
    // float_bits_to_uint(1.0) = 0x3f800000

2.3.1. float in int,uint

2.3.1.1. int_bits_to_float

math_bits::int_bits_to_float(x: int2) : float2()

bit representation of x is interpreted as a float

Arguments
  • x : int2

math_bits::int_bits_to_float(x: int) : float()
math_bits::int_bits_to_float(x: int4) : float4()
math_bits::int_bits_to_float(x: int3) : float3()

2.3.1.2. uint_bits_to_float

math_bits::uint_bits_to_float(x: uint3) : float3()

bit representation of x is interpreted as a float3

Arguments
  • x : uint3

math_bits::uint_bits_to_float(x: uint2) : float2()
math_bits::uint_bits_to_float(x: uint) : float()
math_bits::uint_bits_to_float(x: uint4) : float4()

2.3.2. int,uint in float

2.3.2.1. float_bits_to_int

math_bits::float_bits_to_int(x: float2) : int2()

bit representation of x is interpreted as an int2

Arguments
  • x : float2

math_bits::float_bits_to_int(x: float) : int()
math_bits::float_bits_to_int(x: float4) : int4()
math_bits::float_bits_to_int(x: float3) : int3()

2.3.2.2. float_bits_to_uint

math_bits::float_bits_to_uint(x: float3) : uint3()

bit representation of x is interpreted as a uint3

Arguments
  • x : float3

math_bits::float_bits_to_uint(x: float2) : uint2()
math_bits::float_bits_to_uint(x: float) : uint()
math_bits::float_bits_to_uint(x: float4) : uint4()

2.3.3. int64,uint64 in double

math_bits::double_bits_to_int64(x: double) : int64()

bit representation of x is interpreted as a int64

Arguments
  • x : double

math_bits::double_bits_to_uint64(x: double) : uint64()

bit representation of x is interpreted as a uint64

Arguments
  • x : double

math_bits::int64_bits_to_double(x: int64) : double()

bit representation of x is interpreted as a double

Arguments
  • x : int64

math_bits::uint64_bits_to_double(x: uint64) : double()

bit representation of x is interpreted as a double

Arguments
  • x : uint64

2.3.4. bit-cast vec4f

math_bits::cast_to_int16(data: float4) : int16()

return an int16 which was bit-cast from x

Arguments
  • data : float4

math_bits::cast_to_int32(data: float4) : int()

return an int32 which was bit-cast from x

Arguments
  • data : float4

math_bits::cast_to_int64(data: float4) : int64()

return an int64 which was bit-cast from x

Arguments
  • data : float4

math_bits::cast_to_int8(data: float4) : int8()

return an int8 which was bit-cast from x

Arguments
  • data : float4

math_bits::cast_to_pointer(data: float4) : void?()

return a pointer which was bit-cast from x

Arguments
  • data : float4

math_bits::cast_to_string(data: float4) : string()

return a string which pointer was bit-cast from x

Arguments
  • data : float4

2.3.4.1. cast_to_vec4f

math_bits::cast_to_vec4f(x: int64) : float4()

return a float4 which stores bit-cast version of x

Arguments
  • x : int64

math_bits::cast_to_vec4f(x: bool) : float4()