use num::PrimInt; const b_m16_interleave: [u8; 8] = [0, 49, 49, 41, 90, 27, 117, 10]; pub fn sin8(theta: u8) -> u8 { let mut offset: u8 = theta; if theta & 0x40 != 0 { offset = 255 - offset; } offset &= 0x3f; let mut secoffset: u8 = offset & 0x0f; if theta & 0x40 != 0 { 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; if theta & 0x80 != 0 { y = -y; } y = y.wrapping_add(128u8 as i8); return y as u8; } pub fn cos8(theta: u8) -> u8 { sin8(theta.wrapping_add(64)) }