From d17baa754f070aa913005b289305521b087b69a2 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sun, 24 Nov 2024 21:54:20 +0100 Subject: [PATCH] lib8: trig: style++ --- src/lib8/trig.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lib8/trig.rs b/src/lib8/trig.rs index 00db121..1797d6f 100644 --- a/src/lib8/trig.rs +++ b/src/lib8/trig.rs @@ -11,31 +11,31 @@ impl Trig8 for u8 { fn sin8(self) -> u8 { let mut offset: u8 = self; if self & 0x40 != 0 { - offset = 255 - offset; - } - offset &= 0x3f; + offset = 255 - offset; + } + offset &= 0x3f; - let mut secoffset: u8 = offset & 0x0f; + let mut secoffset: u8 = offset & 0x0f; if self & 0x40 != 0 { - secoffset += 1; - } + secoffset += 1; + } - let section: u8 = offset.unsigned_shr(4); - let s2: u8 = section * 2; - let b: u8 = b_m16_interleave[s2 as usize]; - let m16: u8 = b_m16_interleave[s2 as usize + 1]; - let mx: u8 = m16.wrapping_mul(secoffset).unsigned_shr(4); - let mut y: i8 = mx as i8 + b as i8; + let section: u8 = offset.unsigned_shr(4); + let s2: u8 = section * 2; + let b: u8 = b_m16_interleave[s2 as usize]; + let m16: u8 = b_m16_interleave[s2 as usize + 1]; + let mx: u8 = m16.wrapping_mul(secoffset).unsigned_shr(4); + let mut y: i8 = mx as i8 + b as i8; if self & 0x80 != 0 { - y = -y; + y = -y; + } + y = y.wrapping_add(128u8 as i8); + return y as u8; } - y = y.wrapping_add(128u8 as i8); - return y as u8; -} fn cos8(self) -> u8 { sin8(self.wrapping_add(64)) -} + } } impl Trig8 for usize {