Deterministic fixed-point mathematics for Rust based on configurable continued fraction evaluation.
fixed-math is a numerical computation library for Rust that provides configurable fixed-point arithmetic together with a reusable continued fraction evaluation framework.
Unlike many numerical libraries that rely on floating-point polynomial approximations, fixed-math evaluates elementary functions using configurable continued fraction algorithms, making it suitable for deterministic numerical computation, embedded environments, and systems where floating-point arithmetic is undesirable.
- Configurable binary Q formats
- Signed fixed-point numbers
- Integer encoding and decoding
- Fixed-point rescaling
- Checked multiplication and division
- Multiple rounding strategies
- Generic continued fraction abstraction
- Backward recurrence evaluator
- Modified Lentz evaluator
- Configurable evaluation depth
- Runtime-selectable evaluation algorithm
Currently implemented:
| Function | Method |
|---|---|
| exp(x) | Lambert continued fraction |
| ln(x) | Atanh transformation |
Planned:
- atan
- tanh
- sqrt
- pow
- sin
- cos
- asin
- acos
- gamma
- erf
Most fixed-point numerical libraries implement transcendental functions using polynomial approximations.
This library instead builds around continued fractions, which generally provide:
- improved numerical stability
- better convergence over wide input ranges
- reusable evaluation infrastructure
- configurable evaluation algorithms
- deterministic fixed-point execution
Instead of embedding approximation coefficients directly into each function, fixed-math separates:
- coefficient generation
- evaluation algorithm
- fixed-point arithmetic
This allows the same evaluation engine to be reused across many mathematical functions.
Clone the repository:
git clone https://github.com/Vane-studio/fixed-math.git
cd fixed-mathRun the examples:
cargo run --example basic
cargo run --example configurationRun all tests:
cargo testRun Clippy:
cargo clippy --all-targets --all-features -- -D warningsThe project provides runnable examples demonstrating the public API.
| Example | Description |
|---|---|
| examples/basic.rs | Basic fixed-point function evaluation |
| examples/configuration.rs | Configuring evaluation algorithms |
The examples are intended to demonstrate the recommended usage of the library and are kept synchronized with the public API.
Mathematical Functions
│
▼
EvaluationConfig
│
┌───────────────┴───────────────┐
▼ ▼
Backward Evaluation Modified Lentz
│ │
└───────────────┬───────────────┘
▼
Continued Fraction Engine
│
▼
Fixed-point Arithmetic
The implementation is intentionally layered.
src/
├── number/
│ Fixed-point numbers
│ Formats
│ Rounding
│
├── cf/
│ Continued fractions
│ Coefficients
│ Evaluators
│
├── function/
│ Mathematical functions
│
├── traits/
│ Public traits
│
└── error/
Error types
Evaluation behavior is configured through EvaluationConfig.
It controls:
- binary format
- continued fraction depth
- rounding strategy
- evaluation algorithm
Supported algorithms:
- Backward recurrence
- Modified Lentz
Future algorithms can be added without changing the public function interfaces.
Additional documentation is available in the docs/ directory.
| Document | Description |
|---|---|
| unit1.md | Unit 1 implementation summary |
| design.md | Architecture overview |
| math.md | Mathematical background |
| api.md | Public API reference |
| roadmap.md | Development roadmap |
Project policies:
- CONTRIBUTING.md
- CHANGELOG.md
- SECURITY.md
Current implementation:
- Fixed-point arithmetic
- Continued fraction framework
- Lambert continued fractions
- Atanh continued fractions
- Exponential function
- Natural logarithm
Quality status:
- cargo fmt
- cargo test
- cargo clippy
All existing tests pass.
Unit 2
- atan
- tanh
- sqrt
- pow
Unit 3
- sin
- cos
- asin
- acos
Future work
- special functions
- benchmark suite
- docs.rs documentation
- crates.io release
- no_std support
Contributions are welcome.
Before submitting changes, please ensure:
cargo fmt
cargo test
cargo clippy --all-targets --all-features -- -D warningsSee CONTRIBUTING.md for details.
Licensed under the MIT License.
See LICENSE.