| Crates.io | flexfloat |
| lib.rs | flexfloat |
| version | 0.1.1 |
| created_at | 2025-09-14 16:04:46.814469+00 |
| updated_at | 2025-12-27 19:48:31.506294+00 |
| description | A Rust library for arbitrary floating-point types with infinite exponent. |
| homepage | https://github.com/ferranSanchezLlado/flexfloat-rs |
| repository | https://github.com/ferranSanchezLlado/flexfloat-rs |
| max_upload_size | |
| id | 1838937 |
| size | 115,844 |
A high-precision Rust library for arbitrary precision floating-point arithmetic with growable exponents and fixed-size fractions. FlexFloat extends IEEE 754 double-precision format to handle numbers beyond the standard range while maintaining computational efficiency and precision consistency.
FlexFloat provides a flexible floating-point arithmetic system that automatically adapts to the scale of your computations:
Add FlexFloat to your Cargo.toml:
[dependencies]
flexfloat = "0.1.0"
use flexfloat::FlexFloat;
// Create FlexFloat from standard types
let x = FlexFloat::from(3.14159);
let y = FlexFloat::from(2.71828);
// Perform arithmetic operations
let sum = x + y; // Planned
let neg_x = -x;
let abs_y = y.abs();
// Work with special values
let zero = FlexFloat::zero();
let infinity = FlexFloat::pos_infinity();
let nan = FlexFloat::nan();
// Convert back to f64 when in range
let result: f64 = sum.into();
use flexfloat::{FlexFloat, bitarray::{BitArray, BoolBitArray}};
// Inspect internal representation
let num = FlexFloat::from(123.456);
println!("Sign: {}", num.sign());
println!("Exponent bits: {}", num.exponent().len());
println!("Fraction bits: {}", num.fraction().len());
// Work with bit arrays directly
let custom_bits = BoolBitArray::from_bits(&[true, false, true]);
let from_bytes = BoolBitArray::from_bytes(&[0xFF, 0x00], 16);
// Handle special cases
if num.is_nan() {
println!("Not a number");
} else if num.is_infinity() {
println!("Infinite value");
} else if num.is_zero() {
println!("Zero value");
}
FlexFloat is built around two main components:
Provides flexible bit manipulation with multiple implementations:
Core floating-point implementation featuring:
| Feature | f64 | BigDecimal | FlexFloat |
|---|---|---|---|
| Range | Limited | Unlimited | Unlimited |
| Precision | 52 bits | Arbitrary | 52 bits (fixed) |
| Performance | Fastest | Slower | Balanced |
| Memory | 8 bytes | Variable | Variable |
| IEEE 754 | Full | Partial | Full |
use flexfloat::FlexFloat;
use flexfloat::bitarray::BoolBitArray;
// Use specific bit array implementation
type CustomFloat = FlexFloat<BoolBitArray>;
let num = CustomFloat::from(42.0);
FlexFloat uses an adaptive exponent sizing algorithm:
FlexFloat<B> {
sign: bool // 1 bit
exponent: B // Variable width (≥11 bits)
fraction: B // Fixed 52 bits
}
This library is currently in development. Implemented features:
Contributions are welcome! Areas where help is needed:
This project is licensed under the MIT License - see the LICENSE file for details.
num-bigint crate for arbitrary precision integer supportNote: FlexFloat is designed for applications requiring extended range floating-point arithmetic while maintaining precision consistency. For applications needing arbitrary precision (variable mantissa), consider BigDecimal or similar libraries.
This repository includes a local Git hook that runs the same checks as the project's CI workflow (format check, clippy, tests, builds, and docs). The hook lives in .githooks/pre-commit and is not enabled by default.
To enable the hook locally run:
bash scripts/install-hooks.sh
Note: these checks may be slow (they run the full test/build matrix) — you can skip the hook temporarily with git commit --no-verify when necessary.