Skip to main content

wrap_angle

Function wrap_angle 

Source
pub fn wrap_angle(angle: f32) -> f32
Expand description

Wraps an angle in radians to [-π, π); non-finite input gives NaN.

Float rounding can return exactly +π for inputs just below an odd multiple of π, so treat the range as closed, [-π, π], when that matters.

§Examples

use core::f32::consts::{FRAC_PI_2, PI};
use stable_flight::wrap_angle;

assert!((wrap_angle(3.0 * FRAC_PI_2) + FRAC_PI_2).abs() < 1e-6); // 270° → -90°
assert_eq!(wrap_angle(PI), -PI);
assert!(wrap_angle(f32::NAN).is_nan());