You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Declare "z" as const (renaming to "Z" to keep name idiomatic).
Move check for zero-value "x" earlier, to avoid calculating values that will be discarded.
Putting it together might look something like...
pub fn ang_round(x: f64) -> f64 {
// The makes the smallest gap in x = 1/16 - nextafter(1/16, 0) = 1/2^57
// for reals = 0.7 pm on the earth if x is an angle in degrees. (This
// is about 1000 times more resolution than we get with angles around 90
// degrees.) We use this to avoid having to deal with near singular
// cases when x is non-zero but tiny (e.g., 1.0e-200).
const Z: f64 = 1.0 / 16.0;
if x == 0.0 {
0.0
} else {
let mut y = x.abs();
// The compiler mustn't "simplify" z - (z - y) to y
if y < Z {
y = Z - (Z - y);
}
if x < 0.0 {
-y
} else {
y
}
}
}
The text was updated successfully, but these errors were encountered:
Declare "z" as const (renaming to "Z" to keep name idiomatic).
Move check for zero-value "x" earlier, to avoid calculating values that will be discarded.
Putting it together might look something like...
The text was updated successfully, but these errors were encountered: