Skip to main content

embedded_maths/
lib.rs

1//! Hardware-friendly `f32` mathematics for Rust `no_std` environments.
2//!
3//! `embedded-maths` exposes scalar functions, vectors, matrices, quaternions,
4//! statistics, and compile-time metadata without requiring `micromath`.
5//! Implementations are delegated to focused crates when that provides better
6//! accuracy, compatibility, or maintenance boundaries.
7//!
8//! # Quick example
9//!
10//! ```rust
11//! use embedded_maths::{asin, cos, hypot, sin, sqrt};
12//!
13//! let angle = 0.5_f32;
14//! assert!((sin(angle) - 0.479_425_55).abs() < 1e-6);
15//! assert!((cos(angle) - 0.877_582_6).abs() < 1e-6);
16//! assert!((asin(0.5) - core::f32::consts::FRAC_PI_6).abs() < 1e-6);
17//! assert_eq!(hypot(3.0, 4.0), 5.0);
18//! assert_eq!(sqrt(9.0).unwrap(), 3.0);
19//! ```
20//!
21//! # API groups
22//!
23//! - [`sin()`], [`cos()`], [`tan()`], [`sin_cos()`]
24//! - [`asin()`], [`acos()`], [`atan()`], [`atan2()`]
25//! - [`sqrt()`], [`invsqrt()`], [`hypot()`]
26//! - [`exp()`], [`ln()`], [`log()`], [`log2()`], [`log10()`]
27//! - [`powf()`], [`powi()`], [`inv()`], [`recip()`]
28//! - [`ceil()`], [`floor()`], [`round()`], [`trunc()`], [`fract()`]
29//! - [`abs()`], [`signum()`], [`copysign()`]
30//! - [`mean`], [`variance`], [`std_dev`], [`StreamingStats`]
31//! - [`Vec2`], [`Vec3`], [`Vec4`], [`Quaternion`]
32//! - [`Matrix2x2`], [`Matrix3x3`]
33//!
34//! # Error behavior
35//!
36//! Invalid-domain functions generally preserve the behavior documented in
37//! their implementation crate: `sqrt` and `invsqrt` return `Result`; inverse
38//! trigonometric functions return `NaN` outside their domain; infinities and
39//! `NaN` values are handled explicitly where relevant.
40//!
41//! # License
42//!
43//! Licensed under `GPL-2.0-or-later`.
44
45#![cfg_attr(not(test), no_std)]
46
47#[path = "embedded-maths-functions/abs.rs"]
48pub mod abs;
49
50#[path = "embedded-maths-functions/acos.rs"]
51pub mod acos;
52
53#[path = "embedded-maths-functions/asin.rs"]
54pub mod asin;
55
56#[path = "embedded-maths-functions/sqrt.rs"]
57pub mod sqrt;
58
59#[path = "embedded-maths-functions/atan.rs"]
60pub mod atan;
61#[path = "embedded-maths-functions/atan2.rs"]
62pub mod atan2;
63#[path = "embedded-maths-functions/ceil.rs"]
64pub mod ceil;
65#[path = "embedded-maths-functions/copysign.rs"]
66pub mod copysign;
67#[path = "embedded-maths-functions/cos.rs"]
68pub mod cos;
69#[path = "embedded-maths-functions/cosh.rs"]
70pub mod cosh;
71#[path = "embedded-maths-functions/diveuclid.rs"]
72pub mod div_euclid;
73#[path = "embedded-maths-functions/diveuclidean.rs"]
74pub mod div_euclidean;
75#[path = "embedded-maths-functions/exp.rs"]
76pub mod exp;
77#[path = "embedded-maths-functions/floor.rs"]
78pub mod floor;
79#[path = "embedded-maths-functions/fract.rs"]
80pub mod fract;
81#[path = "embedded-maths-functions/hypot.rs"]
82pub mod hypot;
83#[path = "embedded-maths-functions/inv.rs"]
84pub mod inv;
85#[path = "embedded-maths-functions/invsqrt.rs"]
86pub mod invsqrt;
87#[path = "embedded-maths-functions/ln.rs"]
88pub mod ln;
89#[path = "embedded-maths-functions/log.rs"]
90pub mod log;
91#[path = "embedded-maths-functions/log10.rs"]
92pub mod log10;
93#[path = "embedded-maths-functions/log2.rs"]
94pub mod log2;
95#[path = "embedded-maths-functions/mul_add.rs"]
96pub mod mul_add;
97#[path = "embedded-maths-functions/powf.rs"]
98pub mod powf;
99#[path = "embedded-maths-functions/powi.rs"]
100pub mod powi;
101#[path = "embedded-maths-functions/recip.rs"]
102pub mod recip;
103#[path = "embedded-maths-functions/rem_euclid.rs"]
104pub mod rem_euclid;
105#[path = "embedded-maths-functions/round.rs"]
106pub mod round;
107#[path = "embedded-maths-functions/signum.rs"]
108pub mod signum;
109#[path = "embedded-maths-functions/sin.rs"]
110pub mod sin;
111#[path = "embedded-maths-functions/sin_cos.rs"]
112pub mod sin_cos;
113#[path = "embedded-maths-functions/tan.rs"]
114pub mod tan;
115#[path = "embedded-maths-functions/trunc.rs"]
116pub mod trunc;
117
118#[path = "matrix.rs"]
119pub mod matrix;
120#[path = "quaternion.rs"]
121pub mod quaternion;
122#[path = "statistics.rs"]
123pub mod statistics;
124#[path = "vector.rs"]
125pub mod vector;
126
127pub use embedded_stats_f32::{
128    StatsError, StreamingStats, mean as kahan_mean, std_dev as kahan_std_dev,
129    variance as kahan_variance,
130};
131
132pub use abs::abs;
133pub use acos::acos;
134pub use asin::asin;
135pub use atan::atan;
136pub use atan2::atan2;
137pub use ceil::ceil;
138pub use copysign::copysign;
139pub use cos::cos;
140pub use cosh::cosh;
141pub use div_euclid::div_euclid;
142pub use div_euclidean::div_euclid as div_euclidean;
143pub use exp::exp;
144pub use floor::floor;
145pub use fract::fract;
146pub use hypot::hypot;
147pub use inv::inv;
148pub use invsqrt::inv_sqrt as invsqrt;
149pub use ln::ln;
150pub use log::log;
151pub use log2::log2;
152pub use log10::log10;
153pub use matrix::{Matrix2x2, Matrix3x3, MatrixError};
154pub use mul_add::mul_add;
155pub use powf::powf;
156pub use powi::powi;
157pub use quaternion::Quaternion;
158pub use recip::recip;
159pub use rem_euclid::rem_euclid;
160pub use round::round;
161pub use signum::signum;
162pub use sin::sin;
163pub use sin_cos::sin_cos;
164pub use sqrt::sqrt;
165pub use statistics::{mean, std_dev, variance};
166pub use tan::tan;
167pub use trunc::trunc;
168pub use vector::{Vec2, Vec3, Vec4, VecError};