| 1 | //! Simultaneously computes the sine and cosine of the number, `x`. |
| 2 | |
| 3 | use super::F32; |
| 4 | |
| 5 | impl F32 { |
| 6 | /// Simultaneously computes the sine and cosine of the number, `x`. |
| 7 | /// Returns `(sin(x), cos(x))`. |
| 8 | pub fn sin_cos(self) -> (Self, Self) { |
| 9 | (self.sin(), self.cos()) |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | #[cfg (test)] |
| 14 | mod tests { |
| 15 | use super::F32; |
| 16 | |
| 17 | const TEST_VECTORS: &[f32] = &[ |
| 18 | 0.000, 0.140, 0.279, 0.419, 0.559, 0.698, 0.838, 0.977, 1.117, 1.257, 1.396, 1.536, 1.676, |
| 19 | 1.815, 1.955, 2.094, 2.234, 2.374, 2.513, 2.653, 2.793, 2.932, 3.072, 3.211, 3.351, 3.491, |
| 20 | 3.630, 3.770, 3.910, 4.049, 4.189, 4.328, 4.468, 4.608, 4.747, 4.887, 5.027, 5.166, 5.306, |
| 21 | 5.445, 5.585, 5.725, 5.864, 6.004, 6.144, 6.283, |
| 22 | ]; |
| 23 | |
| 24 | #[test ] |
| 25 | fn sanity_check() { |
| 26 | for &x in TEST_VECTORS { |
| 27 | let sin_x = F32(x).sin(); |
| 28 | let cos_x = F32(x).cos(); |
| 29 | |
| 30 | assert_eq!(F32(x).sin_cos(), (sin_x, cos_x)); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |