I'm reading the Rust tutorial on rust-lang.org, and I came across the following code:
use std::f64;
fn angle(vector: (f64, f64)) -> f64 {
let pi = f64::consts::PI;
match vector {
(0.0, y) if y < 0.0 => 1.5 * pi,
(0.0, _) => 0.5 * pi,
(x, y) => (y / x).atan()
}
}
Normally for atan2 I would expect to see special cases for -0 and 0, for example to implement cases like these:
atan2(+0, +0) = +0
atan2(+0, −0) = +π
atan2(−0, +0) = −0
atan2(−0, −0) = −π
I'm not saying the tutorial should include those examples. After all it's just a demonstration of the match structure.
I'm just wondering if 0.0 would match -0.0 as well? Or if the two would be recognized as disjoint values?