Function normalize_angle

Source
pub const fn normalize_angle(radians: f32) -> f32
Expand description

Normalizes an angle in radians to the range [-π, π].

§Examples

// Note: 450° causes a rounding error, but 540° does not, so there is no problem using `assert`.
use core::f32::consts::{TAU, PI};
const _: () = assert!(TAU == 2.0 * PI);

const RAD_OF_540DEG: f32 = TAU + PI;
assert!(rad_to_deg(RAD_OF_540DEG) == 540.0);
assert!(normalize_angle(RAD_OF_540DEG) == -PI);