Closed
Description
The documentation for the f32::hypot
/ f64::hypot
function reads
Calculates the length of the hypotenuse of a right-angle triangle given legs of length
x
andy
.
and gives this example (and the analogous example for f64
):
let x = 2.0f32;
let y = 3.0f32;
// sqrt(x^2 + y^2)
let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
assert!(abs_difference <= f32::EPSILON);
Since lengths are always positive, it's unclear what this function does for negative values. My expectation is that it gives the hypotenuse of the right triangle whose leg lengths are the absolute values of x
and y
, but I had to look up the relevant libc documentation to be sure, which reads
These functions return
sqrt (x*x + y*y)
. This is the length of the hypotenuse of a right triangle with sides of lengthx
andy
, or the distance of the point(x, y)
from the origin.