Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

fixed

Fixed-Point Type for f128

This module provides the core Fixed type for 64.64 fixed-point arithmetic.

Representation

Values are stored as a magnitude and sign:

  • mag: Absolute value scaled by 2^64 (ONE)
  • sign: true for negative, false for positive

Creating Fixed Values

use cairo_fp::f128::types::fixed::FixedTrait;

// From unscaled integer
let a = FixedTrait::new_unscaled(10, false);  // 10.0

// From raw magnitude (already scaled)
let b = FixedTrait::new(18446744073709551616, false);  // 1.0

// From felt252
let c = FixedTrait::from_unscaled_felt(5);  // 5.0

// Constants
let zero = FixedTrait::ZERO();
let one = FixedTrait::ONE();

Fully qualified path: cairo_fp::f128::types::fixed

Constants

PRIMEThe Starknet field prime.
ONEOne (1.0) as a felt252, equal to 2^64.
ONE_u128One (1.0) as a u128, equal to 2^64.
HALFHalf (0.5) as a felt252, equal to 2^63.
HALF_u128Half (0.5) as a u128, equal to 2^63.
MAX_u128Maximum u128 value (2^128 - 1).

Structs

FixedA signed 64.64 fixed-point number. Uses 64 bits for the integer part and 64 bits for the fractional part, providing approximately 19 decimal digits of precision….

Traits

FixedTraitTrait defining operations for fixed-point numbers. Provides constructors, mathematical operations, trigonometric functions, and hyperbolic functions for the…

Impls