'How to treat a float as an integer bit level in AssemblyScript
I need to implement some C code blow:
float number = 1.5f
long i = * ( long * ) &number;
It is not about to convert the value from float into integer. This data need to be modified bit level.
Solution 1:[1]
Just use reinterpret built-in function:
let num32: f32 = 1.5
let num64: f64 = 2.5
let uint32 = reinterpret<u32>(num32);
// uint32 <- 0x3fc00000
let uint64 = reinterpret<u64>(num64);
// uint64 <- 0x4004000000000000
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MaxGraey |
