Skip to content

Instantly share code, notes, and snippets.

View pehcy's full-sized avatar
🛸
is real

MurphyShark pehcy

🛸
is real
View GitHub Profile
@pehcy
pehcy / main.rs
Created January 27, 2023 14:52
Convert floating number (f64) into integer representation
use std::mem;
fn main() {
let a: f64 = 1.0 / 3.0;
println!("{:?}", integer_decode(a));
}
fn integer_decode(val: f64) -> (u64, i16, i8) {
let bits: u64 = unsafe { std::mem::transmute(val) };
let sgn: i8 = if bits >> 63 == 0 { 1 } else { -1 };