iostream.casti2f
Reinterprets the bits of an integer as a float
Parameters
i | int | the 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
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) = trueSee also
castf2i | Reinterprets the bits of a float as an integer |
swap4 | Byte-swaps a 32-bit value |
| iostream | module index |