|
1 | | -//! Fixed-point math via CORDIC. No floating-point ops, `no_std` compatible. |
| 1 | +//! Fixed-point mathematical functions: accurate, deterministic, and guaranteed not to panic. |
| 2 | +//! |
| 3 | +//! `no_std` compatible with no floating-point operations. |
2 | 4 | //! |
3 | 5 | //! # Quick Start |
4 | 6 | //! |
|
8 | 10 | //! |
9 | 11 | //! let angle = I16F16::from_num(0.5); |
10 | 12 | //! let (s, c) = (sin(angle), cos(angle)); |
| 13 | +//! |
11 | 14 | //! let root = sqrt(I16F16::from_num(2.0)).unwrap(); |
| 15 | +//! assert!((root.to_num::<f32>() - 1.414).abs() < 0.001); |
| 16 | +//! |
12 | 17 | //! let log = ln(I16F16::E).unwrap(); |
| 18 | +//! assert!((log.to_num::<f32>() - 1.0).abs() < 0.01); |
13 | 19 | //! ``` |
14 | 20 | //! |
15 | | -//! # Precision |
| 21 | +//! # Available Functions |
| 22 | +//! |
| 23 | +//! **Total functions** return `T` directly, saturating on overflow. |
| 24 | +//! **Fallible functions** return [`Result<T, Error>`] on domain violations. |
16 | 25 | //! |
17 | | -//! | Type | Accuracy | |
18 | | -//! |------|----------| |
| 26 | +//! | Category | Total | Fallible | |
| 27 | +//! |--------------|-------|----------| |
| 28 | +//! | Trigonometric | [`sin`], [`cos`], [`tan`], [`sin_cos`], [`atan`], [`atan2`] | [`asin`], [`acos`] | |
| 29 | +//! | Hyperbolic | [`sinh`], [`cosh`], [`tanh`], [`sinh_cosh`], [`asinh`] | [`acosh`], [`atanh`], [`acoth`], [`coth`] | |
| 30 | +//! | Exponential | [`exp`], [`pow2`] | [`ln`], [`log2`], [`log10`] | |
| 31 | +//! | Algebraic | — | [`sqrt`] | |
| 32 | +//! |
| 33 | +//! Functions use polynomial evaluation, CORDIC, and Newton-Raphson techniques. |
| 34 | +//! Complete absence of panic is verified at the linker level via the |
| 35 | +//! [`no-panic`](https://github.com/dtolnay/no-panic) crate. |
| 36 | +//! |
| 37 | +//! # Accuracy |
| 38 | +//! |
| 39 | +//! | Type | Typical Accuracy | |
| 40 | +//! |------|------------------| |
19 | 41 | //! | `I16F16` | ~4 decimal digits | |
20 | 42 | //! | `I32F32` | ~8 decimal digits | |
21 | 43 | //! |
| 44 | +//! All functions are benchmarked against MPFR reference implementations. |
| 45 | +//! Accuracy regressions are not permitted across releases. |
| 46 | +//! |
22 | 47 | //! # Features |
23 | 48 | //! |
24 | | -//! - `std` (default): Enables `std::error::Error` impl |
| 49 | +//! - **`std`** (default): Enables `std::error::Error` impl on [`Error`] |
25 | 50 | //! |
26 | | -//! See [`kernel`] module for algorithm details. |
| 51 | +//! See the [`kernel`] module for algorithm details. |
27 | 52 |
|
28 | 53 | #![no_std] |
29 | 54 | #![cfg_attr(docsrs, feature(doc_cfg))] |
|
0 commit comments