std-method
Floating-point hypot
Compute the length of a two-dimensional vector using a dedicated method rather than explicitly squaring potentially huge components. Allow for implementation-dependent precision. Expected stdout (not executed): true Common mistake: Intermediate squares can overflow even when the final length is representable.
Formal Syntax & Structure
rust syntaxrust
x.hypot(y) -> f64Working Example
Example Snippetrust
fn main() { let d = 3.0_f64.hypot(4.0); println!("{}", (d - 5.0).abs() < 1e-10);}