Skip to main content

Crate embedded_maths

Crate embedded_maths 

Source
Expand description

Hardware-friendly f32 mathematics for Rust no_std environments.

embedded-maths exposes scalar functions, vectors, matrices, quaternions, statistics, and compile-time metadata without requiring micromath. Implementations are delegated to focused crates when that provides better accuracy, compatibility, or maintenance boundaries.

§Quick example

use embedded_maths::{asin, cos, hypot, sin, sqrt};

let angle = 0.5_f32;
assert!((sin(angle) - 0.479_425_55).abs() < 1e-6);
assert!((cos(angle) - 0.877_582_6).abs() < 1e-6);
assert!((asin(0.5) - core::f32::consts::FRAC_PI_6).abs() < 1e-6);
assert_eq!(hypot(3.0, 4.0), 5.0);
assert_eq!(sqrt(9.0).unwrap(), 3.0);

§API groups

§Error behavior

Invalid-domain functions generally preserve the behavior documented in their implementation crate: sqrt and invsqrt return Result; inverse trigonometric functions return NaN outside their domain; infinities and NaN values are handled explicitly where relevant.

§License

Licensed under GPL-2.0-or-later.

Re-exports§

pub use abs::abs;
pub use acos::acos;
pub use asin::asin;
pub use atan::atan;
pub use atan2::atan2;
pub use ceil::ceil;
pub use copysign::copysign;
pub use cos::cos;
pub use cosh::cosh;
pub use div_euclid::div_euclid;
pub use div_euclidean::div_euclid as div_euclidean;
pub use exp::exp;
pub use floor::floor;
pub use fract::fract;
pub use hypot::hypot;
pub use inv::inv;
pub use invsqrt::inv_sqrt as invsqrt;
pub use ln::ln;
pub use log::log;
pub use log10::log10;
pub use log2::log2;
pub use mul_add::mul_add;
pub use powf::powf;
pub use powi::powi;
pub use recip::recip;
pub use rem_euclid::rem_euclid;
pub use round::round;
pub use signum::signum;
pub use sin::sin;
pub use sin_cos::sin_cos;
pub use sqrt::sqrt;
pub use tan::tan;
pub use trunc::trunc;
pub use statistics::mean;
pub use statistics::variance;
pub use statistics::std_dev;

Modules§

abs
Absolute value of f32 for no_std, without libm.
acos
Arc cosine of f32 for no_std, without libm.
asin
Arc sine of f32 for no_std, without libm.
atan
Arc tangent of f32 for no_std, without libm.
atan2
Four-quadrant arc tangent of f32 for no_std, without libm.
ceil
f32 ceiling operations.
copysign
f32 sign-copy operations.
cos
Cosinus pour f32, sans dépendance externe.
cosh
exp et cosh pour f32, sans dépendance externe.
div_euclid
Euclidean division for f32.
div_euclidean
Euclidean division alias.
exp
Exponential function e^x for f32 on no_std embedded targets, powered by embedded-exp-f32.
floor
f32 floor operations.
fract
f32 fractional-part operations.
hypot
Overflow-safe Euclidean norm for two f32 values.
inv
Reciprocal operations for f32.
invsqrt
Fast inverse square root 1 / sqrt(x) for f32 on no_std embedded systems, powered by embedded-invsqrt-f32.
ln
Logarithme népérien approché pour f32, sans dépendance externe.
log
log_b(x) approché pour f32, sans dépendance externe.
log2
log base 2 approché pour f32, sans dépendance externe.
log10
log base 10 approché pour f32, sans dépendance externe.
matrix
2x2 and 3x3 f32 matrices for no_std embedded systems, powered by embedded-matrix.
mul_add
Fused multiply-add operations for f32.
powf
Floating-point power for f32.
powi
x^n pour n entier (powi), sans dépendance externe.
quaternion
4D quaternions and perspective projection (f32, no_std), powered by embedded-quaternion-f32.
recip
Reciprocal alias.
rem_euclid
Euclidean remainder for f32.
round
f32 rounding operations.
signum
Signe d’un f32, sans dépendance externe.
sin
Sinus pour f32, sans dépendance externe.
sin_cos
sin, cos et sin_cos pour f32, sans dépendance externe.
sqrt
Square root of f32 for no_std, powered by embedded-f32-sqrt.
statistics
Statistical analysis support for f32 on no_std, powered by embedded-stats-f32.
tan
Tangente pour f32, sans dépendance externe.
trunc
Partie entière (troncature vers zéro) pour f32, sans dépendance externe.
vector
2D, 3D, and 4D f32 vectors for no_std embedded systems, powered by embedded-vector.

Structs§

Matrix2x2
A 2×2 f32 matrix stored in row-major order.
Matrix3x3
A 3×3 f32 matrix stored in row-major order.
Quaternion
Représente un quaternion q = w + xi + yj + z*k ou un point/vecteur dans l’espace 4D.
StreamingStats
Accumulateur de moyenne en ligne, O(1) mémoire.
Vec2
A 2D vector of f32 components.
Vec3
A 3D vector of f32 components.
Vec4
A 4D vector of f32 components.

Enums§

MatrixError
Error returned when a matrix operation is invalid.
StatsError
Erreurs EmptySlice et NonFiniteValue pour la roboustesse du systeme
VecError
Errors returned by vector operations.

Functions§

kahan_mean
Calcule la moyenne arithmétique d’une tranche f32.
kahan_std_dev
Calcule l’écart type de population (= √variance) d’une tranche f32.
kahan_variance
Calcule la variance de population (non corrigée, diviseur N) d’une tranche f32.