Skip to main content

Crate fixed_analytics

Crate fixed_analytics 

Source
Expand description

Fixed-point mathematical functions: accurate, deterministic, and guaranteed not to panic.

no_std compatible with no floating-point operations.

§Quick Start

use fixed::types::I16F16;
use fixed_analytics::{sin, cos, sqrt, ln};

let angle = I16F16::from_num(0.5);
let (s, c) = (sin(angle), cos(angle));

let root = sqrt(I16F16::from_num(2.0)).unwrap();
assert!((root.to_num::<f32>() - 1.414).abs() < 0.001);

let log = ln(I16F16::E).unwrap();
assert!((log.to_num::<f32>() - 1.0).abs() < 0.01);

§Available Functions

Total functions return T directly, saturating on overflow. Fallible functions return Result<T, Error> on domain violations.

CategoryTotalFallible
Trigonometricsin, cos, tan, sin_cos, atan, atan2asin, acos
Hyperbolicsinh, cosh, tanh, sinh_cosh, asinhacosh, atanh, acoth, coth
Exponentialexp, pow2ln, log2, log10
Algebraicsqrt

Functions use polynomial evaluation, CORDIC, and Newton-Raphson techniques. Complete absence of panic is verified at the linker level via the no-panic crate.

§Accuracy

TypeTypical Accuracy
I16F16~4 decimal digits
I32F32~8 decimal digits

All functions are benchmarked against MPFR reference implementations. Accuracy regressions are not permitted across releases.

§Features

  • std (default): Enables std::error::Error impl on Error

See the kernel module for algorithm details.

Re-exports§

pub use error::Error;
pub use error::Result;
pub use traits::CordicNumber;
pub use ops::algebraic::sqrt;
pub use ops::circular::acos;
pub use ops::circular::asin;
pub use ops::circular::atan;
pub use ops::circular::atan2;
pub use ops::circular::cos;
pub use ops::circular::sin;
pub use ops::circular::sin_cos;
pub use ops::circular::tan;
pub use ops::exponential::exp;
pub use ops::exponential::ln;
pub use ops::exponential::log2;
pub use ops::exponential::log10;
pub use ops::exponential::pow2;
pub use ops::hyperbolic::acosh;
pub use ops::hyperbolic::acoth;
pub use ops::hyperbolic::asinh;
pub use ops::hyperbolic::atanh;
pub use ops::hyperbolic::cosh;
pub use ops::hyperbolic::coth;
pub use ops::hyperbolic::sinh;
pub use ops::hyperbolic::sinh_cosh;
pub use ops::hyperbolic::tanh;
pub use fixed;

Modules§

bounded
Bounded value types that encode mathematical invariants at the type level.
error
Error types for CORDIC operations.
kernel
CORDIC (Coordinate Rotation Digital Computer) kernels.
ops
High-level mathematical operations built on CORDIC kernels.
tables
Precomputed lookup tables for CORDIC algorithms and polynomial evaluation.
traits
Trait definitions for types compatible with CORDIC algorithms.