trey decoder 2.0
This commit is contained in:
parent
9003f88a9d
commit
716354df2b
48
src/v1.rs
48
src/v1.rs
@ -1,53 +1,19 @@
|
|||||||
use binrw::{binrw,BinReaderExt,io::TakeSeekExt};
|
use binrw::{binrw,BinReaderExt,io::TakeSeekExt};
|
||||||
|
|
||||||
// whatever this is
|
// the bit chunks are deposited in reverse
|
||||||
fn trey_float(f:f32)->f32{
|
fn trey_float(f:f32)->f32{
|
||||||
let bits=f.to_bits();
|
let bits=f.to_bits();
|
||||||
let s=bits&1!=0;
|
let s=bits&1;
|
||||||
let e=((bits>>1)&((1<<8)-1)) as i32;
|
let e=(bits>>1)&((1<<8)-1);
|
||||||
let m=(bits>>(1+8))&((1<<23)-1);
|
let m=(bits>>(1+8))&((1<<23)-1);
|
||||||
if e==255{
|
f32::from_bits(m|(e<<23)|(s<<31))
|
||||||
if m==0{
|
|
||||||
if s{
|
|
||||||
f32::NEG_INFINITY
|
|
||||||
}else{
|
|
||||||
f32::INFINITY
|
|
||||||
}
|
|
||||||
}else if m==1{
|
|
||||||
f32::NAN
|
|
||||||
}else{
|
|
||||||
// this is supposed to be QNAN but idk how to say it in rust
|
|
||||||
f32::NAN
|
|
||||||
}
|
|
||||||
}else if e==0{
|
|
||||||
if s{-(m as f32)*2.0f32.powi(-149)}else{(m as f32)*2.0f32.powi(-149)}
|
|
||||||
}else{
|
|
||||||
if s{-(m as f32/2.0f32.powi(23)+1.0)*2.0f32.powi(e-127)}else{(m as f32/2.0f32.powi(23)+1.0)*2.0f32.powi(e-127)}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn trey_double(f:f64)->f64{
|
fn trey_double(f:f64)->f64{
|
||||||
let bits=f.to_bits();
|
let bits=f.to_bits();
|
||||||
let s=bits&1!=0;
|
let s=bits&1;
|
||||||
let e=((bits>>1)&((1<<11)-1)) as i32;
|
let e=(bits>>1)&((1<<11)-1);
|
||||||
let m=(bits>>(1+11))&((1<<52)-1);
|
let m=(bits>>(1+11))&((1<<52)-1);
|
||||||
if e==2047{
|
f64::from_bits(m|(e<<52)|(s<<63))
|
||||||
if m==0{
|
|
||||||
if s{
|
|
||||||
f64::NEG_INFINITY
|
|
||||||
}else{
|
|
||||||
f64::INFINITY
|
|
||||||
}
|
|
||||||
}else if m==1{
|
|
||||||
f64::NAN
|
|
||||||
}else{
|
|
||||||
// this is supposed to be QNAN but idk how to say it in rust
|
|
||||||
f64::NAN
|
|
||||||
}
|
|
||||||
}else if e==0{
|
|
||||||
if s{-(m as f64)*2.0f64.powi(-1074)}else{(m as f64)*2.0f64.powi(-1074)}
|
|
||||||
}else{
|
|
||||||
if s{-(m as f64/2.0f64.powi(52)+1.0)*2.0f64.powi(e-1023)}else{(m as f64/2.0f64.powi(52)+1.0)*2.0f64.powi(e-1023)}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user