#fixed-point #angle #trigonometry #geometry

no-std turns

Fixed-point angles modulo 2π backed by unsigned integers

2 releases

Uses new Rust 2024

0.1.1 Apr 19, 2026
0.1.0 Apr 19, 2026

#799 in Math

MIT license

25KB
532 lines

turns

CI crates.io docs.rs

Fixed-point angles modulo 2π, backed by unsigned integers.

Angle<T> represents an angle as an unsigned integer where the full range of T maps onto one full turn (2π radians / 360 degrees). Natural integer overflow provides wraparound at 2π, so modular arithmetic is free.

Type aliases Angle8, Angle16, Angle32, Angle64, and Angle128 cover the standard widths.

Usage

[dependencies]
turns = "0.1"
use turns::Angle8;
use core::f64::consts::PI;

let pi = Angle8::from_radians(PI);
assert_eq!(pi + pi, Angle8::from_radians(0.0_f64));

Features

  • std (default) — enables num-traits/std.
  • libm — enables num-traits/libm for transcendentals in no_std builds.

For no_std:

[dependencies]
turns = { version = "0.1", default-features = false, features = ["libm"] }

Precision

Float conversions are generic over any F: Float. Expect precision loss when the integer width exceeds the float mantissa (e.g. Angle128 with f64 keeps ~53 of 128 bits). Non-finite inputs (NaN, infinities) are coerced to zero rather than panicking.

License

MIT

Dependencies

~220KB