From 9d7986bbfd44b69a623fa29528b5d13000b91c77 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 7 Dec 2022 20:38:00 +0100 Subject: advanced translate --- evc/src/format/ser.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'evc/src/format') diff --git a/evc/src/format/ser.rs b/evc/src/format/ser.rs index 731a7a3..817cafe 100644 --- a/evc/src/format/ser.rs +++ b/evc/src/format/ser.rs @@ -246,6 +246,29 @@ impl Ser for Small> { } } +pub fn map_scalar8(v: i8) -> f32 { + match v { + 0 => 0.0, + x if x > 0 => 2f32.powf((x as f32).abs() / 2.0 - 2.0), + x => -2f32.powf((-x as f32).abs() / 2.0 - 2.0), + } +} +// const SCALAR8: [f32; 256] = gen_scalar8_lookup(); +// const fn gen_scalar8_lookup() -> [f32; 256] { +// let mut a = [0.0; 256]; +// let mut i = 0usize; +// while i < 256 { +// a[i as usize] = if i == 0 { +// 0.0 +// } else { +// let x = i as i8 as f32; +// x.signum() * 2f32.powf(x.abs() / 2.0 - 2.0) +// }; +// i += 1; +// } +// a +// } + #[cfg(test)] mod test { use super::{Ser, Sink}; -- cgit v1.2.3-70-g09d2