Quirrel4.41.0

iostream.casti2f

Defined in module "iostream"
from "iostream" import casti2f
pure fastcall casti2f(i: int): float

Reinterprets the bits of an integer as a float

Parameters

iintthe value whose low 32 bits become the result

Return value

The float whose bit pattern equals the low 32 bits of i.

Notes

A float is 4 bytes, so only the low 32 bits of i matter; any bits above that are ignored, even though i itself can hold a wider integer.

Example

examples/iostream/casti2f.nut
from "iostream" import casti2f, castf2i

println("casti2f(castf2i(2.5)) =", casti2f(castf2i(2.5)))  // round trip returns the original float

// only the low 32 bits matter; a wider integer's upper bits are ignored
println("casti2f(0x89) == casti2f(0x100000089) =", casti2f(0x89) == casti2f(0x100000089))
Output:
casti2f(castf2i(2.5)) = 2.5
casti2f(0x89) == casti2f(0x100000089) = true

See also

castf2iReinterprets the bits of a float as an integer
swap4Byte-swaps a 32-bit value
iostreammodule index