1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! Calculate length of the hypotenuse of a right triangle.

use super::F32;

impl F32 {
    /// Calculate the length of the hypotenuse of a right-angle triangle.
    pub fn hypot(self, rhs: Self) -> Self {
        (self * self + rhs * rhs).sqrt()
    }
}

#[cfg(test)]
mod tests {
    use super::F32;

    #[test]
    fn sanity_check() {
        let x = F32(3.0);
        let y = F32(4.0);
        let difference = x.hypot(y) - F32(25.0).sqrt();
        assert!(difference.abs() <= F32::EPSILON);
    }
}