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

int_bits_to_float(x: int ): float

bit representation of x is interpreted as a float

Arguments:
  • x : int

int_bits_to_float(x: int2 ): float2
int_bits_to_float(x: int3 ): float3
int_bits_to_float(x: int4 ): float4

2.3.1.2. uint_bits_to_float

uint_bits_to_float(x: uint ): float

bit representation of x is interpreted as a float

Arguments:
  • x : uint

uint_bits_to_float(x: uint2 ): float2
uint_bits_to_float(x: uint3 ): float3
uint_bits_to_float(x: uint4 ): float4

2.3.2. int,uint in float

2.3.2.1. float_bits_to_int

float_bits_to_int(x: float ): int

bit representation of x is interpreted as a int

Arguments:
  • x : float

float_bits_to_int(x: float2 ): int2
float_bits_to_int(x: float3 ): int3
float_bits_to_int(x: float4 ): int4

2.3.2.2. float_bits_to_uint

float_bits_to_uint(x: float ): uint

bit representation of x is interpreted as a uint

Arguments:
  • x : float

float_bits_to_uint(x: float2 ): uint2
float_bits_to_uint(x: float3 ): uint3
float_bits_to_uint(x: float4 ): uint4

2.3.3. int64,uint64 in double

double_bits_to_int64(x: double ): int64

bit representation of x is interpreted as a int64

Arguments:
  • x : double

double_bits_to_uint64(x: double ): uint64

bit representation of x is interpreted as a uint64

Arguments:
  • x : double

int64_bits_to_double(x: int64 ): double

bit representation of x is interpreted as a double

Arguments:
  • x : int64

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

cast_to_int16(data: float4 ): int16

return an int16 which was bit-cast from x

Arguments:
  • data : float4

cast_to_int32(data: float4 ): int

return an int32 which was bit-cast from x

Arguments:
  • data : float4

cast_to_int64(data: float4 ): int64

return an int64 which was bit-cast from x

Arguments:
  • data : float4

cast_to_int8(data: float4 ): int8

return an int8 which was bit-cast from x

Arguments:
  • data : float4

cast_to_pointer(data: float4 ): void?

return a pointer which was bit-cast from x

Arguments:
  • data : float4

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

cast_to_vec4f(x: bool ): float4

return a float4 which stores bit-cast version of x

Arguments:
  • x : bool

cast_to_vec4f(x: int64 ): float4