micromath/float/
hypot.rs

1//! Calculate length of the hypotenuse of a right triangle.
2
3use super::F32;
4
5impl F32 {
6    /// Calculate the length of the hypotenuse of a right-angle triangle.
7    pub fn hypot(self, rhs: Self) -> Self {
8        (self * self + rhs * rhs).sqrt()
9    }
10}
11
12#[cfg(test)]
13mod tests {
14    use super::F32;
15
16    #[test]
17    fn sanity_check() {
18        let x = F32(3.0);
19        let y = F32(4.0);
20        let difference = x.hypot(y) - F32(25.0).sqrt();
21        assert!(difference.abs() <= F32::EPSILON);
22    }
23}