1//! Embedded-friendly (i.e. `#![no_std]`) math library featuring fast, safe
2//! floating point approximations for common arithmetic operations, as well as
3//! 2D and 3D vector types, statistical analysis functions, and quaternions.
4//!
5//! ## Floating point approximations: `F32` and `F32Ext`
6//!
7//! `micromath` supports approximating many arithmetic operations on `f32`
8//! using bitwise operations, providing great performance and small code size
9//! at the cost of precision. For use cases like graphics and signal
10//! processing, these approximations are often sufficient and the performance
11//! gains worth the lost precision.
12//!
13//! These approximations are defined on the [`F32`] newtype wrapper.
14//!
15//! ### `F32Ext` extension trait
16//!
17//! Floating point approximations can used via the the [`F32Ext`] trait which
18//! is impl'd for `f32`, providing a drop-in `std`-compatible API.
19//!
20//! ```
21//! use micromath::F32Ext;
22//!
23//! let n = 2.0.sqrt();
24//! assert_eq!(n, 1.5); // close enough
25//! ```
26//!
27//! Since the `F32Ext` trait provides methods which are already defined in
28//! `std`, in cases where your crate links `std` the `F32Ext` versions of
29//! the same methods will not be used, in which case you will get an unused
30//! import warning for `F32Ext`.
31//!
32//! If you encounter this, add an `#[allow(unused_imports)]` above the import.
33//!
34//! ```
35//! #[allow(unused_imports)]
36//! use micromath::F32Ext;
37//! ```
38//!
39//! ## Vector types
40//!
41//! See the [`vector`] module for more information on vector types.
42//!
43//! The following vector types are available, all of which have `pub x` and
44//! `pub y` (and on 3D vectors, `pub z`) members:
45//!
46//! | Rust | 2D | 3D |
47//! |-------|---------|---------|
48//! | `i8` | `I8x2` | `I8x3` |
49//! | `i16` | `I16x2` | `I16x3` |
50//! | `i32` | `I32x2` | `I32x3` |
51//! | `u8` | `U8x2` | `U8x3` |
52//! | `u16` | `U16x2` | `U16x3` |
53//! | `u32` | `U32x2` | `U32x3` |
54//! | `f32` | `F32x2` | `F32x3` |
55//!
56//! ## Statistical analysis
57//!
58//! See the [`statistics`] module for more information on statistical analysis
59//! traits and functionality.
60//!
61//! The following traits are available and impl'd for slices and iterators of
62//! `f32` (and can be impl'd for other types):
63//!
64//! - [`Mean`][`statistics::Mean`] - compute arithmetic mean with the `mean()` method.
65//! - [`StdDev`][`statistics::StdDev`] - compute standard deviation with the `stddev()` method.
66//! - [`Trim`][`statistics::Trim`] - cull outliers from a sample slice with the `trim()` method.
67//! - [`Variance`][`statistics::Variance`] - compute variance with the `variance()` method.
68
69#![no_std]
70#![cfg_attr(docsrs, feature(doc_cfg))]
71#![doc(
72 html_logo_url = "https://raw.githubusercontent.com/tarcieri/micromath/main/img/micromath-sq.png",
73 html_root_url = "https://docs.rs/micromath/2.0.0"
74)]
75#![forbid(unsafe_code)]
76#![warn(
77 missing_docs,
78 rust_2018_idioms,
79 trivial_casts,
80 trivial_numeric_casts,
81 unused_qualifications
82)]
83
84#[cfg(feature = "statistics")]
85#[cfg_attr(docsrs, doc(cfg(feature = "statistics")))]
86pub mod statistics;
87
88#[cfg(feature = "vector")]
89#[cfg_attr(docsrs, doc(cfg(feature = "vector")))]
90pub mod vector;
91
92mod f32ext;
93mod float;
94#[cfg(feature = "quaternion")]
95mod quaternion;
96
97pub use crate::{f32ext::F32Ext, float::F32};
98
99#[cfg(feature = "quaternion")]
100pub use crate::quaternion::Quaternion;
101
102#[cfg(feature = "num-traits")]
103#[cfg_attr(docsrs, doc(cfg(feature = "num-traits")))]
104pub use num_traits;
105