expression

Avoid intermediate overflow in a vector norm

Computing sqrt(x*x+y*y) can overflow even when the norm is representable. The hypot method computes the Euclidean length without unnecessary intermediate overflow for the shown inputs. Exact floating-point accuracy is platform dependent, so check only the finiteness of this example. Expected result (NOT RUN): naive finite: false, hypot finite: true Common mistake: Squaring extreme finite inputs without considering intermediate overflow. Static Rust example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
x.hypot(y)

Working Example

Example Snippetrust
fn main() {    let (x,y) = (1e200_f64, 1e200_f64);    let naive = (x*x+y*y).sqrt();    println!("naive finite: {}, hypot finite: {}", naive.is_finite(), x.hypot(y).is_finite());}
Rust Reference