f64
f64 - 32.32 Fixed-Point Arithmetic
Gas-efficient fixed-point numbers using 64-bit representation.
Format
The f64 format uses 32 bits for the integer part and 32 bits for the fractional part, providing: - Range: approximately ±2.1 × 10⁹ - Precision: approximately 2 × 10⁻¹⁰
When to Use f64
Choose f64 over f128 when:
- Gas optimization is critical
- Values stay within ±2 billion
- Precision of ~10 decimal places is sufficient
f64 operations are typically 40-60% cheaper than f128 equivalents.
Core Type
The Fixed struct represents a signed fixed-point number:
mag: The absolute magnitude scaled by 2³²sign:truefor negative,falsefor positive
Example
use cairo_fp::f64::types::fixed::FixedTrait;
use cairo_fp::f64::math::ops;
let x = FixedTrait::new_unscaled(2, false); // 2.0
let result = ops::exp(x); // e² ≈ 7.389
Fully qualified path: cairo_fp::f64