pub trait Hypot {
// Required method
fn hypot(self, other: &Self) -> Self;
}Expand description
Trait for computing the Euclidean distance (hypotenuse) between two values.
This trait provides the hypot function, which computes sqrt(x² + y²) in a way
that avoids overflow and underflow for intermediate calculations. This is the length
of the hypotenuse of a right triangle with sides of length |x| and |y|.
§Mathematical Background
Computing sqrt(x² + y²) directly can overflow if x or y are very large,
or underflow if they are very small. The hypot function uses scaling techniques
to avoid these issues while maintaining numerical accuracy.
§Examples
use num_valid::functions::Hypot;
let x = 3.0f64;
let y = 4.0f64;
let distance = Hypot::hypot(x, &y);
assert_eq!(distance, 5.0);Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.