cairo_fp
A comprehensive fixed-point math library for Cairo and Starknet.
This library provides two precision levels:
f128- 64.64 fixed-point format (128-bit, high precision)f64- 32.32 fixed-point format (64-bit, lower gas costs)
Features
- Basic Arithmetic: add, sub, mul, div, neg, abs - Power & Exponential: exp, exp2, pow, sqrt, cbrt - Logarithms: ln, log2, log10 - Trigonometry: sin, cos, tan, asin, acos, atan (with fast variants) - Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh - DeFi Primitives: compound interest, AMM pool math, ratio utilities - Procedural Generation: Simplex noise, random number generation - Vector Types: Vec2, Vec3, Vec4 for graphics/games
Quick Start
use cairo_fp::f128::types::fixed::FixedTrait;
use cairo_fp::f128::math::ops;
// Create fixed-point numbers
let a = FixedTrait::new_unscaled(10, false); // 10.0
let b = FixedTrait::new_unscaled(3, false); // 3.0
// Basic arithmetic
let sum = a + b; // 13.0
let product = a * b; // 30.0
let quotient = a / b; // 3.333...
// Advanced math
let sqrt_a = ops::sqrt(a); // ~3.162
let exp_b = ops::exp(b); // ~20.086
Choosing Between f128 and f64
| Aspect | f128 | f64 |
|---|---|---|
| Precision | ~5×10⁻²⁰ | ~2×10⁻¹⁰ |
| Range | ±2⁶³ | ±2³¹ |
| Gas Cost | Higher | 40-60% lower |
Use f64 when gas optimization is critical and precision requirements allow.
Fully qualified path: cairo_fp
Modules
Modules
Modules
f128
f128 - 64.64 Fixed-Point Arithmetic
High-precision fixed-point numbers using 128-bit representation.
Format
The f128 format uses 64 bits for the integer part and 64 bits for the fractional part, providing: - Range: approximately ±9.2 × 10¹⁸ - Precision: approximately 5 × 10⁻²⁰
Core Type
The Fixed struct represents a signed fixed-point number:
mag: The absolute magnitude scaled by 2⁶⁴sign:truefor negative,falsefor positive
Modules
types- Core types (Fixed, Vec2, Vec3, Vec4)math- Mathematical operationsops- Basic arithmetic, power, exponential, logarithmstrig- Trigonometric functionshyp- Hyperbolic functionscomp- Comparison utilities
procgen- Procedural generation (noise, random)
Example
use cairo_fp::f128::types::fixed::FixedTrait;
use cairo_fp::f128::math::ops;
let x = FixedTrait::new_unscaled(2, false); // 2.0
let result = ops::exp(x); // e² ≈ 7.389
Fully qualified path: cairo_fp::f128
Modules
Modules
Modules
math
Fully qualified path: cairo_fp::f128::math
Modules
Modules
Modules
comp
Comparison Functions
Basic comparison utilities for fixed-point numbers.
Functions
max- Returns the larger of two valuesmin- Returns the smaller of two values
Fully qualified path: cairo_fp::f128::math::comp
Free functions
| max | Returns the maximum of two fixed-point values…. |
| min | Returns the minimum of two fixed-point values…. |
Free functions
Free functions
| max | Returns the maximum of two fixed-point values…. |
| min | Returns the minimum of two fixed-point values…. |
max
Returns the maximum of two fixed-point values.
Arguments
a- First value to compareb- Second value to compare
Returns
The larger of the two values
Fully qualified path: cairo_fp::f128::math::comp::max
fn max(a: Fixed, b: Fixed) -> Fixed
min
Returns the minimum of two fixed-point values.
Arguments
a- First value to compareb- Second value to compare
Returns
The smaller of the two values
Fully qualified path: cairo_fp::f128::math::comp::min
fn min(a: Fixed, b: Fixed) -> Fixed
defi_precision
DeFi Precision Tests
Precision validation tests for power and exponential functions across DeFi-typical value ranges.
Test Coverage
- Rates: 0.01% to 500% (0.0001 to 5.0) - Values: Small (1e-8) to Large (1e8)
Gas Benchmarks
Approximate L2 gas costs for f128 (64.64 fixed-point):
| Function | Typical Gas | Notes |
|---|---|---|
| exp() | ~176,000 | General exponential |
| exp2() | ~17,500 | Fast for integer exponents |
| ln() | ~40,000 | Natural logarithm |
| log2() | ~190,000 | Base-2 logarithm |
| log10() | ~201,000 | Base-10 logarithm |
| pow() | ~75,000 | Integer exponent |
| pow() | ~362,000 | Fractional exponent |
| sqrt() | ~33,000 | Square root |
| cbrt() | ~217,000 | Cube root (1.0 input) |
| cbrt() | ~363,000 | Cube root (general case) |
This module contains tests only - no runtime functions are exported.
Fully qualified path: cairo_fp::f128::math::defi_precision
hyp
Hyperbolic Functions
Hyperbolic trigonometric functions and their inverses.
Functions
sinh,cosh,tanh- Hyperbolic sine, cosine, tangentasinh,acosh,atanh- Inverse hyperbolic functions
Gas Costs (f128)
| Function | Gas |
|---|---|
| sinh | ~225,000 |
| cosh | ~225,000 |
| tanh | ~227,000 |
| asinh | ~260,000 |
| acosh | ~455,000 |
| atanh | ~280,000 |
Use Cases
- Physics simulations (catenary curves, special relativity)
- Machine learning (activation functions)
- Signal processing
Fully qualified path: cairo_fp::f128::math::hyp
Free functions
| cosh | Calculates the hyperbolic cosine: (e^x + e^-x) / 2… |
| sinh | Calculates the hyperbolic sine: (e^x - e^-x) / 2… |
| tanh | Calculates the hyperbolic tangent: sinh(x) / cosh(x)… |
| acosh | Calculates the inverse hyperbolic cosine: ln(x + sqrt(x² - 1))… |
| asinh | Calculates the inverse hyperbolic sine: ln(x + sqrt(x² + 1))… |
| atanh | Calculates the inverse hyperbolic tangent: ln((1 + x) / (1 - x)) / 2… |
Free functions
Free functions
| cosh | Calculates the hyperbolic cosine: (e^x + e^-x) / 2… |
| sinh | Calculates the hyperbolic sine: (e^x - e^-x) / 2… |
| tanh | Calculates the hyperbolic tangent: sinh(x) / cosh(x)… |
| acosh | Calculates the inverse hyperbolic cosine: ln(x + sqrt(x² - 1))… |
| asinh | Calculates the inverse hyperbolic sine: ln(x + sqrt(x² + 1))… |
| atanh | Calculates the inverse hyperbolic tangent: ln((1 + x) / (1 - x)) / 2… |
cosh
Calculates the hyperbolic cosine: (e^x + e^-x) / 2
Properties
- cosh(0) = 1
- cosh(-x) = cosh(x) (even function)
- Always >= 1
Fully qualified path: cairo_fp::f128::math::hyp::cosh
fn cosh(a: Fixed) -> Fixed
sinh
Calculates the hyperbolic sine: (e^x - e^-x) / 2
Properties
- sinh(0) = 0
- sinh(-x) = -sinh(x) (odd function)
Fully qualified path: cairo_fp::f128::math::hyp::sinh
fn sinh(a: Fixed) -> Fixed
tanh
Calculates the hyperbolic tangent: sinh(x) / cosh(x)
Properties
- tanh(0) = 0
- Range: (-1, 1)
- Commonly used as activation function in ML
Fully qualified path: cairo_fp::f128::math::hyp::tanh
fn tanh(a: Fixed) -> Fixed
acosh
Calculates the inverse hyperbolic cosine: ln(x + sqrt(x² - 1))
Domain
x >= 1
Range
[0, ∞)
Fully qualified path: cairo_fp::f128::math::hyp::acosh
fn acosh(a: Fixed) -> Fixed
asinh
Calculates the inverse hyperbolic sine: ln(x + sqrt(x² + 1))
Domain
All real numbers
Range
All real numbers
Fully qualified path: cairo_fp::f128::math::hyp::asinh
fn asinh(a: Fixed) -> Fixed
atanh
Calculates the inverse hyperbolic tangent: ln((1 + x) / (1 - x)) / 2
Domain
(-1, 1)
Range
All real numbers
Fully qualified path: cairo_fp::f128::math::hyp::atanh
fn atanh(a: Fixed) -> Fixed
interest
Interest & Time-Value Calculations
Financial functions for DeFi applications.
Functions
linear_interpolate- Interpolation between two valuesexponential_growth- Growth with compound ratedecay- Exponential decaycompound- Compound interest with frequencysimple_interest- Simple interest calculationcontinuous_compound- Continuous compounding (e^rt)present_value- Discount future valueeffective_annual_rate- Convert nominal to effective rate
Example
use cairo_fp::f128::math::interest::{compound, simple_interest};
// $1000 at 10% for 1 year, compounded monthly
let principal = FixedTrait::new_unscaled(1000, false);
let rate = FixedTrait::new(1844674407370955162, false); // 0.1
let n = FixedTrait::new_unscaled(12, false);
let t = FixedTrait::ONE();
let result = compound(principal, rate, n, t); // ~$1104.71
Fully qualified path: cairo_fp::f128::math::interest
Free functions
| linear_interpolate | Linear interpolation between two values. Returns start + (end - start) * t… |
| exponential_growth | Calculates exponential growth: initial × (1 + rate)^periods |
| decay | Calculates exponential decay: initial × (1 - rate)^periods Requires rate < 1 for meaningful results. |
| compound | Calculates compound interest with specified frequency. Formula: principal × (1 + rate/n)^(n×t)… |
| simple_interest | Calculates simple interest: principal × (1 + rate × time) |
| continuous_compound | Calculates continuously compounded interest: principal × e^(rate × time) The theoretical limit of compound interest as compounding frequency → ∞. |
| present_value | Calculates the present value of a future amount. Formula: FV / (1 + rate)^periods… |
| effective_annual_rate | Calculates the effective annual rate (EAR) from a nominal rate. Formula: (1 + r/n)^n - 1… |
Free functions
Free functions
| linear_interpolate | Linear interpolation between two values. Returns start + (end - start) * t… |
| exponential_growth | Calculates exponential growth: initial × (1 + rate)^periods |
| decay | Calculates exponential decay: initial × (1 - rate)^periods Requires rate < 1 for meaningful results. |
| compound | Calculates compound interest with specified frequency. Formula: principal × (1 + rate/n)^(n×t)… |
| simple_interest | Calculates simple interest: principal × (1 + rate × time) |
| continuous_compound | Calculates continuously compounded interest: principal × e^(rate × time) The theoretical limit of compound interest as compounding frequency → ∞. |
| present_value | Calculates the present value of a future amount. Formula: FV / (1 + rate)^periods… |
| effective_annual_rate | Calculates the effective annual rate (EAR) from a nominal rate. Formula: (1 + r/n)^n - 1… |
linear_interpolate
Linear interpolation between two values.
Returns start + (end - start) * t
Arguments
start- Start value (t=0)end- End value (t=1)t- Interpolation factor (typically 0 to 1)
Fully qualified path: cairo_fp::f128::math::interest::linear_interpolate
fn linear_interpolate(start: Fixed, end: Fixed, t: Fixed) -> Fixed
exponential_growth
Calculates exponential growth: initial × (1 + rate)^periods
Fully qualified path: cairo_fp::f128::math::interest::exponential_growth
fn exponential_growth(initial: Fixed, rate: Fixed, periods: Fixed) -> Fixed
decay
Calculates exponential decay: initial × (1 - rate)^periods
Requires rate < 1 for meaningful results.
Fully qualified path: cairo_fp::f128::math::interest::decay
fn decay(initial: Fixed, rate: Fixed, periods: Fixed) -> Fixed
compound
Calculates compound interest with specified frequency.
Formula: principal × (1 + rate/n)^(n×t)
Arguments
principal- Initial amountrate- Annual interest rate (e.g., 0.1 for 10%)n- Compounding frequency per period (e.g., 12 for monthly)t- Number of periods (e.g., years)
Fully qualified path: cairo_fp::f128::math::interest::compound
fn compound(principal: Fixed, rate: Fixed, n: Fixed, t: Fixed) -> Fixed
simple_interest
Calculates simple interest: principal × (1 + rate × time)
Fully qualified path: cairo_fp::f128::math::interest::simple_interest
fn simple_interest(principal: Fixed, rate: Fixed, time: Fixed) -> Fixed
continuous_compound
Calculates continuously compounded interest: principal × e^(rate × time)
The theoretical limit of compound interest as compounding frequency → ∞.
Fully qualified path: cairo_fp::f128::math::interest::continuous_compound
fn continuous_compound(principal: Fixed, rate: Fixed, time: Fixed) -> Fixed
present_value
Calculates the present value of a future amount.
Formula: FV / (1 + rate)^periods
Arguments
future_value- The future amountrate- Discount rate per periodperiods- Number of periods
Fully qualified path: cairo_fp::f128::math::interest::present_value
fn present_value(future_value: Fixed, rate: Fixed, periods: Fixed) -> Fixed
effective_annual_rate
Calculates the effective annual rate (EAR) from a nominal rate.
Formula: (1 + r/n)^n - 1
Arguments
nominal_rate- The stated annual ratecompounds_per_year- Number of compounding periods per year
Fully qualified path: cairo_fp::f128::math::interest::effective_annual_rate
fn effective_annual_rate(nominal_rate: Fixed, compounds_per_year: Fixed) -> Fixed
lut
Lookup Tables
Precomputed lookup tables for fast mathematical operations. These functions use binary search through hardcoded values to avoid expensive runtime calculations.
Functions
msb- Most significant bit position and power of 2exp2- Powers of 2 for exponents 0-64sin- Sine interpolation data for 256 slotsatan- Arctangent interpolation data for 100 slots
Implementation Notes
These lookup tables are optimized for gas efficiency by using cascading if-statements with binary search patterns. While the code is verbose, it provides O(log n) lookup time.
Fully qualified path: cairo_fp::f128::math::lut
Free functions
Free functions
Free functions
msb
Calculates the most significant bit position.
Arguments
whole- The value to analyze (0 to 2^64)
Returns
A tuple of (bit_position, power_of_2) where:
bit_positionis the index of the MSB (0-64)power_of_2is 2^bit_position
Fully qualified path: cairo_fp::f128::math::lut::msb
fn msb(whole: u128) -> (u128, u128)
exp2
Fully qualified path: cairo_fp::f128::math::lut::exp2
fn exp2(exp: u128) -> u128
sin
Fully qualified path: cairo_fp::f128::math::lut::sin
fn sin(a: u128) -> (u128, u128, u128)
atan
Fully qualified path: cairo_fp::f128::math::lut::atan
fn atan(a: u128) -> (u128, u128, u128)
ops
Mathematical Operations
Core arithmetic and mathematical functions for fixed-point numbers.
Basic Arithmetic
add,sub,mul,div- Basic operationsneg,abs,rem- Sign and remainder
Rounding
floor- Round down (toward negative infinity)ceil- Round up (toward positive infinity)round- Round to nearest (half up)
Power & Exponential
exp- Natural exponential (e^x)exp2- Binary exponential (2^x)exp2_int- Fast 2^x for integer exponentspow- General power function (x^y)sqrt- Square rootcbrt- Cube root
Logarithms
ln- Natural logarithmlog2- Base-2 logarithmlog10- Base-10 logarithm
Comparison
eq,ne- Equalitylt,le,gt,ge- Ordering
Fully qualified path: cairo_fp::f128::math::ops
Free functions
| abs | Returns the absolute value of a fixed-point number…. |
| add | Adds two fixed-point numbers. |
| ceil | Rounds up to the nearest integer (toward positive infinity)…. |
| div | Divides two fixed-point numbers…. |
| eq | Checks equality of two fixed-point numbers. |
| exp | Calculates the natural exponential: e^x… |
| exp2 | Calculates the binary exponential: 2^x Supports both positive and negative exponents…. |
| exp2_int | Fast 2^x for integer exponents. Uses a lookup table for O(1) computation…. |
| floor | Rounds down to the nearest integer (toward negative infinity)…. |
| ge | — |
| gt | — |
| le | — |
| ln | Calculates the natural logarithm: ln(x)… |
| log2 | Calculates the base-2 logarithm: log₂(x)… |
| log10 | Calculates the base-10 logarithm: log₁₀(x)… |
| lt | — |
| mul | Multiplies two fixed-point numbers. |
| mul_64 | — |
| ne | — |
| neg | — |
| pow | Calculates x^y (power function). Automatically uses a faster algorithm for integer exponents…. |
| pow_int | — |
| rem | — |
| round | Rounds to the nearest integer (half up)…. |
| sqrt | Calculates the square root…. |
| cbrt | Calculates the cube root. Preserves sign: cbrt(-8) = -2 Useful for 3-asset AMM pool calculations (geometric mean of 3 values)…. |
| sub | — |
| _split_unsigned | — |
Structs
| f64 | — |
Impls
Free functions
Free functions
| abs | Returns the absolute value of a fixed-point number…. |
| add | Adds two fixed-point numbers. |
| ceil | Rounds up to the nearest integer (toward positive infinity)…. |
| div | Divides two fixed-point numbers…. |
| eq | Checks equality of two fixed-point numbers. |
| exp | Calculates the natural exponential: e^x… |
| exp2 | Calculates the binary exponential: 2^x Supports both positive and negative exponents…. |
| exp2_int | Fast 2^x for integer exponents. Uses a lookup table for O(1) computation…. |
| floor | Rounds down to the nearest integer (toward negative infinity)…. |
| ge | — |
| gt | — |
| le | — |
| ln | Calculates the natural logarithm: ln(x)… |
| log2 | Calculates the base-2 logarithm: log₂(x)… |
| log10 | Calculates the base-10 logarithm: log₁₀(x)… |
| lt | — |
| mul | Multiplies two fixed-point numbers. |
| mul_64 | — |
| ne | — |
| neg | — |
| pow | Calculates x^y (power function). Automatically uses a faster algorithm for integer exponents…. |
| pow_int | — |
| rem | — |
| round | Rounds to the nearest integer (half up)…. |
| sqrt | Calculates the square root…. |
| cbrt | Calculates the cube root. Preserves sign: cbrt(-8) = -2 Useful for 3-asset AMM pool calculations (geometric mean of 3 values)…. |
| sub | — |
| _split_unsigned | — |
abs
Returns the absolute value of a fixed-point number.
Arguments
a- The input value
Returns
The absolute value (always positive)
Fully qualified path: cairo_fp::f128::math::ops::abs
fn abs(a: Fixed) -> Fixed
add
Adds two fixed-point numbers.
Fully qualified path: cairo_fp::f128::math::ops::add
fn add(a: Fixed, b: Fixed) -> Fixed
ceil
Rounds up to the nearest integer (toward positive infinity).
Examples
ceil(2.1)→3ceil(-2.9)→-2
Fully qualified path: cairo_fp::f128::math::ops::ceil
fn ceil(a: Fixed) -> Fixed
div
Divides two fixed-point numbers.
Panics
Panics if b is zero.
Fully qualified path: cairo_fp::f128::math::ops::div
fn div(a: Fixed, b: Fixed) -> Fixed
eq
Checks equality of two fixed-point numbers.
Fully qualified path: cairo_fp::f128::math::ops::eq
fn eq(a: @Fixed, b: @Fixed) -> bool
exp
Calculates the natural exponential: e^x
Gas Cost
~176,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::exp
fn exp(a: Fixed) -> Fixed
exp2
Calculates the binary exponential: 2^x
Supports both positive and negative exponents.
Gas Cost
~167,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::exp2
fn exp2(a: Fixed) -> Fixed
exp2_int
Fast 2^x for integer exponents.
Uses a lookup table for O(1) computation.
Gas Cost
~17,500 (f128) - ~10x faster than exp2
Fully qualified path: cairo_fp::f128::math::ops::exp2_int
fn exp2_int(exp: u128) -> Fixed
floor
Rounds down to the nearest integer (toward negative infinity).
Examples
floor(2.9)→2floor(-2.1)→-3
Fully qualified path: cairo_fp::f128::math::ops::floor
fn floor(a: Fixed) -> Fixed
ge
Fully qualified path: cairo_fp::f128::math::ops::ge
fn ge(a: Fixed, b: Fixed) -> bool
gt
Fully qualified path: cairo_fp::f128::math::ops::gt
fn gt(a: Fixed, b: Fixed) -> bool
le
Fully qualified path: cairo_fp::f128::math::ops::le
fn le(a: Fixed, b: Fixed) -> bool
ln
Calculates the natural logarithm: ln(x)
Panics
Panics if a is zero or negative.
Gas Cost
~40,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::ln
fn ln(a: Fixed) -> Fixed
log2
Calculates the base-2 logarithm: log₂(x)
Panics
Panics if a is zero or negative.
Gas Cost
~190,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::log2
fn log2(a: Fixed) -> Fixed
log10
Calculates the base-10 logarithm: log₁₀(x)
Panics
Panics if a is zero or negative.
Gas Cost
~201,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::log10
fn log10(a: Fixed) -> Fixed
lt
Fully qualified path: cairo_fp::f128::math::ops::lt
fn lt(a: Fixed, b: Fixed) -> bool
mul
Multiplies two fixed-point numbers.
Fully qualified path: cairo_fp::f128::math::ops::mul
fn mul(a: Fixed, b: Fixed) -> Fixed
mul_64
Fully qualified path: cairo_fp::f128::math::ops::mul_64
fn mul_64(a: f64, b: f64) -> f64
ne
Fully qualified path: cairo_fp::f128::math::ops::ne
fn ne(a: @Fixed, b: @Fixed) -> bool
neg
Fully qualified path: cairo_fp::f128::math::ops::neg
fn neg(a: Fixed) -> Fixed
pow
Calculates x^y (power function).
Automatically uses a faster algorithm for integer exponents.
Gas Cost
- Integer exponent: ~75,000 (f128)
- Fractional exponent: ~362,000 (f128)
Panics
Panics if a is negative and b is fractional.
Fully qualified path: cairo_fp::f128::math::ops::pow
fn pow(a: Fixed, b: Fixed) -> Fixed
pow_int
Fully qualified path: cairo_fp::f128::math::ops::pow_int
fn pow_int(a: Fixed, b: u128, sign: bool) -> Fixed
rem
Fully qualified path: cairo_fp::f128::math::ops::rem
fn rem(a: Fixed, b: Fixed) -> Fixed
round
Rounds to the nearest integer (half up).
Examples
round(2.4)→2round(2.5)→3round(-2.5)→-3
Fully qualified path: cairo_fp::f128::math::ops::round
fn round(a: Fixed) -> Fixed
sqrt
Calculates the square root.
Panics
Panics if a is negative.
Gas Cost
~33,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::sqrt
fn sqrt(a: Fixed) -> Fixed
cbrt
Calculates the cube root.
Preserves sign: cbrt(-8) = -2
Useful for 3-asset AMM pool calculations (geometric mean of 3 values).
Gas Cost
~217,000 - ~363,000 (f128)
Fully qualified path: cairo_fp::f128::math::ops::cbrt
fn cbrt(a: Fixed) -> Fixed
sub
Fully qualified path: cairo_fp::f128::math::ops::sub
fn sub(a: Fixed, b: Fixed) -> Fixed
_split_unsigned
Fully qualified path: cairo_fp::f128::math::ops::_split_unsigned
fn _split_unsigned(a: Fixed) -> (u128, u128)
Structs
Structs
| f64 | — |
f64
Fully qualified path: cairo_fp::f128::math::ops::f64
[derive(Copy, Drop, Serde)]
struct f64 {
mag: u64,
sign: bool,
}
Members
mag
Fully qualified path: cairo_fp::f128::math::ops::f64::mag
mag: u64
sign
Fully qualified path: cairo_fp::f128::math::ops::f64::sign
sign: bool
Impls
Impls
f64Copy
Fully qualified path: cairo_fp::f128::math::ops::f64Copy
impl f64Copy of Copy<f64>;
f64Drop
Fully qualified path: cairo_fp::f128::math::ops::f64Drop
impl f64Drop of Drop<f64>;
f64Serde
Fully qualified path: cairo_fp::f128::math::ops::f64Serde
impl f64Serde of Serde<f64>;
Impl functions
serialize
Fully qualified path: cairo_fp::f128::math::ops::f64Serde::serialize
fn serialize(self: @f64, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f128::math::ops::f64Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<f64>
pool
AMM Pool Math
Constant product (x×y=k) AMM formulas and related calculations.
Core Functions
constant_product_out- Calculate swap output amountconstant_product_in- Calculate swap input amountprice_from_reserves- Get spot price from reservesprice_impact- Calculate trade price impactslippage- Calculate execution slippage
Liquidity Functions
initial_lp_tokens- LP tokens for initial deposit (sqrt(x×y))mint_lp_tokens- LP tokens for subsequent depositsliquidity_share- User’s share of reservesremove_liquidity- Amounts returned on withdrawal
Example
use cairo_fp::f128::math::pool::{constant_product_out, price_from_reserves};
// Pool with 1000 ETH and 2M USDC
let eth = FixedTrait::new_unscaled(1000, false);
let usdc = FixedTrait::new_unscaled(2000000, false);
// Get spot price
let price = price_from_reserves(eth, usdc).unwrap(); // 2000 USDC/ETH
// Swap 10 ETH
let eth_in = FixedTrait::new_unscaled(10, false);
let usdc_out = constant_product_out(eth, usdc, eth_in).unwrap();
Fully qualified path: cairo_fp::f128::math::pool
Free functions
| constant_product_out | Calculates output amount for a constant product swap. Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy… |
| constant_product_in | — |
| price_from_reserves | — |
| price_impact | — |
| slippage | — |
| liquidity_share | — |
| calculate_k | — |
| initial_lp_tokens | — |
| mint_lp_tokens | — |
| add_liquidity | — |
| remove_liquidity | — |
Free functions
Free functions
| constant_product_out | Calculates output amount for a constant product swap. Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy… |
| constant_product_in | — |
| price_from_reserves | — |
| price_impact | — |
| slippage | — |
| liquidity_share | — |
| calculate_k | — |
| initial_lp_tokens | — |
| mint_lp_tokens | — |
| add_liquidity | — |
| remove_liquidity | — |
constant_product_out
Calculates output amount for a constant product swap.
Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy
Formula
dy = y × dx / (x + dx)
Returns
None if reserves are zero
Fully qualified path: cairo_fp::f128::math::pool::constant_product_out
fn constant_product_out(x: Fixed, y: Fixed, dx: Fixed) -> Option<Fixed>
constant_product_in
Fully qualified path: cairo_fp::f128::math::pool::constant_product_in
fn constant_product_in(x: Fixed, y: Fixed, dy: Fixed) -> Option<Fixed>
price_from_reserves
Fully qualified path: cairo_fp::f128::math::pool::price_from_reserves
fn price_from_reserves(x: Fixed, y: Fixed) -> Option<Fixed>
price_impact
Fully qualified path: cairo_fp::f128::math::pool::price_impact
fn price_impact(spot_price: Fixed, execution_price: Fixed) -> Option<Fixed>
slippage
Fully qualified path: cairo_fp::f128::math::pool::slippage
fn slippage(expected: Fixed, actual: Fixed) -> Option<Fixed>
liquidity_share
Fully qualified path: cairo_fp::f128::math::pool::liquidity_share
fn liquidity_share(user_lp: Fixed, total_lp: Fixed, reserve: Fixed) -> Option<Fixed>
calculate_k
Fully qualified path: cairo_fp::f128::math::pool::calculate_k
fn calculate_k(x: Fixed, y: Fixed) -> Fixed
initial_lp_tokens
Fully qualified path: cairo_fp::f128::math::pool::initial_lp_tokens
fn initial_lp_tokens(x: Fixed, y: Fixed) -> Fixed
mint_lp_tokens
Fully qualified path: cairo_fp::f128::math::pool::mint_lp_tokens
fn mint_lp_tokens(
dx: Fixed, dy: Fixed, reserve_x: Fixed, reserve_y: Fixed, total_lp: Fixed,
) -> Option<Fixed>
add_liquidity
Fully qualified path: cairo_fp::f128::math::pool::add_liquidity
fn add_liquidity(reserve_x: Fixed, reserve_y: Fixed, dx: Fixed, dy: Fixed) -> (Fixed, Fixed)
remove_liquidity
Fully qualified path: cairo_fp::f128::math::pool::remove_liquidity
fn remove_liquidity(
lp_amount: Fixed, total_lp: Fixed, reserve_x: Fixed, reserve_y: Fixed,
) -> Option<(Fixed, Fixed)>
ratio
Ratio & Proportion Calculations
Utility functions for ratio calculations in DeFi contexts.
Functions
proportion- Calculate part/total ratioscale_by_ratio- Multiply amount by ratioinverse_ratio- Calculate 1/ratioweighted_average- Compute weighted averagepercentage_change- Calculate % change between valuespercentage_diff- Calculate absolute % difference
All functions that could divide by zero return Option<Fixed>.
Fully qualified path: cairo_fp::f128::math::ratio
Free functions
| proportion | Calculates the proportion of part to total…. |
| scale_by_ratio | Multiplies an amount by a ratio. Semantic wrapper around multiplication for clarity in DeFi contexts. |
| inverse_ratio | Calculates the inverse of a ratio (1 / ratio)…. |
| weighted_average | Calculates the weighted average of values…. |
| percentage_change | Calculates the percentage change between two values. Returns (new - old) / old as a ratio. Multiply by 100 to get percentage…. |
| percentage_diff | Calculates the absolute percentage difference. Returns |
Free functions
Free functions
| proportion | Calculates the proportion of part to total…. |
| scale_by_ratio | Multiplies an amount by a ratio. Semantic wrapper around multiplication for clarity in DeFi contexts. |
| inverse_ratio | Calculates the inverse of a ratio (1 / ratio)…. |
| weighted_average | Calculates the weighted average of values…. |
| percentage_change | Calculates the percentage change between two values. Returns (new - old) / old as a ratio. Multiply by 100 to get percentage…. |
| percentage_diff | Calculates the absolute percentage difference. Returns |
proportion
Calculates the proportion of part to total.
Returns
Some(part / total) or None if total is zero
Fully qualified path: cairo_fp::f128::math::ratio::proportion
fn proportion(part: Fixed, total: Fixed) -> Option<Fixed>
scale_by_ratio
Multiplies an amount by a ratio.
Semantic wrapper around multiplication for clarity in DeFi contexts.
Fully qualified path: cairo_fp::f128::math::ratio::scale_by_ratio
fn scale_by_ratio(amount: Fixed, ratio: Fixed) -> Fixed
inverse_ratio
Calculates the inverse of a ratio (1 / ratio).
Returns
Some(1 / ratio) or None if ratio is zero
Fully qualified path: cairo_fp::f128::math::ratio::inverse_ratio
fn inverse_ratio(ratio: Fixed) -> Option<Fixed>
weighted_average
Calculates the weighted average of values.
Arguments
values- Array of valuesweights- Array of weights (must match values length)
Returns
None if arrays differ in length or weights sum to zero
Fully qualified path: cairo_fp::f128::math::ratio::weighted_average
fn weighted_average(values: Span<Fixed>, weights: Span<Fixed>) -> Option<Fixed>
percentage_change
Calculates the percentage change between two values.
Returns (new - old) / old as a ratio. Multiply by 100 to get percentage.
Returns
None if old is zero
Fully qualified path: cairo_fp::f128::math::ratio::percentage_change
fn percentage_change(old: Fixed, new: Fixed) -> Option<Fixed>
percentage_diff
Calculates the absolute percentage difference.
Returns |a - b| / max(a, b)
Returns
None if both values are zero
Fully qualified path: cairo_fp::f128::math::ratio::percentage_diff
fn percentage_diff(a: Fixed, b: Fixed) -> Option<Fixed>
rounding
Rounding & Precision Utilities
Various rounding modes and precision control for DeFi applications.
Rounding Modes
round_down/round_up- Floor/Ceilinground_half_up- Standard rounding (0.5 rounds up)round_toward_zero- Truncationround_away_from_zero- Round away from zero
Precision Control
truncate_decimals- Truncate to N decimal placesround_to_decimals- Round to N decimal places
Comparison & Clamping
approx_equal- Check equality within toleranceclamp- Constrain value to rangemin/max- Minimum/Maximum
Fully qualified path: cairo_fp::f128::math::rounding
Free functions
| round_down | Rounds down to the nearest integer (floor). |
| round_up | Rounds up to the nearest integer (ceiling). |
| round_half_up | Standard rounding (half up). Rounds to nearest integer, with 0.5 rounding up. |
| round_toward_zero | Rounds toward zero (truncation)…. |
| round_away_from_zero | Rounds away from zero…. |
| truncate_decimals | — |
| round_to_decimals | — |
| approx_equal | — |
| clamp | — |
| min | — |
| max | — |
| _split_unsigned | — |
Free functions
Free functions
| round_down | Rounds down to the nearest integer (floor). |
| round_up | Rounds up to the nearest integer (ceiling). |
| round_half_up | Standard rounding (half up). Rounds to nearest integer, with 0.5 rounding up. |
| round_toward_zero | Rounds toward zero (truncation)…. |
| round_away_from_zero | Rounds away from zero…. |
| truncate_decimals | — |
| round_to_decimals | — |
| approx_equal | — |
| clamp | — |
| min | — |
| max | — |
| _split_unsigned | — |
round_down
Rounds down to the nearest integer (floor).
Fully qualified path: cairo_fp::f128::math::rounding::round_down
fn round_down(value: Fixed) -> Fixed
round_up
Rounds up to the nearest integer (ceiling).
Fully qualified path: cairo_fp::f128::math::rounding::round_up
fn round_up(value: Fixed) -> Fixed
round_half_up
Standard rounding (half up).
Rounds to nearest integer, with 0.5 rounding up.
Fully qualified path: cairo_fp::f128::math::rounding::round_half_up
fn round_half_up(value: Fixed) -> Fixed
round_toward_zero
Rounds toward zero (truncation).
- Positive numbers round down
- Negative numbers round up
Fully qualified path: cairo_fp::f128::math::rounding::round_toward_zero
fn round_toward_zero(value: Fixed) -> Fixed
round_away_from_zero
Rounds away from zero.
- Positive numbers round up
- Negative numbers round down
Fully qualified path: cairo_fp::f128::math::rounding::round_away_from_zero
fn round_away_from_zero(value: Fixed) -> Fixed
truncate_decimals
Fully qualified path: cairo_fp::f128::math::rounding::truncate_decimals
fn truncate_decimals(value: Fixed, decimals: u8) -> Fixed
round_to_decimals
Fully qualified path: cairo_fp::f128::math::rounding::round_to_decimals
fn round_to_decimals(value: Fixed, decimals: u8) -> Fixed
approx_equal
Fully qualified path: cairo_fp::f128::math::rounding::approx_equal
fn approx_equal(a: Fixed, b: Fixed, tolerance: Fixed) -> bool
clamp
Fully qualified path: cairo_fp::f128::math::rounding::clamp
fn clamp(value: Fixed, min: Fixed, max: Fixed) -> Fixed
min
Fully qualified path: cairo_fp::f128::math::rounding::min
fn min(a: Fixed, b: Fixed) -> Fixed
max
Fully qualified path: cairo_fp::f128::math::rounding::max
fn max(a: Fixed, b: Fixed) -> Fixed
_split_unsigned
Fully qualified path: cairo_fp::f128::math::rounding::_split_unsigned
fn _split_unsigned(a: Fixed) -> (u128, u128)
trig
Trigonometric Functions
All angles are in radians.
Standard Functions
High precision using Taylor series expansion:
sin,cos,tan- Basic trig functionsasin,acos,atan- Inverse functions
Fast Functions
Lower precision using lookup tables (~15x faster):
sin_fast,cos_fast,tan_fastasin_fast,acos_fast,atan_fast
Gas Costs (f128)
| Function | Standard | Fast |
|---|---|---|
| sin/cos | ~2.8M | ~180k |
| tan | ~2.9M | ~360k |
| asin/acos/atan | ~340k | ~330k |
When to Use Fast Variants
Use _fast functions for:
- Games and graphics
- UI animations
- Approximate calculations
Use standard functions for:
- Financial calculations
- Scientific computing
- When precision is critical
Fully qualified path: cairo_fp::f128::math::trig
Constants
| PI_u128 | π (pi) as a fixed-point constant. |
| HALF_PI_u128 | π/2 (half pi) as a fixed-point constant. |
Free functions
| acos | Calculates the arc cosine (inverse cosine)…. |
| acos_fast | Fast arc cosine using lookup table. |
| asin | Calculates the arc sine (inverse sine)…. |
| asin_fast | Fast arc sine using lookup table. |
| atan | Calculates the arc tangent (inverse tangent)…. |
| atan_fast | Fast arc tangent using lookup table. |
| cos | Calculates the cosine of an angle…. |
| cos_fast | Fast cosine using lookup table. |
| sin | Calculates the sine of an angle. Uses Taylor series for high precision…. |
| sin_fast | Fast sine using lookup table. |
| tan | Calculates the tangent of an angle…. |
| tan_fast | Fast tangent using lookup table. |
| _sin_loop | — |
Constants
Constants
| PI_u128 | π (pi) as a fixed-point constant. |
| HALF_PI_u128 | π/2 (half pi) as a fixed-point constant. |
PI_u128
π (pi) as a fixed-point constant.
Fully qualified path: cairo_fp::f128::math::trig::PI_u128
const PI_u128: u128 = 57952155664616982739;
HALF_PI_u128
π/2 (half pi) as a fixed-point constant.
Fully qualified path: cairo_fp::f128::math::trig::HALF_PI_u128
const HALF_PI_u128: u128 = 28976077832308491370;
Free functions
Free functions
| acos | Calculates the arc cosine (inverse cosine)…. |
| acos_fast | Fast arc cosine using lookup table. |
| asin | Calculates the arc sine (inverse sine)…. |
| asin_fast | Fast arc sine using lookup table. |
| atan | Calculates the arc tangent (inverse tangent)…. |
| atan_fast | Fast arc tangent using lookup table. |
| cos | Calculates the cosine of an angle…. |
| cos_fast | Fast cosine using lookup table. |
| sin | Calculates the sine of an angle. Uses Taylor series for high precision…. |
| sin_fast | Fast sine using lookup table. |
| tan | Calculates the tangent of an angle…. |
| tan_fast | Fast tangent using lookup table. |
| _sin_loop | — |
acos
Calculates the arc cosine (inverse cosine).
Arguments
a- Value in range -1, 1
Returns
Angle in radians 0, π
Panics
Panics if |a| > 1
Fully qualified path: cairo_fp::f128::math::trig::acos
fn acos(a: Fixed) -> Fixed
acos_fast
Fast arc cosine using lookup table.
Fully qualified path: cairo_fp::f128::math::trig::acos_fast
fn acos_fast(a: Fixed) -> Fixed
asin
Calculates the arc sine (inverse sine).
Arguments
a- Value in range -1, 1
Returns
Angle in radians -π/2, π/2
Panics
Panics if |a| > 1
Fully qualified path: cairo_fp::f128::math::trig::asin
fn asin(a: Fixed) -> Fixed
asin_fast
Fast arc sine using lookup table.
Fully qualified path: cairo_fp::f128::math::trig::asin_fast
fn asin_fast(a: Fixed) -> Fixed
atan
Calculates the arc tangent (inverse tangent).
Arguments
a- Any real number
Returns
Angle in radians (-π/2, π/2)
Fully qualified path: cairo_fp::f128::math::trig::atan
fn atan(a: Fixed) -> Fixed
atan_fast
Fast arc tangent using lookup table.
Fully qualified path: cairo_fp::f128::math::trig::atan_fast
fn atan_fast(a: Fixed) -> Fixed
cos
Calculates the cosine of an angle.
Arguments
a- Angle in radians
Returns
Cosine value in range -1, 1
Fully qualified path: cairo_fp::f128::math::trig::cos
fn cos(a: Fixed) -> Fixed
cos_fast
Fast cosine using lookup table.
Fully qualified path: cairo_fp::f128::math::trig::cos_fast
fn cos_fast(a: Fixed) -> Fixed
sin
Calculates the sine of an angle.
Uses Taylor series for high precision.
Arguments
a- Angle in radians
Returns
Sine value in range -1, 1
Fully qualified path: cairo_fp::f128::math::trig::sin
fn sin(a: Fixed) -> Fixed
sin_fast
Fast sine using lookup table.
Fully qualified path: cairo_fp::f128::math::trig::sin_fast
fn sin_fast(a: Fixed) -> Fixed
tan
Calculates the tangent of an angle.
Arguments
a- Angle in radians
Panics
Panics when cos(a) = 0 (at π/2 + nπ)
Fully qualified path: cairo_fp::f128::math::trig::tan
fn tan(a: Fixed) -> Fixed
tan_fast
Fast tangent using lookup table.
Fully qualified path: cairo_fp::f128::math::trig::tan_fast
fn tan_fast(a: Fixed) -> Fixed
_sin_loop
Fully qualified path: cairo_fp::f128::math::trig::_sin_loop
fn _sin_loop(a: Fixed, i: u128, acc: Fixed) -> Fixed
procgen
Procedural Generation (f128)
Utilities for procedural content generation using 64.64 fixed-point.
Modules
Fully qualified path: cairo_fp::f128::procgen
Modules
Modules
Modules
rand
Random Number Generation (f128)
Pseudo-random number generation utilities using 64.64 fixed-point.
Functions
derive- Derive a new seed from an existing seed and entropyfixed_between- Random fixed-point in range [low, high)u128_between- Random u128 in range [low, high)fixed_normal_between- Normally distributed random (approximation)u128_normal_between- Normally distributed u128 (approximation)
Note
These are deterministic pseudo-random generators suitable for games and simulations, not for cryptographic purposes.
Fully qualified path: cairo_fp::f128::procgen::rand
Free functions
| derive | Derives a new seed by hashing the current seed with entropy. |
| fixed_between | Returns a pseudo-random fixed-point value in range [ low, high). The value is deterministic based on the seed. |
| u128_between | — |
| fixed_normal_between | — |
| u128_normal_between | — |
| _fixed_normal_between_loop | — |
Free functions
Free functions
| derive | Derives a new seed by hashing the current seed with entropy. |
| fixed_between | Returns a pseudo-random fixed-point value in range [ low, high). The value is deterministic based on the seed. |
| u128_between | — |
| fixed_normal_between | — |
| u128_normal_between | — |
| _fixed_normal_between_loop | — |
derive
Derives a new seed by hashing the current seed with entropy.
Fully qualified path: cairo_fp::f128::procgen::rand::derive
fn derive(seed: felt252, entropy: felt252) -> felt252
fixed_between
Returns a pseudo-random fixed-point value in range [low, high).
The value is deterministic based on the seed.
Fully qualified path: cairo_fp::f128::procgen::rand::fixed_between
fn fixed_between(seed: felt252, low: Fixed, high: Fixed) -> Fixed
u128_between
Fully qualified path: cairo_fp::f128::procgen::rand::u128_between
fn u128_between(seed: felt252, low: u128, high: u128) -> u128
fixed_normal_between
Fully qualified path: cairo_fp::f128::procgen::rand::fixed_normal_between
fn fixed_normal_between(seed: felt252, low: Fixed, high: Fixed) -> Fixed
u128_normal_between
Fully qualified path: cairo_fp::f128::procgen::rand::u128_normal_between
fn u128_normal_between(seed: felt252, low: u128, high: u128) -> u128
_fixed_normal_between_loop
Fully qualified path: cairo_fp::f128::procgen::rand::_fixed_normal_between_loop
fn _fixed_normal_between_loop(
seed: felt252, low: Fixed, high: Fixed, acc: Fixed, iter: felt252,
) -> Fixed
simplex3
3D Simplex Noise (f128)
Implementation of 3D Simplex noise for procedural generation. Useful for terrain generation, textures, and other game/graphics applications.
Functions
noise- Generate noise value for a 3D pointnoise_octaves- Generate layered noise with multiple octaves
Output Range
Returns values in the range -1, 1.
Fully qualified path: cairo_fp::f128::procgen::simplex3
Free functions
| permute | Permutation function for noise generation. |
| taylor_inv_sqrt | — |
| step | — |
| noise | — |
| noise_octaves | — |
Free functions
Free functions
| permute | Permutation function for noise generation. |
| taylor_inv_sqrt | — |
| step | — |
| noise | — |
| noise_octaves | — |
permute
Permutation function for noise generation.
Fully qualified path: cairo_fp::f128::procgen::simplex3::permute
fn permute(x: Vec4) -> Vec4
taylor_inv_sqrt
Fully qualified path: cairo_fp::f128::procgen::simplex3::taylor_inv_sqrt
fn taylor_inv_sqrt(r: Vec4) -> Vec4
step
Fully qualified path: cairo_fp::f128::procgen::simplex3::step
fn step(edge: Fixed, x: Fixed) -> Fixed
noise
Fully qualified path: cairo_fp::f128::procgen::simplex3::noise
fn noise(v: Vec3) -> Fixed
noise_octaves
Fully qualified path: cairo_fp::f128::procgen::simplex3::noise_octaves
fn noise_octaves(v: Vec3, mut octaves: u128, persistence: Fixed) -> Fixed
test
Fully qualified path: cairo_fp::f128::test
Modules
Modules
Modules
helpers
Fully qualified path: cairo_fp::f128::test::helpers
Constants
Free functions
Constants
Constants
DEFAULT_PRECISION
Fully qualified path: cairo_fp::f128::test::helpers::DEFAULT_PRECISION
const DEFAULT_PRECISION: u128 = 1844674407370;
Free functions
Free functions
assert_precise
Fully qualified path: cairo_fp::f128::test::helpers::assert_precise
fn assert_precise(result: Fixed, expected: felt252, msg: felt252, custom_precision: Option<u128>)
assert_relative
Fully qualified path: cairo_fp::f128::test::helpers::assert_relative
fn assert_relative(result: Fixed, expected: felt252, msg: felt252, custom_precision: Option<u128>)
types
Fully qualified path: cairo_fp::f128::types
Modules
Modules
Modules
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:truefor negative,falsefor 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
| PRIME | The Starknet field prime. |
| ONE | One (1.0) as a felt252, equal to 2^64. |
| ONE_u128 | One (1.0) as a u128, equal to 2^64. |
| HALF | Half (0.5) as a felt252, equal to 2^63. |
| HALF_u128 | Half (0.5) as a u128, equal to 2^63. |
| MAX_u128 | Maximum u128 value (2^128 - 1). |
Structs
| Fixed | A 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
| FixedTrait | Trait defining operations for fixed-point numbers. Provides constructors, mathematical operations, trigonometric functions, and hyperbolic functions for the… |
Impls
Constants
Constants
| PRIME | The Starknet field prime. |
| ONE | One (1.0) as a felt252, equal to 2^64. |
| ONE_u128 | One (1.0) as a u128, equal to 2^64. |
| HALF | Half (0.5) as a felt252, equal to 2^63. |
| HALF_u128 | Half (0.5) as a u128, equal to 2^63. |
| MAX_u128 | Maximum u128 value (2^128 - 1). |
PRIME
The Starknet field prime.
Fully qualified path: cairo_fp::f128::types::fixed::PRIME
const PRIME: felt252 = 3618502788666131213697322783095070105623107215331596699973092056135872020480;
ONE
One (1.0) as a felt252, equal to 2^64.
Fully qualified path: cairo_fp::f128::types::fixed::ONE
const ONE: felt252 = 18446744073709551616;
ONE_u128
One (1.0) as a u128, equal to 2^64.
Fully qualified path: cairo_fp::f128::types::fixed::ONE_u128
const ONE_u128: u128 = 18446744073709551616;
HALF
Half (0.5) as a felt252, equal to 2^63.
Fully qualified path: cairo_fp::f128::types::fixed::HALF
const HALF: felt252 = 9223372036854775808;
HALF_u128
Half (0.5) as a u128, equal to 2^63.
Fully qualified path: cairo_fp::f128::types::fixed::HALF_u128
const HALF_u128: u128 = 9223372036854775808;
MAX_u128
Maximum u128 value (2^128 - 1).
Fully qualified path: cairo_fp::f128::types::fixed::MAX_u128
const MAX_u128: u128 = 340282366920938463463374607431768211455;
Structs
Structs
| Fixed | A 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…. |
Fixed
A 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.
Fields
mag- The absolute magnitude, scaled by 2^64sign- The sign:truefor negative,falsefor positive/zero
Example
// Create 2.5: magnitude = 2.5 * 2^64
let value = Fixed { mag: 46116860184273879040, sign: false };
Fully qualified path: cairo_fp::f128::types::fixed::Fixed
[derive(Copy, Drop, Serde)]
struct Fixed {
mag: u128,
sign: bool,
}
Members
mag
Fully qualified path: cairo_fp::f128::types::fixed::Fixed::mag
mag: u128
sign
Fully qualified path: cairo_fp::f128::types::fixed::Fixed::sign
sign: bool
Traits
Traits
| FixedTrait | Trait defining operations for fixed-point numbers. Provides constructors, mathematical operations, trigonometric functions, and hyperbolic functions for the… |
FixedTrait
Trait defining operations for fixed-point numbers.
Provides constructors, mathematical operations, trigonometric functions,
and hyperbolic functions for the Fixed type.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait
trait FixedTrait
Trait functions
ZERO
Returns zero (0.0).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::ZERO
fn ZERO() -> Fixed
ONE
Returns one (1.0).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::ONE
fn ONE() -> Fixed
new
Creates a new fixed-point number from a pre-scaled magnitude.
Arguments
mag- The magnitude, already scaled by 2^64sign-truefor negative,falsefor positive
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::new
fn new(mag: u128, sign: bool) -> Fixed
new_unscaled
Creates a new fixed-point number from an unscaled integer.
The value is automatically scaled by ONE (2^64).
Arguments
mag- The integer valuesign-truefor negative,falsefor positive
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::new_unscaled
fn new_unscaled(mag: u128, sign: bool) -> Fixed
from_felt
Creates a fixed-point number from a felt252 (pre-scaled).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::from_felt
fn from_felt(val: felt252) -> Fixed
from_unscaled_felt
Creates a fixed-point number from an unscaled felt252.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::from_unscaled_felt
fn from_unscaled_felt(val: felt252) -> Fixed
abs
Returns the absolute value.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::abs
fn abs(self: Fixed) -> Fixed
ceil
Rounds up to the nearest integer.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::ceil
fn ceil(self: Fixed) -> Fixed
exp
Calculates e^x (natural exponential).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::exp
fn exp(self: Fixed) -> Fixed
exp2
Calculates 2^x (binary exponential).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::exp2
fn exp2(self: Fixed) -> Fixed
floor
Rounds down to the nearest integer.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::floor
fn floor(self: Fixed) -> Fixed
ln
Calculates ln(x) (natural logarithm). Panics if x <= 0.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::ln
fn ln(self: Fixed) -> Fixed
log2
Calculates log2(x) (base-2 logarithm). Panics if x <= 0.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::log2
fn log2(self: Fixed) -> Fixed
log10
Calculates log10(x) (base-10 logarithm). Panics if x <= 0.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::log10
fn log10(self: Fixed) -> Fixed
pow
Calculates x^b (power function).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::pow
fn pow(self: Fixed, b: Fixed) -> Fixed
round
Rounds to the nearest integer (half up).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::round
fn round(self: Fixed) -> Fixed
sqrt
Calculates the square root. Panics if x < 0.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::sqrt
fn sqrt(self: Fixed) -> Fixed
acos
Calculates arccos(x). Domain: -1, 1.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::acos
fn acos(self: Fixed) -> Fixed
acos_fast
Fast arccos using lookup table.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::acos_fast
fn acos_fast(self: Fixed) -> Fixed
asin
Calculates arcsin(x). Domain: -1, 1.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::asin
fn asin(self: Fixed) -> Fixed
asin_fast
Fast arcsin using lookup table.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::asin_fast
fn asin_fast(self: Fixed) -> Fixed
atan
Calculates arctan(x).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::atan
fn atan(self: Fixed) -> Fixed
atan_fast
Fast arctan using lookup table.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::atan_fast
fn atan_fast(self: Fixed) -> Fixed
cos
Calculates cos(x) using Taylor series.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::cos
fn cos(self: Fixed) -> Fixed
cos_fast
Fast cos using lookup table.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::cos_fast
fn cos_fast(self: Fixed) -> Fixed
sin
Calculates sin(x) using Taylor series.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::sin
fn sin(self: Fixed) -> Fixed
sin_fast
Fast sin using lookup table.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::sin_fast
fn sin_fast(self: Fixed) -> Fixed
tan
Calculates tan(x). Panics at x = π/2 + nπ.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::tan
fn tan(self: Fixed) -> Fixed
tan_fast
Fast tan using lookup table.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::tan_fast
fn tan_fast(self: Fixed) -> Fixed
acosh
Calculates acosh(x). Domain: x >= 1.
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::acosh
fn acosh(self: Fixed) -> Fixed
asinh
Calculates asinh(x).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::asinh
fn asinh(self: Fixed) -> Fixed
atanh
Calculates atanh(x). Domain: (-1, 1).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::atanh
fn atanh(self: Fixed) -> Fixed
cosh
Calculates cosh(x).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::cosh
fn cosh(self: Fixed) -> Fixed
sinh
Calculates sinh(x).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::sinh
fn sinh(self: Fixed) -> Fixed
tanh
Calculates tanh(x).
Fully qualified path: cairo_fp::f128::types::fixed::FixedTrait::tanh
fn tanh(self: Fixed) -> Fixed
Impls
Impls
FixedImpl
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl
impl FixedImpl of FixedTrait;
Impl functions
ZERO
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::ZERO
fn ZERO() -> Fixed
ONE
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::ONE
fn ONE() -> Fixed
new
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::new
fn new(mag: u128, sign: bool) -> Fixed
new_unscaled
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::new_unscaled
fn new_unscaled(mag: u128, sign: bool) -> Fixed
from_felt
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::from_felt
fn from_felt(val: felt252) -> Fixed
from_unscaled_felt
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::from_unscaled_felt
fn from_unscaled_felt(val: felt252) -> Fixed
abs
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::abs
fn abs(self: Fixed) -> Fixed
acos
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::acos
fn acos(self: Fixed) -> Fixed
acos_fast
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::acos_fast
fn acos_fast(self: Fixed) -> Fixed
acosh
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::acosh
fn acosh(self: Fixed) -> Fixed
asin
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::asin
fn asin(self: Fixed) -> Fixed
asin_fast
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::asin_fast
fn asin_fast(self: Fixed) -> Fixed
asinh
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::asinh
fn asinh(self: Fixed) -> Fixed
atan
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::atan
fn atan(self: Fixed) -> Fixed
atan_fast
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::atan_fast
fn atan_fast(self: Fixed) -> Fixed
atanh
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::atanh
fn atanh(self: Fixed) -> Fixed
ceil
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::ceil
fn ceil(self: Fixed) -> Fixed
cos
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::cos
fn cos(self: Fixed) -> Fixed
cos_fast
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::cos_fast
fn cos_fast(self: Fixed) -> Fixed
cosh
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::cosh
fn cosh(self: Fixed) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::floor
fn floor(self: Fixed) -> Fixed
exp
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::exp
fn exp(self: Fixed) -> Fixed
exp2
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::exp2
fn exp2(self: Fixed) -> Fixed
ln
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::ln
fn ln(self: Fixed) -> Fixed
log2
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::log2
fn log2(self: Fixed) -> Fixed
log10
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::log10
fn log10(self: Fixed) -> Fixed
pow
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::pow
fn pow(self: Fixed, b: Fixed) -> Fixed
round
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::round
fn round(self: Fixed) -> Fixed
sin
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::sin
fn sin(self: Fixed) -> Fixed
sin_fast
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::sin_fast
fn sin_fast(self: Fixed) -> Fixed
sinh
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::sinh
fn sinh(self: Fixed) -> Fixed
sqrt
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::sqrt
fn sqrt(self: Fixed) -> Fixed
tan
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::tan
fn tan(self: Fixed) -> Fixed
tan_fast
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::tan_fast
fn tan_fast(self: Fixed) -> Fixed
tanh
Fully qualified path: cairo_fp::f128::types::fixed::FixedImpl::tanh
fn tanh(self: Fixed) -> Fixed
Fixed128TryIntoFixed64
Fully qualified path: cairo_fp::f128::types::fixed::Fixed128TryIntoFixed64
impl Fixed128TryIntoFixed64 of TryInto<Fixed, Fixed>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::Fixed128TryIntoFixed64::try_into
fn try_into(self: Fixed) -> Option<Fixed>
FixedPrint
Fully qualified path: cairo_fp::f128::types::fixed::FixedPrint
impl FixedPrint of PrintTrait<Fixed>;
Impl functions
Fully qualified path: cairo_fp::f128::types::fixed::FixedPrint::print
fn print(self: Fixed)
FixedInto
Fully qualified path: cairo_fp::f128::types::fixed::FixedInto
impl FixedInto of Into<Fixed, felt252>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::FixedInto::into
fn into(self: Fixed) -> felt252
FixedTryIntoU128
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU128
impl FixedTryIntoU128 of TryInto<Fixed, u128>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU128::try_into
fn try_into(self: Fixed) -> Option<u128>
FixedTryIntoU64
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU64
impl FixedTryIntoU64 of TryInto<Fixed, u64>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU64::try_into
fn try_into(self: Fixed) -> Option<u64>
FixedTryIntoU32
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU32
impl FixedTryIntoU32 of TryInto<Fixed, u32>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU32::try_into
fn try_into(self: Fixed) -> Option<u32>
FixedTryIntoU16
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU16
impl FixedTryIntoU16 of TryInto<Fixed, u16>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU16::try_into
fn try_into(self: Fixed) -> Option<u16>
FixedTryIntoU8
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU8
impl FixedTryIntoU8 of TryInto<Fixed, u8>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::FixedTryIntoU8::try_into
fn try_into(self: Fixed) -> Option<u8>
U8IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::U8IntoFixed
impl U8IntoFixed of Into<u8, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::U8IntoFixed::into
fn into(self: u8) -> Fixed
U16IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::U16IntoFixed
impl U16IntoFixed of Into<u16, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::U16IntoFixed::into
fn into(self: u16) -> Fixed
U32IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::U32IntoFixed
impl U32IntoFixed of Into<u32, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::U32IntoFixed::into
fn into(self: u32) -> Fixed
U64IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::U64IntoFixed
impl U64IntoFixed of Into<u64, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::U64IntoFixed::into
fn into(self: u64) -> Fixed
U128IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::U128IntoFixed
impl U128IntoFixed of Into<u128, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::U128IntoFixed::into
fn into(self: u128) -> Fixed
U256TryIntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::U256TryIntoFixed
impl U256TryIntoFixed of TryInto<u256, Fixed>;
Impl functions
try_into
Fully qualified path: cairo_fp::f128::types::fixed::U256TryIntoFixed::try_into
fn try_into(self: u256) -> Option<Fixed>
I8IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::I8IntoFixed
impl I8IntoFixed of Into<i8, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::I8IntoFixed::into
fn into(self: i8) -> Fixed
I16IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::I16IntoFixed
impl I16IntoFixed of Into<i16, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::I16IntoFixed::into
fn into(self: i16) -> Fixed
I32IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::I32IntoFixed
impl I32IntoFixed of Into<i32, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::I32IntoFixed::into
fn into(self: i32) -> Fixed
I64IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::I64IntoFixed
impl I64IntoFixed of Into<i64, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::I64IntoFixed::into
fn into(self: i64) -> Fixed
I128IntoFixed
Fully qualified path: cairo_fp::f128::types::fixed::I128IntoFixed
impl I128IntoFixed of Into<i128, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f128::types::fixed::I128IntoFixed::into
fn into(self: i128) -> Fixed
FixedPartialEq
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialEq
impl FixedPartialEq of PartialEq<Fixed>;
Impl functions
eq
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialEq::eq
fn eq(lhs: @Fixed, rhs: @Fixed) -> bool
ne
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialEq::ne
fn ne(lhs: @Fixed, rhs: @Fixed) -> bool
FixedAdd
Fully qualified path: cairo_fp::f128::types::fixed::FixedAdd
impl FixedAdd of Add<Fixed>;
Impl functions
add
Fully qualified path: cairo_fp::f128::types::fixed::FixedAdd::add
fn add(lhs: Fixed, rhs: Fixed) -> Fixed
FixedAddAssign
Fully qualified path: cairo_fp::f128::types::fixed::FixedAddAssign
impl FixedAddAssign of AddAssign<Fixed, Fixed>;
Impl functions
add_assign
Fully qualified path: cairo_fp::f128::types::fixed::FixedAddAssign::add_assign
fn add_assign(ref self: Fixed, rhs: Fixed)
FixedSub
Fully qualified path: cairo_fp::f128::types::fixed::FixedSub
impl FixedSub of Sub<Fixed>;
Impl functions
sub
Fully qualified path: cairo_fp::f128::types::fixed::FixedSub::sub
fn sub(lhs: Fixed, rhs: Fixed) -> Fixed
FixedSubAssign
Fully qualified path: cairo_fp::f128::types::fixed::FixedSubAssign
impl FixedSubAssign of SubAssign<Fixed, Fixed>;
Impl functions
sub_assign
Fully qualified path: cairo_fp::f128::types::fixed::FixedSubAssign::sub_assign
fn sub_assign(ref self: Fixed, rhs: Fixed)
FixedMul
Fully qualified path: cairo_fp::f128::types::fixed::FixedMul
impl FixedMul of Mul<Fixed>;
Impl functions
mul
Fully qualified path: cairo_fp::f128::types::fixed::FixedMul::mul
fn mul(lhs: Fixed, rhs: Fixed) -> Fixed
FixedMulAssign
Fully qualified path: cairo_fp::f128::types::fixed::FixedMulAssign
impl FixedMulAssign of MulAssign<Fixed, Fixed>;
Impl functions
mul_assign
Fully qualified path: cairo_fp::f128::types::fixed::FixedMulAssign::mul_assign
fn mul_assign(ref self: Fixed, rhs: Fixed)
FixedDiv
Fully qualified path: cairo_fp::f128::types::fixed::FixedDiv
impl FixedDiv of Div<Fixed>;
Impl functions
div
Fully qualified path: cairo_fp::f128::types::fixed::FixedDiv::div
fn div(lhs: Fixed, rhs: Fixed) -> Fixed
FixedDivAssign
Fully qualified path: cairo_fp::f128::types::fixed::FixedDivAssign
impl FixedDivAssign of DivAssign<Fixed, Fixed>;
Impl functions
div_assign
Fully qualified path: cairo_fp::f128::types::fixed::FixedDivAssign::div_assign
fn div_assign(ref self: Fixed, rhs: Fixed)
FixedPartialOrd
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialOrd
impl FixedPartialOrd of PartialOrd<Fixed>;
Impl functions
ge
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialOrd::ge
fn ge(lhs: Fixed, rhs: Fixed) -> bool
gt
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialOrd::gt
fn gt(lhs: Fixed, rhs: Fixed) -> bool
le
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialOrd::le
fn le(lhs: Fixed, rhs: Fixed) -> bool
lt
Fully qualified path: cairo_fp::f128::types::fixed::FixedPartialOrd::lt
fn lt(lhs: Fixed, rhs: Fixed) -> bool
FixedNeg
Fully qualified path: cairo_fp::f128::types::fixed::FixedNeg
impl FixedNeg of Neg<Fixed>;
Impl functions
neg
Fully qualified path: cairo_fp::f128::types::fixed::FixedNeg::neg
fn neg(a: Fixed) -> Fixed
FixedRem
Fully qualified path: cairo_fp::f128::types::fixed::FixedRem
impl FixedRem of Rem<Fixed>;
Impl functions
rem
Fully qualified path: cairo_fp::f128::types::fixed::FixedRem::rem
fn rem(lhs: Fixed, rhs: Fixed) -> Fixed
PackFixed
Fully qualified path: cairo_fp::f128::types::fixed::PackFixed
impl PackFixed of StorePacking<Fixed, felt252>;
Impl functions
pack
Fully qualified path: cairo_fp::f128::types::fixed::PackFixed::pack
fn pack(value: Fixed) -> felt252
unpack
Fully qualified path: cairo_fp::f128::types::fixed::PackFixed::unpack
fn unpack(value: felt252) -> Fixed
FixedZero
Fully qualified path: cairo_fp::f128::types::fixed::FixedZero
impl FixedZero of Zero<Fixed>;
Impl functions
zero
Fully qualified path: cairo_fp::f128::types::fixed::FixedZero::zero
fn zero() -> Fixed
is_zero
Fully qualified path: cairo_fp::f128::types::fixed::FixedZero::is_zero
fn is_zero(self: @Fixed) -> bool
is_non_zero
Fully qualified path: cairo_fp::f128::types::fixed::FixedZero::is_non_zero
fn is_non_zero(self: @Fixed) -> bool
FixedOne
Fully qualified path: cairo_fp::f128::types::fixed::FixedOne
impl FixedOne of One<Fixed>;
Impl functions
one
Fully qualified path: cairo_fp::f128::types::fixed::FixedOne::one
fn one() -> Fixed
is_one
Fully qualified path: cairo_fp::f128::types::fixed::FixedOne::is_one
fn is_one(self: @Fixed) -> bool
is_non_one
Fully qualified path: cairo_fp::f128::types::fixed::FixedOne::is_non_one
fn is_non_one(self: @Fixed) -> bool
FixedCopy
Fully qualified path: cairo_fp::f128::types::fixed::FixedCopy
impl FixedCopy of Copy<Fixed>;
FixedDrop
Fully qualified path: cairo_fp::f128::types::fixed::FixedDrop
impl FixedDrop of Drop<Fixed>;
FixedSerde
Fully qualified path: cairo_fp::f128::types::fixed::FixedSerde
impl FixedSerde of Serde<Fixed>;
Impl functions
serialize
Fully qualified path: cairo_fp::f128::types::fixed::FixedSerde::serialize
fn serialize(self: @Fixed, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f128::types::fixed::FixedSerde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Fixed>
vec2
Fully qualified path: cairo_fp::f128::types::vec2
Free functions
Structs
| Vec2 | — |
Traits
Impls
Free functions
Free functions
abs
Fully qualified path: cairo_fp::f128::types::vec2::abs
fn abs(a: Vec2) -> Vec2
add
Fully qualified path: cairo_fp::f128::types::vec2::add
fn add(a: Vec2, b: Vec2) -> Vec2
cross
Fully qualified path: cairo_fp::f128::types::vec2::cross
fn cross(a: Vec2, b: Vec2) -> Fixed
div
Fully qualified path: cairo_fp::f128::types::vec2::div
fn div(a: Vec2, b: Vec2) -> Vec2
dot
Fully qualified path: cairo_fp::f128::types::vec2::dot
fn dot(a: Vec2, b: Vec2) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec2::floor
fn floor(a: Vec2) -> Vec2
mul
Fully qualified path: cairo_fp::f128::types::vec2::mul
fn mul(a: Vec2, b: Vec2) -> Vec2
norm
Fully qualified path: cairo_fp::f128::types::vec2::norm
fn norm(a: Vec2) -> Fixed
rem
Fully qualified path: cairo_fp::f128::types::vec2::rem
fn rem(a: Vec2, b: Vec2) -> Vec2
sub
Fully qualified path: cairo_fp::f128::types::vec2::sub
fn sub(a: Vec2, b: Vec2) -> Vec2
Structs
Structs
| Vec2 | — |
Vec2
Fully qualified path: cairo_fp::f128::types::vec2::Vec2
#[derive(Copy, Drop, Serde)]
struct Vec2 {
x: Fixed,
y: Fixed,
}
Members
x
Fully qualified path: cairo_fp::f128::types::vec2::Vec2::x
x: Fixed
y
Fully qualified path: cairo_fp::f128::types::vec2::Vec2::y
y: Fixed
Traits
Traits
Vec2Trait
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait
trait Vec2Trait
Trait functions
new
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::new
fn new(x: Fixed, y: Fixed) -> Vec2
splat
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::splat
fn splat(v: Fixed) -> Vec2
abs
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::abs
fn abs(self: Vec2) -> Vec2
cross
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::cross
fn cross(self: Vec2, rhs: Vec2) -> Fixed
dot
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::dot
fn dot(self: Vec2, rhs: Vec2) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::floor
fn floor(self: Vec2) -> Vec2
norm
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Trait::norm
fn norm(self: Vec2) -> Fixed
Impls
Impls
Vec2Impl
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl
impl Vec2Impl of Vec2Trait;
Impl functions
new
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::new
fn new(x: Fixed, y: Fixed) -> Vec2
splat
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::splat
fn splat(v: Fixed) -> Vec2
abs
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::abs
fn abs(self: Vec2) -> Vec2
cross
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::cross
fn cross(self: Vec2, rhs: Vec2) -> Fixed
dot
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::dot
fn dot(self: Vec2, rhs: Vec2) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::floor
fn floor(self: Vec2) -> Vec2
norm
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Impl::norm
fn norm(self: Vec2) -> Fixed
Vec2Print
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Print
impl Vec2Print of PrintTrait<Vec2>;
Impl functions
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Print::print
fn print(self: Vec2)
Vec2Add
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Add
impl Vec2Add of Add<Vec2>;
Impl functions
add
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Add::add
fn add(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Div
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Div
impl Vec2Div of Div<Vec2>;
Impl functions
div
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Div::div
fn div(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Mul
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Mul
impl Vec2Mul of Mul<Vec2>;
Impl functions
mul
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Mul::mul
fn mul(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Rem
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Rem
impl Vec2Rem of Rem<Vec2>;
Impl functions
rem
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Rem::rem
fn rem(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Sub
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Sub
impl Vec2Sub of Sub<Vec2>;
Impl functions
sub
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Sub::sub
fn sub(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Copy
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Copy
impl Vec2Copy of Copy<Vec2>;
Vec2Drop
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Drop
impl Vec2Drop of Drop<Vec2>;
Vec2Serde
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Serde
impl Vec2Serde of Serde<Vec2>;
Impl functions
serialize
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Serde::serialize
fn serialize(self: @Vec2, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f128::types::vec2::Vec2Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Vec2>
vec3
Fully qualified path: cairo_fp::f128::types::vec3
Free functions
Structs
| Vec3 | — |
Traits
Impls
Free functions
Free functions
abs
Fully qualified path: cairo_fp::f128::types::vec3::abs
fn abs(a: Vec3) -> Vec3
add
Fully qualified path: cairo_fp::f128::types::vec3::add
fn add(a: Vec3, b: Vec3) -> Vec3
cross
Fully qualified path: cairo_fp::f128::types::vec3::cross
fn cross(a: Vec3, b: Vec3) -> Vec3
div
Fully qualified path: cairo_fp::f128::types::vec3::div
fn div(a: Vec3, b: Vec3) -> Vec3
dot
Fully qualified path: cairo_fp::f128::types::vec3::dot
fn dot(a: Vec3, b: Vec3) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec3::floor
fn floor(a: Vec3) -> Vec3
mul
Fully qualified path: cairo_fp::f128::types::vec3::mul
fn mul(a: Vec3, b: Vec3) -> Vec3
norm
Fully qualified path: cairo_fp::f128::types::vec3::norm
fn norm(a: Vec3) -> Fixed
rem
Fully qualified path: cairo_fp::f128::types::vec3::rem
fn rem(a: Vec3, b: Vec3) -> Vec3
sub
Fully qualified path: cairo_fp::f128::types::vec3::sub
fn sub(a: Vec3, b: Vec3) -> Vec3
Structs
Structs
| Vec3 | — |
Vec3
Fully qualified path: cairo_fp::f128::types::vec3::Vec3
#[derive(Copy, Drop, Serde)]
struct Vec3 {
x: Fixed,
y: Fixed,
z: Fixed,
}
Members
x
Fully qualified path: cairo_fp::f128::types::vec3::Vec3::x
x: Fixed
y
Fully qualified path: cairo_fp::f128::types::vec3::Vec3::y
y: Fixed
z
Fully qualified path: cairo_fp::f128::types::vec3::Vec3::z
z: Fixed
Traits
Traits
Vec3Trait
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait
trait Vec3Trait
Trait functions
new
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::new
fn new(x: Fixed, y: Fixed, z: Fixed) -> Vec3
splat
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::splat
fn splat(v: Fixed) -> Vec3
abs
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::abs
fn abs(self: Vec3) -> Vec3
cross
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::cross
fn cross(self: Vec3, rhs: Vec3) -> Vec3
dot
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::dot
fn dot(self: Vec3, rhs: Vec3) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::floor
fn floor(self: Vec3) -> Vec3
norm
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::norm
fn norm(self: Vec3) -> Fixed
add
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::add
fn add(self: Vec3, scalar: Fixed) -> Vec3
sub
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::sub
fn sub(self: Vec3, scalar: Fixed) -> Vec3
mul
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::mul
fn mul(self: Vec3, scalar: Fixed) -> Vec3
div
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::div
fn div(self: Vec3, scalar: Fixed) -> Vec3
rem
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Trait::rem
fn rem(self: Vec3, scalar: Fixed) -> Vec3
Impls
Impls
Vec3Impl
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl
impl Vec3Impl of Vec3Trait;
Impl functions
new
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::new
fn new(x: Fixed, y: Fixed, z: Fixed) -> Vec3
splat
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::splat
fn splat(v: Fixed) -> Vec3
abs
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::abs
fn abs(self: Vec3) -> Vec3
cross
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::cross
fn cross(self: Vec3, rhs: Vec3) -> Vec3
dot
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::dot
fn dot(self: Vec3, rhs: Vec3) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::floor
fn floor(self: Vec3) -> Vec3
norm
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::norm
fn norm(self: Vec3) -> Fixed
add
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::add
fn add(self: Vec3, scalar: Fixed) -> Vec3
sub
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::sub
fn sub(self: Vec3, scalar: Fixed) -> Vec3
mul
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::mul
fn mul(self: Vec3, scalar: Fixed) -> Vec3
div
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::div
fn div(self: Vec3, scalar: Fixed) -> Vec3
rem
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Impl::rem
fn rem(self: Vec3, scalar: Fixed) -> Vec3
Vec3Print
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Print
impl Vec3Print of PrintTrait<Vec3>;
Impl functions
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Print::print
fn print(self: Vec3)
Vec3Add
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Add
impl Vec3Add of Add<Vec3>;
Impl functions
add
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Add::add
fn add(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Div
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Div
impl Vec3Div of Div<Vec3>;
Impl functions
div
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Div::div
fn div(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Mul
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Mul
impl Vec3Mul of Mul<Vec3>;
Impl functions
mul
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Mul::mul
fn mul(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Rem
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Rem
impl Vec3Rem of Rem<Vec3>;
Impl functions
rem
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Rem::rem
fn rem(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Sub
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Sub
impl Vec3Sub of Sub<Vec3>;
Impl functions
sub
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Sub::sub
fn sub(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Copy
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Copy
impl Vec3Copy of Copy<Vec3>;
Vec3Drop
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Drop
impl Vec3Drop of Drop<Vec3>;
Vec3Serde
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Serde
impl Vec3Serde of Serde<Vec3>;
Impl functions
serialize
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Serde::serialize
fn serialize(self: @Vec3, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f128::types::vec3::Vec3Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Vec3>
vec4
Fully qualified path: cairo_fp::f128::types::vec4
Free functions
Structs
| Vec4 | — |
Traits
Impls
Free functions
Free functions
abs
Fully qualified path: cairo_fp::f128::types::vec4::abs
fn abs(a: Vec4) -> Vec4
add
Fully qualified path: cairo_fp::f128::types::vec4::add
fn add(a: Vec4, b: Vec4) -> Vec4
div
Fully qualified path: cairo_fp::f128::types::vec4::div
fn div(a: Vec4, b: Vec4) -> Vec4
dot
Fully qualified path: cairo_fp::f128::types::vec4::dot
fn dot(a: Vec4, b: Vec4) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec4::floor
fn floor(a: Vec4) -> Vec4
mul
Fully qualified path: cairo_fp::f128::types::vec4::mul
fn mul(a: Vec4, b: Vec4) -> Vec4
norm
Fully qualified path: cairo_fp::f128::types::vec4::norm
fn norm(a: Vec4) -> Fixed
rem
Fully qualified path: cairo_fp::f128::types::vec4::rem
fn rem(a: Vec4, b: Vec4) -> Vec4
sub
Fully qualified path: cairo_fp::f128::types::vec4::sub
fn sub(a: Vec4, b: Vec4) -> Vec4
Structs
Structs
| Vec4 | — |
Vec4
Fully qualified path: cairo_fp::f128::types::vec4::Vec4
#[derive(Copy, Drop, Serde)]
struct Vec4 {
x: Fixed,
y: Fixed,
z: Fixed,
w: Fixed,
}
Members
x
Fully qualified path: cairo_fp::f128::types::vec4::Vec4::x
x: Fixed
y
Fully qualified path: cairo_fp::f128::types::vec4::Vec4::y
y: Fixed
z
Fully qualified path: cairo_fp::f128::types::vec4::Vec4::z
z: Fixed
w
Fully qualified path: cairo_fp::f128::types::vec4::Vec4::w
w: Fixed
Traits
Traits
Vec4Trait
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait
trait Vec4Trait
Trait functions
new
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::new
fn new(x: Fixed, y: Fixed, z: Fixed, w: Fixed) -> Vec4
splat
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::splat
fn splat(v: Fixed) -> Vec4
abs
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::abs
fn abs(self: Vec4) -> Vec4
dot
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::dot
fn dot(self: Vec4, rhs: Vec4) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::floor
fn floor(self: Vec4) -> Vec4
norm
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::norm
fn norm(self: Vec4) -> Fixed
add
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::add
fn add(self: Vec4, scalar: Fixed) -> Vec4
sub
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::sub
fn sub(self: Vec4, scalar: Fixed) -> Vec4
mul
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::mul
fn mul(self: Vec4, scalar: Fixed) -> Vec4
div
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::div
fn div(self: Vec4, scalar: Fixed) -> Vec4
rem
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Trait::rem
fn rem(self: Vec4, scalar: Fixed) -> Vec4
Impls
Impls
Vec4Impl
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl
impl Vec4Impl of Vec4Trait;
Impl functions
new
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::new
fn new(x: Fixed, y: Fixed, z: Fixed, w: Fixed) -> Vec4
splat
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::splat
fn splat(v: Fixed) -> Vec4
abs
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::abs
fn abs(self: Vec4) -> Vec4
dot
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::dot
fn dot(self: Vec4, rhs: Vec4) -> Fixed
floor
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::floor
fn floor(self: Vec4) -> Vec4
norm
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::norm
fn norm(self: Vec4) -> Fixed
add
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::add
fn add(self: Vec4, scalar: Fixed) -> Vec4
sub
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::sub
fn sub(self: Vec4, scalar: Fixed) -> Vec4
mul
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::mul
fn mul(self: Vec4, scalar: Fixed) -> Vec4
div
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::div
fn div(self: Vec4, scalar: Fixed) -> Vec4
rem
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Impl::rem
fn rem(self: Vec4, scalar: Fixed) -> Vec4
Vec4Print
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Print
impl Vec4Print of PrintTrait<Vec4>;
Impl functions
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Print::print
fn print(self: Vec4)
Vec4Add
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Add
impl Vec4Add of Add<Vec4>;
Impl functions
add
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Add::add
fn add(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Div
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Div
impl Vec4Div of Div<Vec4>;
Impl functions
div
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Div::div
fn div(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Mul
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Mul
impl Vec4Mul of Mul<Vec4>;
Impl functions
mul
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Mul::mul
fn mul(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Rem
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Rem
impl Vec4Rem of Rem<Vec4>;
Impl functions
rem
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Rem::rem
fn rem(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Sub
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Sub
impl Vec4Sub of Sub<Vec4>;
Impl functions
sub
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Sub::sub
fn sub(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Copy
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Copy
impl Vec4Copy of Copy<Vec4>;
Vec4Drop
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Drop
impl Vec4Drop of Drop<Vec4>;
Vec4Serde
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Serde
impl Vec4Serde of Serde<Vec4>;
Impl functions
serialize
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Serde::serialize
fn serialize(self: @Vec4, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f128::types::vec4::Vec4Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Vec4>
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
Modules
Modules
Modules
math
f64 Math Operations
Mathematical functions for 32.32 fixed-point numbers. All operations are optimized for lower gas costs compared to f128.
Modules
ops- Basic arithmetic and mathematical operationstrig- Trigonometric functions (sin, cos, tan, etc.)hyp- Hyperbolic functions (sinh, cosh, tanh, etc.)comp- Comparison functions (min, max)interest- DeFi interest calculationspool- AMM pool math (constant product)ratio- Ratio and proportion utilitiesrounding- Rounding and precision controllut- Lookup tables for fast computationdefi_precision- Precision tests for DeFi contexts
Fully qualified path: cairo_fp::f64::math
Modules
Modules
Modules
comp
Comparison Functions (f64)
Basic comparison utilities for 32.32 fixed-point numbers.
Functions
max- Returns the larger of two valuesmin- Returns the smaller of two values
Fully qualified path: cairo_fp::f64::math::comp
Free functions
Free functions
Free functions
max
Returns the maximum of two fixed-point values.
Fully qualified path: cairo_fp::f64::math::comp::max
fn max(a: Fixed, b: Fixed) -> Fixed
min
Returns the minimum of two fixed-point values.
Fully qualified path: cairo_fp::f64::math::comp::min
fn min(a: Fixed, b: Fixed) -> Fixed
defi_precision
DeFi Precision Tests (f64)
Precision validation tests for 32.32 fixed-point power and exponential functions.
Test Coverage
- Rates: 0.01% to 500% (0.0001 to 5.0) - Values: Small (1e-4) to Large (1e4)
Gas Benchmarks
Approximate L2 gas costs for f64 (32.32 fixed-point):
| Function | Typical Gas | Notes |
|---|---|---|
| exp() | ~97,000 | General exponential |
| exp2() | ~14,000 | Fast for integer exponents |
| ln() | ~51,000 | Natural logarithm |
| log2() | ~84,000 | Base-2 logarithm |
| log10() | ~87,000 | Base-10 logarithm |
| pow() | ~54,000 | Compound interest (int) |
| pow() | ~118,000 | Fractional exponent |
| sqrt() | ~39,000 | Square root |
| cbrt() | ~107,000 | Cube root (1.0 input) |
| cbrt() | ~172,000 | Cube root (general case) |
This module contains tests only - no runtime functions are exported.
Fully qualified path: cairo_fp::f64::math::defi_precision
hyp
Hyperbolic Functions (f64)
Hyperbolic trigonometric functions for 32.32 fixed-point numbers.
Functions
sinh/cosh/tanh- Hyperbolic functionsasinh/acosh/atanh- Inverse hyperbolic functions
Formulas
- sinh(x) = (e^x - e^-x) / 2
- cosh(x) = (e^x + e^-x) / 2
- tanh(x) = sinh(x) / cosh(x)
Fully qualified path: cairo_fp::f64::math::hyp
Free functions
| cosh | Calculates hyperbolic cosine: cosh(a) = (e^a + e^-a) / 2 |
| sinh | Calculates hyperbolic sine: sinh(a) = (e^a - e^-a) / 2 |
| tanh | Calculates hyperbolic tangent: tanh(a) = sinh(a) / cosh(a) |
| acosh | Calculates inverse hyperbolic cosine: acosh(a) = ln(a + sqrt(a² - 1)) Requires a ≥ 1. |
| asinh | Calculates inverse hyperbolic sine: asinh(a) = ln(a + sqrt(a² + 1)) |
| atanh | Calculates inverse hyperbolic tangent: atanh(a) = ln((1+a)/(1-a)) / 2 Requires -1 < a < 1. |
Free functions
Free functions
| cosh | Calculates hyperbolic cosine: cosh(a) = (e^a + e^-a) / 2 |
| sinh | Calculates hyperbolic sine: sinh(a) = (e^a - e^-a) / 2 |
| tanh | Calculates hyperbolic tangent: tanh(a) = sinh(a) / cosh(a) |
| acosh | Calculates inverse hyperbolic cosine: acosh(a) = ln(a + sqrt(a² - 1)) Requires a ≥ 1. |
| asinh | Calculates inverse hyperbolic sine: asinh(a) = ln(a + sqrt(a² + 1)) |
| atanh | Calculates inverse hyperbolic tangent: atanh(a) = ln((1+a)/(1-a)) / 2 Requires -1 < a < 1. |
cosh
Calculates hyperbolic cosine: cosh(a) = (e^a + e^-a) / 2
Fully qualified path: cairo_fp::f64::math::hyp::cosh
fn cosh(a: Fixed) -> Fixed
sinh
Calculates hyperbolic sine: sinh(a) = (e^a - e^-a) / 2
Fully qualified path: cairo_fp::f64::math::hyp::sinh
fn sinh(a: Fixed) -> Fixed
tanh
Calculates hyperbolic tangent: tanh(a) = sinh(a) / cosh(a)
Fully qualified path: cairo_fp::f64::math::hyp::tanh
fn tanh(a: Fixed) -> Fixed
acosh
Calculates inverse hyperbolic cosine: acosh(a) = ln(a + sqrt(a² - 1))
Requires a ≥ 1.
Fully qualified path: cairo_fp::f64::math::hyp::acosh
fn acosh(a: Fixed) -> Fixed
asinh
Calculates inverse hyperbolic sine: asinh(a) = ln(a + sqrt(a² + 1))
Fully qualified path: cairo_fp::f64::math::hyp::asinh
fn asinh(a: Fixed) -> Fixed
atanh
Calculates inverse hyperbolic tangent: atanh(a) = ln((1+a)/(1-a)) / 2
Requires -1 < a < 1.
Fully qualified path: cairo_fp::f64::math::hyp::atanh
fn atanh(a: Fixed) -> Fixed
interest
Interest & Time-Based Calculations (f64)
Financial mathematics for DeFi applications using 32.32 fixed-point. Gas-optimized versions of the f128 interest functions.
Interpolation
linear_interpolate- Linear interpolation between two values
Growth & Decay
exponential_growth- Calculate growth with compoundingdecay- Calculate exponential decay
Interest Calculations
simple_interest- Simple interest: P × (1 + rt)compound- Compound interest: P × (1 + r/n)^(nt)continuous_compound- Continuous compounding: P × e^(rt)
Financial Utilities
present_value- Discount future value to presenteffective_annual_rate- Convert nominal to effective rate
Fully qualified path: cairo_fp::f64::math::interest
Free functions
| linear_interpolate | Linear interpolation between start and end. Returns start + (end - start) × t for 0 ≤ t ≤ 1. |
| exponential_growth | Calculates exponential growth: initial × (1 + rate)^periods. |
| decay | Calculates exponential decay: initial × (1 - rate)^periods. Requires rate < 1 for meaningful results. |
| compound | Calculates compound interest. Formula: principal × (1 + rate/n)^(n×t)… |
| simple_interest | Calculates simple interest: principal × (1 + rate × time). |
| continuous_compound | Calculates continuously compounded interest: principal × e^(rate × time). |
| present_value | Calculates present value from future value. Formula: FV / (1 + rate)^periods |
| effective_annual_rate | Calculates effective annual rate from nominal rate. Formula: (1 + r/n)^n - 1 |
Free functions
Free functions
| linear_interpolate | Linear interpolation between start and end. Returns start + (end - start) × t for 0 ≤ t ≤ 1. |
| exponential_growth | Calculates exponential growth: initial × (1 + rate)^periods. |
| decay | Calculates exponential decay: initial × (1 - rate)^periods. Requires rate < 1 for meaningful results. |
| compound | Calculates compound interest. Formula: principal × (1 + rate/n)^(n×t)… |
| simple_interest | Calculates simple interest: principal × (1 + rate × time). |
| continuous_compound | Calculates continuously compounded interest: principal × e^(rate × time). |
| present_value | Calculates present value from future value. Formula: FV / (1 + rate)^periods |
| effective_annual_rate | Calculates effective annual rate from nominal rate. Formula: (1 + r/n)^n - 1 |
linear_interpolate
Linear interpolation between start and end.
Returns start + (end - start) × t for 0 ≤ t ≤ 1.
Fully qualified path: cairo_fp::f64::math::interest::linear_interpolate
fn linear_interpolate(start: Fixed, end: Fixed, t: Fixed) -> Fixed
exponential_growth
Calculates exponential growth: initial × (1 + rate)^periods.
Fully qualified path: cairo_fp::f64::math::interest::exponential_growth
fn exponential_growth(initial: Fixed, rate: Fixed, periods: Fixed) -> Fixed
decay
Calculates exponential decay: initial × (1 - rate)^periods.
Requires rate < 1 for meaningful results.
Fully qualified path: cairo_fp::f64::math::interest::decay
fn decay(initial: Fixed, rate: Fixed, periods: Fixed) -> Fixed
compound
Calculates compound interest.
Formula: principal × (1 + rate/n)^(n×t)
Arguments
principal- Initial amountrate- Annual interest raten- Compounding frequency per periodt- Number of periods
Fully qualified path: cairo_fp::f64::math::interest::compound
fn compound(principal: Fixed, rate: Fixed, n: Fixed, t: Fixed) -> Fixed
simple_interest
Calculates simple interest: principal × (1 + rate × time).
Fully qualified path: cairo_fp::f64::math::interest::simple_interest
fn simple_interest(principal: Fixed, rate: Fixed, time: Fixed) -> Fixed
continuous_compound
Calculates continuously compounded interest: principal × e^(rate × time).
Fully qualified path: cairo_fp::f64::math::interest::continuous_compound
fn continuous_compound(principal: Fixed, rate: Fixed, time: Fixed) -> Fixed
present_value
Calculates present value from future value.
Formula: FV / (1 + rate)^periods
Fully qualified path: cairo_fp::f64::math::interest::present_value
fn present_value(future_value: Fixed, rate: Fixed, periods: Fixed) -> Fixed
effective_annual_rate
Calculates effective annual rate from nominal rate.
Formula: (1 + r/n)^n - 1
Fully qualified path: cairo_fp::f64::math::interest::effective_annual_rate
fn effective_annual_rate(nominal_rate: Fixed, compounds_per_year: Fixed) -> Fixed
lut
Lookup Tables (f64)
Precomputed lookup tables for fast 32.32 fixed-point operations. Uses binary search through hardcoded values for gas efficiency.
Functions
msb- Most significant bit position and power of 2exp2- Powers of 2 for exponents 0-32sin- Sine interpolation dataatan- Arctangent interpolation data
Fully qualified path: cairo_fp::f64::math::lut
Free functions
| msb | Calculates the most significant bit position. Returns (bit_position, 2^bit_position) for the input value. |
| exp2 | — |
| sin | — |
| atan | — |
Free functions
Free functions
| msb | Calculates the most significant bit position. Returns (bit_position, 2^bit_position) for the input value. |
| exp2 | — |
| sin | — |
| atan | — |
msb
Calculates the most significant bit position.
Returns (bit_position, 2^bit_position) for the input value.
Fully qualified path: cairo_fp::f64::math::lut::msb
fn msb(whole: u64) -> (u64, u64)
exp2
Fully qualified path: cairo_fp::f64::math::lut::exp2
fn exp2(exp: u64) -> u64
sin
Fully qualified path: cairo_fp::f64::math::lut::sin
fn sin(a: u64) -> (u64, u64, u64)
atan
Fully qualified path: cairo_fp::f64::math::lut::atan
fn atan(a: u64) -> (u64, u64, u64)
ops
Core Mathematical Operations (f64)
Basic arithmetic and mathematical functions for 32.32 fixed-point numbers. These are the gas-optimized versions using 64-bit arithmetic.
Arithmetic
abs- Absolute valueadd- Additiondiv- Divisionmul- Multiplication (via operator overloading)neg- Negationsub- Subtraction
Rounding
ceil- Round upfloor- Round downround- Round to nearest
Exponential & Logarithmic
exp- Natural exponential (e^x)exp2- Binary exponential (2^x)ln- Natural logarithmlog2- Binary logarithmlog10- Common logarithmpow- Power function
Roots
sqrt- Square root
Fully qualified path: cairo_fp::f64::math::ops
Free functions
| abs | Returns the absolute value of a fixed-point number. |
| add | — |
| ceil | — |
| div | — |
| eq | — |
| exp | — |
| exp2 | — |
| exp2_int | — |
| floor | — |
| ge | — |
| gt | — |
| le | — |
| ln | — |
| log2 | — |
| log10 | — |
| lt | — |
| mul | — |
| ne | — |
| neg | — |
| pow | — |
| pow_int | — |
| rem | — |
| round | — |
| sqrt | — |
| cbrt | — |
| sub | — |
Free functions
Free functions
| abs | Returns the absolute value of a fixed-point number. |
| add | — |
| ceil | — |
| div | — |
| eq | — |
| exp | — |
| exp2 | — |
| exp2_int | — |
| floor | — |
| ge | — |
| gt | — |
| le | — |
| ln | — |
| log2 | — |
| log10 | — |
| lt | — |
| mul | — |
| ne | — |
| neg | — |
| pow | — |
| pow_int | — |
| rem | — |
| round | — |
| sqrt | — |
| cbrt | — |
| sub | — |
abs
Returns the absolute value of a fixed-point number.
Fully qualified path: cairo_fp::f64::math::ops::abs
fn abs(a: Fixed) -> Fixed
add
Fully qualified path: cairo_fp::f64::math::ops::add
fn add(a: Fixed, b: Fixed) -> Fixed
ceil
Fully qualified path: cairo_fp::f64::math::ops::ceil
fn ceil(a: Fixed) -> Fixed
div
Fully qualified path: cairo_fp::f64::math::ops::div
fn div(a: Fixed, b: Fixed) -> Fixed
eq
Fully qualified path: cairo_fp::f64::math::ops::eq
fn eq(a: @Fixed, b: @Fixed) -> bool
exp
Fully qualified path: cairo_fp::f64::math::ops::exp
fn exp(a: Fixed) -> Fixed
exp2
Fully qualified path: cairo_fp::f64::math::ops::exp2
fn exp2(a: Fixed) -> Fixed
exp2_int
Fully qualified path: cairo_fp::f64::math::ops::exp2_int
fn exp2_int(exp: u64) -> Fixed
floor
Fully qualified path: cairo_fp::f64::math::ops::floor
fn floor(a: Fixed) -> Fixed
ge
Fully qualified path: cairo_fp::f64::math::ops::ge
fn ge(a: Fixed, b: Fixed) -> bool
gt
Fully qualified path: cairo_fp::f64::math::ops::gt
fn gt(a: Fixed, b: Fixed) -> bool
le
Fully qualified path: cairo_fp::f64::math::ops::le
fn le(a: Fixed, b: Fixed) -> bool
ln
Fully qualified path: cairo_fp::f64::math::ops::ln
fn ln(a: Fixed) -> Fixed
log2
Fully qualified path: cairo_fp::f64::math::ops::log2
fn log2(a: Fixed) -> Fixed
log10
Fully qualified path: cairo_fp::f64::math::ops::log10
fn log10(a: Fixed) -> Fixed
lt
Fully qualified path: cairo_fp::f64::math::ops::lt
fn lt(a: Fixed, b: Fixed) -> bool
mul
Fully qualified path: cairo_fp::f64::math::ops::mul
fn mul(a: Fixed, b: Fixed) -> Fixed
ne
Fully qualified path: cairo_fp::f64::math::ops::ne
fn ne(a: @Fixed, b: @Fixed) -> bool
neg
Fully qualified path: cairo_fp::f64::math::ops::neg
fn neg(a: Fixed) -> Fixed
pow
Fully qualified path: cairo_fp::f64::math::ops::pow
fn pow(a: Fixed, b: Fixed) -> Fixed
pow_int
Fully qualified path: cairo_fp::f64::math::ops::pow_int
fn pow_int(a: Fixed, b: u64, sign: bool) -> Fixed
rem
Fully qualified path: cairo_fp::f64::math::ops::rem
fn rem(a: Fixed, b: Fixed) -> Fixed
round
Fully qualified path: cairo_fp::f64::math::ops::round
fn round(a: Fixed) -> Fixed
sqrt
Fully qualified path: cairo_fp::f64::math::ops::sqrt
fn sqrt(a: Fixed) -> Fixed
cbrt
Fully qualified path: cairo_fp::f64::math::ops::cbrt
fn cbrt(a: Fixed) -> Fixed
sub
Fully qualified path: cairo_fp::f64::math::ops::sub
fn sub(a: Fixed, b: Fixed) -> Fixed
pool
AMM Pool Math (f64)
Constant product (x×y=k) AMM formulas for 32.32 fixed-point. Gas-optimized versions of the f128 pool functions.
Swap Functions
constant_product_out- Calculate output for given inputconstant_product_in- Calculate input for desired output
Price & Slippage
price_from_reserves- Get spot price from reservesslippage- Calculate execution slippage
Liquidity Functions
initial_lp_tokens- LP tokens for initial depositmint_lp_tokens- LP tokens for subsequent depositsliquidity_share- User’s share of reservesremove_liquidity- Amounts returned on withdrawal
Fully qualified path: cairo_fp::f64::math::pool
Free functions
| constant_product_out | Calculates output amount for a constant product swap. Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy. Formula: dy = y × dx / (x + dx) |
| constant_product_in | — |
| price_from_reserves | — |
| slippage | — |
| liquidity_share | — |
| calculate_k | — |
| initial_lp_tokens | — |
| remove_liquidity | — |
Free functions
Free functions
| constant_product_out | Calculates output amount for a constant product swap. Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy. Formula: dy = y × dx / (x + dx) |
| constant_product_in | — |
| price_from_reserves | — |
| slippage | — |
| liquidity_share | — |
| calculate_k | — |
| initial_lp_tokens | — |
| remove_liquidity | — |
constant_product_out
Calculates output amount for a constant product swap.
Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy. Formula: dy = y × dx / (x + dx)
Fully qualified path: cairo_fp::f64::math::pool::constant_product_out
fn constant_product_out(x: Fixed, y: Fixed, dx: Fixed) -> Option<Fixed>
constant_product_in
Fully qualified path: cairo_fp::f64::math::pool::constant_product_in
fn constant_product_in(x: Fixed, y: Fixed, dy: Fixed) -> Option<Fixed>
price_from_reserves
Fully qualified path: cairo_fp::f64::math::pool::price_from_reserves
fn price_from_reserves(x: Fixed, y: Fixed) -> Option<Fixed>
slippage
Fully qualified path: cairo_fp::f64::math::pool::slippage
fn slippage(expected: Fixed, actual: Fixed) -> Option<Fixed>
liquidity_share
Fully qualified path: cairo_fp::f64::math::pool::liquidity_share
fn liquidity_share(user_lp: Fixed, total_lp: Fixed, reserve: Fixed) -> Option<Fixed>
calculate_k
Fully qualified path: cairo_fp::f64::math::pool::calculate_k
fn calculate_k(x: Fixed, y: Fixed) -> Fixed
initial_lp_tokens
Fully qualified path: cairo_fp::f64::math::pool::initial_lp_tokens
fn initial_lp_tokens(x: Fixed, y: Fixed) -> Fixed
remove_liquidity
Fully qualified path: cairo_fp::f64::math::pool::remove_liquidity
fn remove_liquidity(
lp_amount: Fixed, total_lp: Fixed, reserve_x: Fixed, reserve_y: Fixed,
) -> Option<(Fixed, Fixed)>
ratio
Ratio & Proportion Calculations (f64)
Utility functions for ratio calculations using 32.32 fixed-point.
All division operations return Option<Fixed> to handle zero divisors.
Functions
proportion- Calculate part/total ratioscale_by_ratio- Multiply amount by ratioinverse_ratio- Calculate 1/ratioweighted_average- Compute weighted averagepercentage_change- Calculate % change between valuespercentage_diff- Calculate absolute % difference
Fully qualified path: cairo_fp::f64::math::ratio
Free functions
| proportion | Calculates the proportion of part to total. Returns Some(part / total) or None if total is zero. |
| scale_by_ratio | — |
| inverse_ratio | — |
| weighted_average | — |
| percentage_change | — |
| percentage_diff | — |
Free functions
Free functions
| proportion | Calculates the proportion of part to total. Returns Some(part / total) or None if total is zero. |
| scale_by_ratio | — |
| inverse_ratio | — |
| weighted_average | — |
| percentage_change | — |
| percentage_diff | — |
proportion
Calculates the proportion of part to total.
Returns Some(part / total) or None if total is zero.
Fully qualified path: cairo_fp::f64::math::ratio::proportion
fn proportion(part: Fixed, total: Fixed) -> Option<Fixed>
scale_by_ratio
Fully qualified path: cairo_fp::f64::math::ratio::scale_by_ratio
fn scale_by_ratio(amount: Fixed, ratio: Fixed) -> Fixed
inverse_ratio
Fully qualified path: cairo_fp::f64::math::ratio::inverse_ratio
fn inverse_ratio(ratio: Fixed) -> Option<Fixed>
weighted_average
Fully qualified path: cairo_fp::f64::math::ratio::weighted_average
fn weighted_average(values: Span<Fixed>, weights: Span<Fixed>) -> Option<Fixed>
percentage_change
Fully qualified path: cairo_fp::f64::math::ratio::percentage_change
fn percentage_change(old: Fixed, new: Fixed) -> Option<Fixed>
percentage_diff
Fully qualified path: cairo_fp::f64::math::ratio::percentage_diff
fn percentage_diff(a: Fixed, b: Fixed) -> Option<Fixed>
rounding
Rounding & Precision Utilities (f64)
Rounding modes and precision control for 32.32 fixed-point numbers.
Rounding Modes
round_down/round_up- Floor/Ceilinground_half_up- Standard rounding (0.5 rounds up)round_toward_zero- Truncationround_away_from_zero- Round away from zero
Comparison & Clamping
approx_equal- Check equality within toleranceclamp- Constrain value to rangemin/max- Minimum/Maximum
Fully qualified path: cairo_fp::f64::math::rounding
Free functions
| round_down | Rounds down to the nearest integer (floor). |
| round_up | Rounds up to the nearest integer (ceiling). |
| round_half_up | Standard rounding (half up): rounds to nearest, with 0.5 rounding up. |
| round_toward_zero | Rounds toward zero (truncation). Positive numbers round down, negative numbers round up. |
| round_away_from_zero | Rounds away from zero. Positive numbers round up, negative numbers round down. |
| approx_equal | Checks if two values are approximately equal within a tolerance. |
| clamp | — |
| min | — |
| max | — |
| _split_unsigned | — |
Free functions
Free functions
| round_down | Rounds down to the nearest integer (floor). |
| round_up | Rounds up to the nearest integer (ceiling). |
| round_half_up | Standard rounding (half up): rounds to nearest, with 0.5 rounding up. |
| round_toward_zero | Rounds toward zero (truncation). Positive numbers round down, negative numbers round up. |
| round_away_from_zero | Rounds away from zero. Positive numbers round up, negative numbers round down. |
| approx_equal | Checks if two values are approximately equal within a tolerance. |
| clamp | — |
| min | — |
| max | — |
| _split_unsigned | — |
round_down
Rounds down to the nearest integer (floor).
Fully qualified path: cairo_fp::f64::math::rounding::round_down
fn round_down(value: Fixed) -> Fixed
round_up
Rounds up to the nearest integer (ceiling).
Fully qualified path: cairo_fp::f64::math::rounding::round_up
fn round_up(value: Fixed) -> Fixed
round_half_up
Standard rounding (half up): rounds to nearest, with 0.5 rounding up.
Fully qualified path: cairo_fp::f64::math::rounding::round_half_up
fn round_half_up(value: Fixed) -> Fixed
round_toward_zero
Rounds toward zero (truncation).
Positive numbers round down, negative numbers round up.
Fully qualified path: cairo_fp::f64::math::rounding::round_toward_zero
fn round_toward_zero(value: Fixed) -> Fixed
round_away_from_zero
Rounds away from zero.
Positive numbers round up, negative numbers round down.
Fully qualified path: cairo_fp::f64::math::rounding::round_away_from_zero
fn round_away_from_zero(value: Fixed) -> Fixed
approx_equal
Checks if two values are approximately equal within a tolerance.
Fully qualified path: cairo_fp::f64::math::rounding::approx_equal
fn approx_equal(a: Fixed, b: Fixed, tolerance: Fixed) -> bool
clamp
Fully qualified path: cairo_fp::f64::math::rounding::clamp
fn clamp(value: Fixed, min: Fixed, max: Fixed) -> Fixed
min
Fully qualified path: cairo_fp::f64::math::rounding::min
fn min(a: Fixed, b: Fixed) -> Fixed
max
Fully qualified path: cairo_fp::f64::math::rounding::max
fn max(a: Fixed, b: Fixed) -> Fixed
_split_unsigned
Fully qualified path: cairo_fp::f64::math::rounding::_split_unsigned
fn _split_unsigned(a: Fixed) -> (u64, u64)
trig
Trigonometric Functions (f64)
Trigonometric functions for 32.32 fixed-point numbers. All angles are in radians.
Standard Functions
sin/cos/tan- Basic trig functionsasin/acos/atan- Inverse trig functions
Fast Variants
Each function has a _fast variant that trades precision for gas savings.
Use these when approximate results are acceptable.
Constants
PI≈ 3.14159… (13493037705 in 32.32 format)HALF_PI≈ 1.57079…TWO_PI≈ 6.28318…
Fully qualified path: cairo_fp::f64::math::trig
Constants
| TWO_PI | 2π in 32.32 fixed-point format. |
| PI | π in 32.32 fixed-point format. |
| HALF_PI | π/2 in 32.32 fixed-point format. |
Free functions
| acos | Calculates arccosine for -1 ≤ a ≤ 1. Uses the identity: arccos(a) = arcsin(sqrt(1 - a²)) |
| acos_fast | — |
| asin | — |
| asin_fast | — |
| atan | — |
| atan_fast | — |
| cos | — |
| cos_fast | — |
| sin | — |
| sin_fast | — |
| tan | — |
| tan_fast | — |
| _sin_loop | — |
Constants
Constants
| TWO_PI | 2π in 32.32 fixed-point format. |
| PI | π in 32.32 fixed-point format. |
| HALF_PI | π/2 in 32.32 fixed-point format. |
TWO_PI
2π in 32.32 fixed-point format.
Fully qualified path: cairo_fp::f64::math::trig::TWO_PI
const TWO_PI: u64 = 26986075409;
PI
π in 32.32 fixed-point format.
Fully qualified path: cairo_fp::f64::math::trig::PI
const PI: u64 = 13493037705;
HALF_PI
π/2 in 32.32 fixed-point format.
Fully qualified path: cairo_fp::f64::math::trig::HALF_PI
const HALF_PI: u64 = 6746518852;
Free functions
Free functions
| acos | Calculates arccosine for -1 ≤ a ≤ 1. Uses the identity: arccos(a) = arcsin(sqrt(1 - a²)) |
| acos_fast | — |
| asin | — |
| asin_fast | — |
| atan | — |
| atan_fast | — |
| cos | — |
| cos_fast | — |
| sin | — |
| sin_fast | — |
| tan | — |
| tan_fast | — |
| _sin_loop | — |
acos
Calculates arccosine for -1 ≤ a ≤ 1.
Uses the identity: arccos(a) = arcsin(sqrt(1 - a²))
Fully qualified path: cairo_fp::f64::math::trig::acos
fn acos(a: Fixed) -> Fixed
acos_fast
Fully qualified path: cairo_fp::f64::math::trig::acos_fast
fn acos_fast(a: Fixed) -> Fixed
asin
Fully qualified path: cairo_fp::f64::math::trig::asin
fn asin(a: Fixed) -> Fixed
asin_fast
Fully qualified path: cairo_fp::f64::math::trig::asin_fast
fn asin_fast(a: Fixed) -> Fixed
atan
Fully qualified path: cairo_fp::f64::math::trig::atan
fn atan(a: Fixed) -> Fixed
atan_fast
Fully qualified path: cairo_fp::f64::math::trig::atan_fast
fn atan_fast(a: Fixed) -> Fixed
cos
Fully qualified path: cairo_fp::f64::math::trig::cos
fn cos(a: Fixed) -> Fixed
cos_fast
Fully qualified path: cairo_fp::f64::math::trig::cos_fast
fn cos_fast(a: Fixed) -> Fixed
sin
Fully qualified path: cairo_fp::f64::math::trig::sin
fn sin(a: Fixed) -> Fixed
sin_fast
Fully qualified path: cairo_fp::f64::math::trig::sin_fast
fn sin_fast(a: Fixed) -> Fixed
tan
Fully qualified path: cairo_fp::f64::math::trig::tan
fn tan(a: Fixed) -> Fixed
tan_fast
Fully qualified path: cairo_fp::f64::math::trig::tan_fast
fn tan_fast(a: Fixed) -> Fixed
_sin_loop
Fully qualified path: cairo_fp::f64::math::trig::_sin_loop
fn _sin_loop(a: Fixed, i: u64, acc: Fixed) -> Fixed
procgen
Procedural Generation (f64)
Utilities for procedural content generation using 32.32 fixed-point.
Modules
Fully qualified path: cairo_fp::f64::procgen
Modules
Modules
Modules
rand
Random Number Generation (f64)
Pseudo-random number generation utilities using 32.32 fixed-point.
Functions
derive- Derive a new seed from an existing seed and entropyfixed_between- Random fixed-point in range [low, high)u64_between- Random u64 in range [low, high)fixed_normal_between- Normally distributed random (approximation)u64_normal_between- Normally distributed u64 (approximation)
Note
These are deterministic pseudo-random generators suitable for games and simulations, not for cryptographic purposes.
Fully qualified path: cairo_fp::f64::procgen::rand
Free functions
| derive | Derives a new seed by hashing the current seed with entropy. |
| fixed_between | Returns a pseudo-random fixed-point value in range [ low, high). The value is deterministic based on the seed. |
| u64_between | — |
| fixed_normal_between | — |
| u64_normal_between | — |
| _fixed_normal_between_loop | — |
Free functions
Free functions
| derive | Derives a new seed by hashing the current seed with entropy. |
| fixed_between | Returns a pseudo-random fixed-point value in range [ low, high). The value is deterministic based on the seed. |
| u64_between | — |
| fixed_normal_between | — |
| u64_normal_between | — |
| _fixed_normal_between_loop | — |
derive
Derives a new seed by hashing the current seed with entropy.
Fully qualified path: cairo_fp::f64::procgen::rand::derive
fn derive(seed: felt252, entropy: felt252) -> felt252
fixed_between
Returns a pseudo-random fixed-point value in range [low, high).
The value is deterministic based on the seed.
Fully qualified path: cairo_fp::f64::procgen::rand::fixed_between
fn fixed_between(seed: felt252, low: Fixed, high: Fixed) -> Fixed
u64_between
Fully qualified path: cairo_fp::f64::procgen::rand::u64_between
fn u64_between(seed: felt252, low: u64, high: u64) -> u64
fixed_normal_between
Fully qualified path: cairo_fp::f64::procgen::rand::fixed_normal_between
fn fixed_normal_between(seed: felt252, low: Fixed, high: Fixed) -> Fixed
u64_normal_between
Fully qualified path: cairo_fp::f64::procgen::rand::u64_normal_between
fn u64_normal_between(seed: felt252, low: u64, high: u64) -> u64
_fixed_normal_between_loop
Fully qualified path: cairo_fp::f64::procgen::rand::_fixed_normal_between_loop
fn _fixed_normal_between_loop(
seed: felt252, low: Fixed, high: Fixed, acc: Fixed, iter: felt252,
) -> Fixed
simplex3
3D Simplex Noise (f64)
Implementation of 3D Simplex noise for procedural generation. Useful for terrain generation, textures, and other game/graphics applications.
Main Function
noise- Generate noise value for a 3D point
Output Range
Returns values in the range -1, 1.
Fully qualified path: cairo_fp::f64::procgen::simplex3
Free functions
| permute | Permutation function for noise generation. |
| taylor_inv_sqrt | — |
| step | — |
| noise | — |
| noise_octaves | — |
Free functions
Free functions
| permute | Permutation function for noise generation. |
| taylor_inv_sqrt | — |
| step | — |
| noise | — |
| noise_octaves | — |
permute
Permutation function for noise generation.
Fully qualified path: cairo_fp::f64::procgen::simplex3::permute
fn permute(x: Vec4) -> Vec4
taylor_inv_sqrt
Fully qualified path: cairo_fp::f64::procgen::simplex3::taylor_inv_sqrt
fn taylor_inv_sqrt(r: Vec4) -> Vec4
step
Fully qualified path: cairo_fp::f64::procgen::simplex3::step
fn step(edge: Fixed, x: Fixed) -> Fixed
noise
Fully qualified path: cairo_fp::f64::procgen::simplex3::noise
fn noise(v: Vec3) -> Fixed
noise_octaves
Fully qualified path: cairo_fp::f64::procgen::simplex3::noise_octaves
fn noise_octaves(v: Vec3, mut octaves: u64, persistence: Fixed) -> Fixed
test
Test Utilities (f64)
Testing helpers for 32.32 fixed-point numbers.
Fully qualified path: cairo_fp::f64::test
Modules
Modules
Modules
helpers
Test Assertion Helpers (f64)
Precision assertion utilities for testing 32.32 fixed-point operations.
Functions
assert_precise- Assert absolute precision within toleranceassert_relative- Assert relative precision within tolerance
Default Precision
The default precision is 430 (approximately 1e-7 in 32.32 format).
Fully qualified path: cairo_fp::f64::test::helpers
Constants
| DEFAULT_PRECISION | Default precision tolerance (~1e-7). |
Free functions
| assert_precise | Asserts that a result matches an expected value within absolute precision. Use Option::None for default precision, or Option::Some(value) for custom. |
| assert_relative | — |
Constants
Constants
| DEFAULT_PRECISION | Default precision tolerance (~1e-7). |
DEFAULT_PRECISION
Default precision tolerance (~1e-7).
Fully qualified path: cairo_fp::f64::test::helpers::DEFAULT_PRECISION
const DEFAULT_PRECISION: u64 = 430;
Free functions
Free functions
| assert_precise | Asserts that a result matches an expected value within absolute precision. Use Option::None for default precision, or Option::Some(value) for custom. |
| assert_relative | — |
assert_precise
Asserts that a result matches an expected value within absolute precision.
Use Option::None for default precision, or Option::Some(value) for custom.
Fully qualified path: cairo_fp::f64::test::helpers::assert_precise
fn assert_precise(result: Fixed, expected: felt252, msg: felt252, custom_precision: Option<u64>)
assert_relative
Fully qualified path: cairo_fp::f64::test::helpers::assert_relative
fn assert_relative(result: Fixed, expected: felt252, msg: felt252, custom_precision: Option<u64>)
types
f64 Types
Core types for 32.32 fixed-point arithmetic.
Modules
fixed- TheFixedtype andFixedTraitvec2- 2D vector typevec3- 3D vector typevec4- 4D vector type
Fully qualified path: cairo_fp::f64::types
Modules
Modules
Modules
fixed
f64 Fixed-Point Type
A 32.32 fixed-point number implementation optimized for gas efficiency. Uses 64-bit storage with 32 bits for the integer part and 32 bits for the fractional part.
Format
- Total bits: 64 - Integer bits: 32 (range: ±2³¹) - Fractional bits: 32 (precision: ~2×10⁻¹⁰)
Gas Savings
Compared to f128 (64.64 format), f64 typically uses 40-60% less gas for equivalent operations due to smaller integer arithmetic.
Example
use cairo_fp::f64::types::fixed::FixedTrait;
let a = FixedTrait::new_unscaled(10, false); // 10.0
let b = FixedTrait::new(2147483648, false); // 0.5 (HALF)
let c = a * b; // 5.0
Fully qualified path: cairo_fp::f64::types::fixed
Constants
| TWO | Two in fixed-point representation (2 × 2³²). |
| ONE | One in fixed-point representation (2³²). This is the scaling factor for the 32.32 format. |
| HALF | Half in fixed-point representation (2³¹). |
| MAX_u64 | Maximum value for u64. |
Structs
| Fixed | A signed 32.32 fixed-point number. The magnitude is stored as a u64 where the upper 32 bits represent the integer part and the lower 32 bits represent the fractional part…. |
Traits
| FixedTrait | Core trait for f64 fixed-point operations. Provides constructors, mathematical operations, trigonometric functions, and hyperbolic functions for the Fixed type. |
Impls
Constants
Constants
| TWO | Two in fixed-point representation (2 × 2³²). |
| ONE | One in fixed-point representation (2³²). This is the scaling factor for the 32.32 format. |
| HALF | Half in fixed-point representation (2³¹). |
| MAX_u64 | Maximum value for u64. |
TWO
Two in fixed-point representation (2 × 2³²).
Fully qualified path: cairo_fp::f64::types::fixed::TWO
const TWO: u64 = 8589934592;
ONE
One in fixed-point representation (2³²). This is the scaling factor for the 32.32 format.
Fully qualified path: cairo_fp::f64::types::fixed::ONE
const ONE: u64 = 4294967296;
HALF
Half in fixed-point representation (2³¹).
Fully qualified path: cairo_fp::f64::types::fixed::HALF
const HALF: u64 = 2147483648;
MAX_u64
Maximum value for u64.
Fully qualified path: cairo_fp::f64::types::fixed::MAX_u64
const MAX_u64: u128 = 18446744073709551615;
Structs
Structs
| Fixed | A signed 32.32 fixed-point number. The magnitude is stored as a u64 where the upper 32 bits represent the integer part and the lower 32 bits represent the fractional part…. |
Fixed
A signed 32.32 fixed-point number.
The magnitude is stored as a u64 where the upper 32 bits represent the integer part and the lower 32 bits represent the fractional part. The sign is stored separately as a boolean.
Fully qualified path: cairo_fp::f64::types::fixed::Fixed
[derive(Copy, Drop, Serde)]
struct Fixed {
mag: u64,
sign: bool,
}
Members
mag
The absolute value in 32.32 format
Fully qualified path: cairo_fp::f64::types::fixed::Fixed::mag
mag: u64
sign
Sign flag: true = negative, false = positive
Fully qualified path: cairo_fp::f64::types::fixed::Fixed::sign
sign: bool
Traits
Traits
| FixedTrait | Core trait for f64 fixed-point operations. Provides constructors, mathematical operations, trigonometric functions, and hyperbolic functions for the Fixed type. |
FixedTrait
Core trait for f64 fixed-point operations.
Provides constructors, mathematical operations, trigonometric functions, and hyperbolic functions for the Fixed type.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait
trait FixedTrait
Trait functions
ZERO
Returns zero (0.0).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::ZERO
fn ZERO() -> Fixed
ONE
Returns one (1.0).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::ONE
fn ONE() -> Fixed
new
Creates a Fixed from a raw magnitude and sign.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::new
fn new(mag: u64, sign: bool) -> Fixed
new_unscaled
Creates a Fixed from an unscaled integer.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::new_unscaled
fn new_unscaled(mag: u64, sign: bool) -> Fixed
from_felt
Creates a Fixed from a felt252 (scaled value).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::from_felt
fn from_felt(val: felt252) -> Fixed
from_unscaled_felt
Creates a Fixed from an unscaled felt252.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::from_unscaled_felt
fn from_unscaled_felt(val: felt252) -> Fixed
abs
Absolute value.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::abs
fn abs(self: Fixed) -> Fixed
ceil
Ceiling (round up).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::ceil
fn ceil(self: Fixed) -> Fixed
exp
Natural exponential (e^x).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::exp
fn exp(self: Fixed) -> Fixed
exp2
Binary exponential (2^x).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::exp2
fn exp2(self: Fixed) -> Fixed
floor
Floor (round down).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::floor
fn floor(self: Fixed) -> Fixed
ln
Natural logarithm.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::ln
fn ln(self: Fixed) -> Fixed
log2
Base-2 logarithm.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::log2
fn log2(self: Fixed) -> Fixed
log10
Base-10 logarithm.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::log10
fn log10(self: Fixed) -> Fixed
pow
Power function (self^b).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::pow
fn pow(self: Fixed, b: Fixed) -> Fixed
round
Round to nearest integer.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::round
fn round(self: Fixed) -> Fixed
sqrt
Square root.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::sqrt
fn sqrt(self: Fixed) -> Fixed
acos
Arccosine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::acos
fn acos(self: Fixed) -> Fixed
acos_fast
Arccosine (fast, lower precision).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::acos_fast
fn acos_fast(self: Fixed) -> Fixed
asin
Arcsine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::asin
fn asin(self: Fixed) -> Fixed
asin_fast
Arcsine (fast, lower precision).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::asin_fast
fn asin_fast(self: Fixed) -> Fixed
atan
Arctangent.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::atan
fn atan(self: Fixed) -> Fixed
atan_fast
Arctangent (fast, lower precision).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::atan_fast
fn atan_fast(self: Fixed) -> Fixed
cos
Cosine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::cos
fn cos(self: Fixed) -> Fixed
cos_fast
Cosine (fast, lower precision).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::cos_fast
fn cos_fast(self: Fixed) -> Fixed
sin
Sine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::sin
fn sin(self: Fixed) -> Fixed
sin_fast
Sine (fast, lower precision).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::sin_fast
fn sin_fast(self: Fixed) -> Fixed
tan
Tangent.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::tan
fn tan(self: Fixed) -> Fixed
tan_fast
Tangent (fast, lower precision).
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::tan_fast
fn tan_fast(self: Fixed) -> Fixed
acosh
Inverse hyperbolic cosine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::acosh
fn acosh(self: Fixed) -> Fixed
asinh
Inverse hyperbolic sine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::asinh
fn asinh(self: Fixed) -> Fixed
atanh
Inverse hyperbolic tangent.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::atanh
fn atanh(self: Fixed) -> Fixed
cosh
Hyperbolic cosine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::cosh
fn cosh(self: Fixed) -> Fixed
sinh
Hyperbolic sine.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::sinh
fn sinh(self: Fixed) -> Fixed
tanh
Hyperbolic tangent.
Fully qualified path: cairo_fp::f64::types::fixed::FixedTrait::tanh
fn tanh(self: Fixed) -> Fixed
Impls
Impls
FixedImpl
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl
impl FixedImpl of FixedTrait;
Impl functions
ZERO
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::ZERO
fn ZERO() -> Fixed
ONE
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::ONE
fn ONE() -> Fixed
new
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::new
fn new(mag: u64, sign: bool) -> Fixed
new_unscaled
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::new_unscaled
fn new_unscaled(mag: u64, sign: bool) -> Fixed
from_felt
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::from_felt
fn from_felt(val: felt252) -> Fixed
from_unscaled_felt
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::from_unscaled_felt
fn from_unscaled_felt(val: felt252) -> Fixed
abs
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::abs
fn abs(self: Fixed) -> Fixed
acos
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::acos
fn acos(self: Fixed) -> Fixed
acos_fast
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::acos_fast
fn acos_fast(self: Fixed) -> Fixed
acosh
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::acosh
fn acosh(self: Fixed) -> Fixed
asin
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::asin
fn asin(self: Fixed) -> Fixed
asin_fast
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::asin_fast
fn asin_fast(self: Fixed) -> Fixed
asinh
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::asinh
fn asinh(self: Fixed) -> Fixed
atan
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::atan
fn atan(self: Fixed) -> Fixed
atan_fast
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::atan_fast
fn atan_fast(self: Fixed) -> Fixed
atanh
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::atanh
fn atanh(self: Fixed) -> Fixed
ceil
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::ceil
fn ceil(self: Fixed) -> Fixed
cos
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::cos
fn cos(self: Fixed) -> Fixed
cos_fast
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::cos_fast
fn cos_fast(self: Fixed) -> Fixed
cosh
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::cosh
fn cosh(self: Fixed) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::floor
fn floor(self: Fixed) -> Fixed
exp
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::exp
fn exp(self: Fixed) -> Fixed
exp2
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::exp2
fn exp2(self: Fixed) -> Fixed
ln
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::ln
fn ln(self: Fixed) -> Fixed
log2
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::log2
fn log2(self: Fixed) -> Fixed
log10
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::log10
fn log10(self: Fixed) -> Fixed
pow
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::pow
fn pow(self: Fixed, b: Fixed) -> Fixed
round
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::round
fn round(self: Fixed) -> Fixed
sin
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::sin
fn sin(self: Fixed) -> Fixed
sin_fast
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::sin_fast
fn sin_fast(self: Fixed) -> Fixed
sinh
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::sinh
fn sinh(self: Fixed) -> Fixed
sqrt
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::sqrt
fn sqrt(self: Fixed) -> Fixed
tan
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::tan
fn tan(self: Fixed) -> Fixed
tan_fast
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::tan_fast
fn tan_fast(self: Fixed) -> Fixed
tanh
Fully qualified path: cairo_fp::f64::types::fixed::FixedImpl::tanh
fn tanh(self: Fixed) -> Fixed
FixedPrint
Fully qualified path: cairo_fp::f64::types::fixed::FixedPrint
impl FixedPrint of PrintTrait<Fixed>;
Impl functions
Fully qualified path: cairo_fp::f64::types::fixed::FixedPrint::print
fn print(self: Fixed)
Fixed64IntoFixed128
Fully qualified path: cairo_fp::f64::types::fixed::Fixed64IntoFixed128
impl Fixed64IntoFixed128 of Into<Fixed, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::Fixed64IntoFixed128::into
fn into(self: Fixed) -> Fixed
FixedIntoFelt252
Fully qualified path: cairo_fp::f64::types::fixed::FixedIntoFelt252
impl FixedIntoFelt252 of Into<Fixed, felt252>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::FixedIntoFelt252::into
fn into(self: Fixed) -> felt252
FixedTryIntoU128
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU128
impl FixedTryIntoU128 of TryInto<Fixed, u128>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU128::try_into
fn try_into(self: Fixed) -> Option<u128>
FixedTryIntoU64
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU64
impl FixedTryIntoU64 of TryInto<Fixed, u64>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU64::try_into
fn try_into(self: Fixed) -> Option<u64>
FixedTryIntoU32
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU32
impl FixedTryIntoU32 of TryInto<Fixed, u32>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU32::try_into
fn try_into(self: Fixed) -> Option<u32>
FixedTryIntoU16
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU16
impl FixedTryIntoU16 of TryInto<Fixed, u16>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU16::try_into
fn try_into(self: Fixed) -> Option<u16>
FixedTryIntoU8
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU8
impl FixedTryIntoU8 of TryInto<Fixed, u8>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::FixedTryIntoU8::try_into
fn try_into(self: Fixed) -> Option<u8>
U8IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::U8IntoFixed
impl U8IntoFixed of Into<u8, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::U8IntoFixed::into
fn into(self: u8) -> Fixed
U16IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::U16IntoFixed
impl U16IntoFixed of Into<u16, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::U16IntoFixed::into
fn into(self: u16) -> Fixed
U32IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::U32IntoFixed
impl U32IntoFixed of Into<u32, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::U32IntoFixed::into
fn into(self: u32) -> Fixed
U64IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::U64IntoFixed
impl U64IntoFixed of Into<u64, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::U64IntoFixed::into
fn into(self: u64) -> Fixed
U128TryIntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::U128TryIntoFixed
impl U128TryIntoFixed of TryInto<u128, Fixed>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::U128TryIntoFixed::try_into
fn try_into(self: u128) -> Option<Fixed>
U256TryIntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::U256TryIntoFixed
impl U256TryIntoFixed of TryInto<u256, Fixed>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::U256TryIntoFixed::try_into
fn try_into(self: u256) -> Option<Fixed>
I8IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::I8IntoFixed
impl I8IntoFixed of Into<i8, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::I8IntoFixed::into
fn into(self: i8) -> Fixed
I16IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::I16IntoFixed
impl I16IntoFixed of Into<i16, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::I16IntoFixed::into
fn into(self: i16) -> Fixed
I32IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::I32IntoFixed
impl I32IntoFixed of Into<i32, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::I32IntoFixed::into
fn into(self: i32) -> Fixed
I64IntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::I64IntoFixed
impl I64IntoFixed of Into<i64, Fixed>;
Impl functions
into
Fully qualified path: cairo_fp::f64::types::fixed::I64IntoFixed::into
fn into(self: i64) -> Fixed
I128TryIntoFixed
Fully qualified path: cairo_fp::f64::types::fixed::I128TryIntoFixed
impl I128TryIntoFixed of TryInto<i128, Fixed>;
Impl functions
try_into
Fully qualified path: cairo_fp::f64::types::fixed::I128TryIntoFixed::try_into
fn try_into(self: i128) -> Option<Fixed>
FixedPartialEq
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialEq
impl FixedPartialEq of PartialEq<Fixed>;
Impl functions
eq
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialEq::eq
fn eq(lhs: @Fixed, rhs: @Fixed) -> bool
ne
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialEq::ne
fn ne(lhs: @Fixed, rhs: @Fixed) -> bool
FixedAdd
Fully qualified path: cairo_fp::f64::types::fixed::FixedAdd
impl FixedAdd of Add<Fixed>;
Impl functions
add
Fully qualified path: cairo_fp::f64::types::fixed::FixedAdd::add
fn add(lhs: Fixed, rhs: Fixed) -> Fixed
FixedAddAssign
Fully qualified path: cairo_fp::f64::types::fixed::FixedAddAssign
impl FixedAddAssign of AddAssign<Fixed, Fixed>;
Impl functions
add_assign
Fully qualified path: cairo_fp::f64::types::fixed::FixedAddAssign::add_assign
fn add_assign(ref self: Fixed, rhs: Fixed)
FixedSub
Fully qualified path: cairo_fp::f64::types::fixed::FixedSub
impl FixedSub of Sub<Fixed>;
Impl functions
sub
Fully qualified path: cairo_fp::f64::types::fixed::FixedSub::sub
fn sub(lhs: Fixed, rhs: Fixed) -> Fixed
FixedSubAssign
Fully qualified path: cairo_fp::f64::types::fixed::FixedSubAssign
impl FixedSubAssign of SubAssign<Fixed, Fixed>;
Impl functions
sub_assign
Fully qualified path: cairo_fp::f64::types::fixed::FixedSubAssign::sub_assign
fn sub_assign(ref self: Fixed, rhs: Fixed)
FixedMul
Fully qualified path: cairo_fp::f64::types::fixed::FixedMul
impl FixedMul of Mul<Fixed>;
Impl functions
mul
Fully qualified path: cairo_fp::f64::types::fixed::FixedMul::mul
fn mul(lhs: Fixed, rhs: Fixed) -> Fixed
FixedMulAssign
Fully qualified path: cairo_fp::f64::types::fixed::FixedMulAssign
impl FixedMulAssign of MulAssign<Fixed, Fixed>;
Impl functions
mul_assign
Fully qualified path: cairo_fp::f64::types::fixed::FixedMulAssign::mul_assign
fn mul_assign(ref self: Fixed, rhs: Fixed)
FixedDiv
Fully qualified path: cairo_fp::f64::types::fixed::FixedDiv
impl FixedDiv of Div<Fixed>;
Impl functions
div
Fully qualified path: cairo_fp::f64::types::fixed::FixedDiv::div
fn div(lhs: Fixed, rhs: Fixed) -> Fixed
FixedDivAssign
Fully qualified path: cairo_fp::f64::types::fixed::FixedDivAssign
impl FixedDivAssign of DivAssign<Fixed, Fixed>;
Impl functions
div_assign
Fully qualified path: cairo_fp::f64::types::fixed::FixedDivAssign::div_assign
fn div_assign(ref self: Fixed, rhs: Fixed)
FixedPartialOrd
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialOrd
impl FixedPartialOrd of PartialOrd<Fixed>;
Impl functions
ge
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialOrd::ge
fn ge(lhs: Fixed, rhs: Fixed) -> bool
gt
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialOrd::gt
fn gt(lhs: Fixed, rhs: Fixed) -> bool
le
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialOrd::le
fn le(lhs: Fixed, rhs: Fixed) -> bool
lt
Fully qualified path: cairo_fp::f64::types::fixed::FixedPartialOrd::lt
fn lt(lhs: Fixed, rhs: Fixed) -> bool
FixedNeg
Fully qualified path: cairo_fp::f64::types::fixed::FixedNeg
impl FixedNeg of Neg<Fixed>;
Impl functions
neg
Fully qualified path: cairo_fp::f64::types::fixed::FixedNeg::neg
fn neg(a: Fixed) -> Fixed
FixedRem
Fully qualified path: cairo_fp::f64::types::fixed::FixedRem
impl FixedRem of Rem<Fixed>;
Impl functions
rem
Fully qualified path: cairo_fp::f64::types::fixed::FixedRem::rem
fn rem(lhs: Fixed, rhs: Fixed) -> Fixed
PackFixed
Fully qualified path: cairo_fp::f64::types::fixed::PackFixed
impl PackFixed of StorePacking<Fixed, felt252>;
Impl functions
pack
Fully qualified path: cairo_fp::f64::types::fixed::PackFixed::pack
fn pack(value: Fixed) -> felt252
unpack
Fully qualified path: cairo_fp::f64::types::fixed::PackFixed::unpack
fn unpack(value: felt252) -> Fixed
FixedZero
Fully qualified path: cairo_fp::f64::types::fixed::FixedZero
impl FixedZero of Zero<Fixed>;
Impl functions
zero
Fully qualified path: cairo_fp::f64::types::fixed::FixedZero::zero
fn zero() -> Fixed
is_zero
Fully qualified path: cairo_fp::f64::types::fixed::FixedZero::is_zero
fn is_zero(self: @Fixed) -> bool
is_non_zero
Fully qualified path: cairo_fp::f64::types::fixed::FixedZero::is_non_zero
fn is_non_zero(self: @Fixed) -> bool
FixedOne
Fully qualified path: cairo_fp::f64::types::fixed::FixedOne
impl FixedOne of One<Fixed>;
Impl functions
one
Fully qualified path: cairo_fp::f64::types::fixed::FixedOne::one
fn one() -> Fixed
is_one
Fully qualified path: cairo_fp::f64::types::fixed::FixedOne::is_one
fn is_one(self: @Fixed) -> bool
is_non_one
Fully qualified path: cairo_fp::f64::types::fixed::FixedOne::is_non_one
fn is_non_one(self: @Fixed) -> bool
FixedCopy
Fully qualified path: cairo_fp::f64::types::fixed::FixedCopy
impl FixedCopy of Copy<Fixed>;
FixedDrop
Fully qualified path: cairo_fp::f64::types::fixed::FixedDrop
impl FixedDrop of Drop<Fixed>;
FixedSerde
Fully qualified path: cairo_fp::f64::types::fixed::FixedSerde
impl FixedSerde of Serde<Fixed>;
Impl functions
serialize
Fully qualified path: cairo_fp::f64::types::fixed::FixedSerde::serialize
fn serialize(self: @Fixed, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f64::types::fixed::FixedSerde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Fixed>
vec2
2D Vector Type (f64)
A 2-component vector using 32.32 fixed-point coordinates.
Operations
- Vector arithmetic: add, sub, mul, div
- Dot product and cross product (returns scalar)
- Norm (magnitude) calculation
- Component-wise abs, floor
Fully qualified path: cairo_fp::f64::types::vec2
Free functions
Structs
| Vec2 | A 2D vector with fixed-point components. |
Traits
| Vec2Trait | Trait for Vec2 operations. |
Impls
Free functions
Free functions
abs
Fully qualified path: cairo_fp::f64::types::vec2::abs
fn abs(a: Vec2) -> Vec2
add
Fully qualified path: cairo_fp::f64::types::vec2::add
fn add(a: Vec2, b: Vec2) -> Vec2
cross
Fully qualified path: cairo_fp::f64::types::vec2::cross
fn cross(a: Vec2, b: Vec2) -> Fixed
div
Fully qualified path: cairo_fp::f64::types::vec2::div
fn div(a: Vec2, b: Vec2) -> Vec2
dot
Fully qualified path: cairo_fp::f64::types::vec2::dot
fn dot(a: Vec2, b: Vec2) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::vec2::floor
fn floor(a: Vec2) -> Vec2
mul
Fully qualified path: cairo_fp::f64::types::vec2::mul
fn mul(a: Vec2, b: Vec2) -> Vec2
norm
Fully qualified path: cairo_fp::f64::types::vec2::norm
fn norm(a: Vec2) -> Fixed
rem
Fully qualified path: cairo_fp::f64::types::vec2::rem
fn rem(a: Vec2, b: Vec2) -> Vec2
sub
Fully qualified path: cairo_fp::f64::types::vec2::sub
fn sub(a: Vec2, b: Vec2) -> Vec2
Structs
Structs
| Vec2 | A 2D vector with fixed-point components. |
Vec2
A 2D vector with fixed-point components.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2
#[derive(Copy, Drop, Serde)]
struct Vec2 {
x: Fixed,
y: Fixed,
}
Members
x
Fully qualified path: cairo_fp::f64::types::vec2::Vec2::x
x: Fixed
y
Fully qualified path: cairo_fp::f64::types::vec2::Vec2::y
y: Fixed
Traits
Traits
| Vec2Trait | Trait for Vec2 operations. |
Vec2Trait
Trait for Vec2 operations.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait
trait Vec2Trait
Trait functions
new
Creates a new vector from components.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::new
fn new(x: Fixed, y: Fixed) -> Vec2
splat
Creates a vector with all components set to the same value.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::splat
fn splat(v: Fixed) -> Vec2
abs
Component-wise absolute value.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::abs
fn abs(self: Vec2) -> Vec2
cross
2D cross product (returns scalar: x1_y2 - y1_x2).
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::cross
fn cross(self: Vec2, rhs: Vec2) -> Fixed
dot
Dot product.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::dot
fn dot(self: Vec2, rhs: Vec2) -> Fixed
floor
Component-wise floor.
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::floor
fn floor(self: Vec2) -> Vec2
norm
Vector magnitude (length).
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Trait::norm
fn norm(self: Vec2) -> Fixed
Impls
Impls
Vec2Impl
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl
impl Vec2Impl of Vec2Trait;
Impl functions
new
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::new
fn new(x: Fixed, y: Fixed) -> Vec2
splat
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::splat
fn splat(v: Fixed) -> Vec2
abs
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::abs
fn abs(self: Vec2) -> Vec2
cross
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::cross
fn cross(self: Vec2, rhs: Vec2) -> Fixed
dot
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::dot
fn dot(self: Vec2, rhs: Vec2) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::floor
fn floor(self: Vec2) -> Vec2
norm
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Impl::norm
fn norm(self: Vec2) -> Fixed
Vec2Print
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Print
impl Vec2Print of PrintTrait<Vec2>;
Impl functions
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Print::print
fn print(self: Vec2)
Vec2Add
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Add
impl Vec2Add of Add<Vec2>;
Impl functions
add
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Add::add
fn add(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Div
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Div
impl Vec2Div of Div<Vec2>;
Impl functions
div
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Div::div
fn div(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Mul
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Mul
impl Vec2Mul of Mul<Vec2>;
Impl functions
mul
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Mul::mul
fn mul(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Rem
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Rem
impl Vec2Rem of Rem<Vec2>;
Impl functions
rem
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Rem::rem
fn rem(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Sub
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Sub
impl Vec2Sub of Sub<Vec2>;
Impl functions
sub
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Sub::sub
fn sub(lhs: Vec2, rhs: Vec2) -> Vec2
Vec2Copy
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Copy
impl Vec2Copy of Copy<Vec2>;
Vec2Drop
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Drop
impl Vec2Drop of Drop<Vec2>;
Vec2Serde
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Serde
impl Vec2Serde of Serde<Vec2>;
Impl functions
serialize
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Serde::serialize
fn serialize(self: @Vec2, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f64::types::vec2::Vec2Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Vec2>
vec3
3D Vector Type (f64)
A 3-component vector using 32.32 fixed-point coordinates.
Operations
- Vector arithmetic: add, sub, mul, div
- Dot product and cross product (returns Vec3)
- Norm (magnitude) calculation
- Component-wise abs, floor
- Scalar operations
Fully qualified path: cairo_fp::f64::types::vec3
Free functions
Structs
| Vec3 | A 3D vector with fixed-point components. |
Traits
| Vec3Trait | Trait for Vec3 operations. |
Impls
Free functions
Free functions
abs
Fully qualified path: cairo_fp::f64::types::vec3::abs
fn abs(a: Vec3) -> Vec3
add
Fully qualified path: cairo_fp::f64::types::vec3::add
fn add(a: Vec3, b: Vec3) -> Vec3
cross
Fully qualified path: cairo_fp::f64::types::vec3::cross
fn cross(a: Vec3, b: Vec3) -> Vec3
div
Fully qualified path: cairo_fp::f64::types::vec3::div
fn div(a: Vec3, b: Vec3) -> Vec3
dot
Fully qualified path: cairo_fp::f64::types::vec3::dot
fn dot(a: Vec3, b: Vec3) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::vec3::floor
fn floor(a: Vec3) -> Vec3
mul
Fully qualified path: cairo_fp::f64::types::vec3::mul
fn mul(a: Vec3, b: Vec3) -> Vec3
norm
Fully qualified path: cairo_fp::f64::types::vec3::norm
fn norm(a: Vec3) -> Fixed
rem
Fully qualified path: cairo_fp::f64::types::vec3::rem
fn rem(a: Vec3, b: Vec3) -> Vec3
sub
Fully qualified path: cairo_fp::f64::types::vec3::sub
fn sub(a: Vec3, b: Vec3) -> Vec3
Structs
Structs
| Vec3 | A 3D vector with fixed-point components. |
Vec3
A 3D vector with fixed-point components.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3
#[derive(Copy, Drop, Serde)]
struct Vec3 {
x: Fixed,
y: Fixed,
z: Fixed,
}
Members
x
Fully qualified path: cairo_fp::f64::types::vec3::Vec3::x
x: Fixed
y
Fully qualified path: cairo_fp::f64::types::vec3::Vec3::y
y: Fixed
z
Fully qualified path: cairo_fp::f64::types::vec3::Vec3::z
z: Fixed
Traits
Traits
| Vec3Trait | Trait for Vec3 operations. |
Vec3Trait
Trait for Vec3 operations.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait
trait Vec3Trait
Trait functions
new
Creates a new vector from components.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::new
fn new(x: Fixed, y: Fixed, z: Fixed) -> Vec3
splat
Creates a vector with all components set to the same value.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::splat
fn splat(v: Fixed) -> Vec3
abs
Component-wise absolute value.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::abs
fn abs(self: Vec3) -> Vec3
cross
3D cross product (returns Vec3).
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::cross
fn cross(self: Vec3, rhs: Vec3) -> Vec3
dot
Dot product.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::dot
fn dot(self: Vec3, rhs: Vec3) -> Fixed
floor
Component-wise floor.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::floor
fn floor(self: Vec3) -> Vec3
norm
Vector magnitude (length).
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::norm
fn norm(self: Vec3) -> Fixed
add
Add scalar to all components.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::add
fn add(self: Vec3, scalar: Fixed) -> Vec3
sub
Subtract scalar from all components.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::sub
fn sub(self: Vec3, scalar: Fixed) -> Vec3
mul
Multiply all components by scalar.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::mul
fn mul(self: Vec3, scalar: Fixed) -> Vec3
div
Divide all components by scalar.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::div
fn div(self: Vec3, scalar: Fixed) -> Vec3
rem
Remainder of all components divided by scalar.
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Trait::rem
fn rem(self: Vec3, scalar: Fixed) -> Vec3
Impls
Impls
Vec3Impl
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl
impl Vec3Impl of Vec3Trait;
Impl functions
new
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::new
fn new(x: Fixed, y: Fixed, z: Fixed) -> Vec3
splat
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::splat
fn splat(v: Fixed) -> Vec3
abs
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::abs
fn abs(self: Vec3) -> Vec3
cross
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::cross
fn cross(self: Vec3, rhs: Vec3) -> Vec3
dot
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::dot
fn dot(self: Vec3, rhs: Vec3) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::floor
fn floor(self: Vec3) -> Vec3
norm
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::norm
fn norm(self: Vec3) -> Fixed
add
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::add
fn add(self: Vec3, scalar: Fixed) -> Vec3
sub
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::sub
fn sub(self: Vec3, scalar: Fixed) -> Vec3
mul
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::mul
fn mul(self: Vec3, scalar: Fixed) -> Vec3
div
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::div
fn div(self: Vec3, scalar: Fixed) -> Vec3
rem
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Impl::rem
fn rem(self: Vec3, scalar: Fixed) -> Vec3
Vec3Print
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Print
impl Vec3Print of PrintTrait<Vec3>;
Impl functions
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Print::print
fn print(self: Vec3)
Vec3Add
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Add
impl Vec3Add of Add<Vec3>;
Impl functions
add
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Add::add
fn add(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Div
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Div
impl Vec3Div of Div<Vec3>;
Impl functions
div
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Div::div
fn div(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Mul
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Mul
impl Vec3Mul of Mul<Vec3>;
Impl functions
mul
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Mul::mul
fn mul(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Rem
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Rem
impl Vec3Rem of Rem<Vec3>;
Impl functions
rem
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Rem::rem
fn rem(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Sub
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Sub
impl Vec3Sub of Sub<Vec3>;
Impl functions
sub
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Sub::sub
fn sub(lhs: Vec3, rhs: Vec3) -> Vec3
Vec3Copy
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Copy
impl Vec3Copy of Copy<Vec3>;
Vec3Drop
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Drop
impl Vec3Drop of Drop<Vec3>;
Vec3Serde
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Serde
impl Vec3Serde of Serde<Vec3>;
Impl functions
serialize
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Serde::serialize
fn serialize(self: @Vec3, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f64::types::vec3::Vec3Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Vec3>
vec4
4D Vector Type (f64)
A 4-component vector using 32.32 fixed-point coordinates. Useful for homogeneous coordinates and SIMD-style operations.
Operations
- Vector arithmetic: add, sub, mul, div
- Dot product
- Norm (magnitude) calculation
- Component-wise abs, floor
- Scalar operations
Fully qualified path: cairo_fp::f64::types::vec4
Free functions
Structs
| Vec4 | A 4D vector with fixed-point components. |
Traits
| Vec4Trait | Trait for Vec4 operations. |
Impls
Free functions
Free functions
abs
Fully qualified path: cairo_fp::f64::types::vec4::abs
fn abs(a: Vec4) -> Vec4
add
Fully qualified path: cairo_fp::f64::types::vec4::add
fn add(a: Vec4, b: Vec4) -> Vec4
div
Fully qualified path: cairo_fp::f64::types::vec4::div
fn div(a: Vec4, b: Vec4) -> Vec4
dot
Fully qualified path: cairo_fp::f64::types::vec4::dot
fn dot(a: Vec4, b: Vec4) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::vec4::floor
fn floor(a: Vec4) -> Vec4
mul
Fully qualified path: cairo_fp::f64::types::vec4::mul
fn mul(a: Vec4, b: Vec4) -> Vec4
norm
Fully qualified path: cairo_fp::f64::types::vec4::norm
fn norm(a: Vec4) -> Fixed
rem
Fully qualified path: cairo_fp::f64::types::vec4::rem
fn rem(a: Vec4, b: Vec4) -> Vec4
sub
Fully qualified path: cairo_fp::f64::types::vec4::sub
fn sub(a: Vec4, b: Vec4) -> Vec4
Structs
Structs
| Vec4 | A 4D vector with fixed-point components. |
Vec4
A 4D vector with fixed-point components.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4
#[derive(Copy, Drop, Serde)]
struct Vec4 {
x: Fixed,
y: Fixed,
z: Fixed,
w: Fixed,
}
Members
x
Fully qualified path: cairo_fp::f64::types::vec4::Vec4::x
x: Fixed
y
Fully qualified path: cairo_fp::f64::types::vec4::Vec4::y
y: Fixed
z
Fully qualified path: cairo_fp::f64::types::vec4::Vec4::z
z: Fixed
w
Fully qualified path: cairo_fp::f64::types::vec4::Vec4::w
w: Fixed
Traits
Traits
| Vec4Trait | Trait for Vec4 operations. |
Vec4Trait
Trait for Vec4 operations.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait
trait Vec4Trait
Trait functions
new
Creates a new vector from components.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::new
fn new(x: Fixed, y: Fixed, z: Fixed, w: Fixed) -> Vec4
splat
Creates a vector with all components set to the same value.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::splat
fn splat(v: Fixed) -> Vec4
abs
Component-wise absolute value.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::abs
fn abs(self: Vec4) -> Vec4
dot
Dot product.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::dot
fn dot(self: Vec4, rhs: Vec4) -> Fixed
floor
Component-wise floor.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::floor
fn floor(self: Vec4) -> Vec4
norm
Vector magnitude (length).
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::norm
fn norm(self: Vec4) -> Fixed
add
Add scalar to all components.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::add
fn add(self: Vec4, scalar: Fixed) -> Vec4
sub
Subtract scalar from all components.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::sub
fn sub(self: Vec4, scalar: Fixed) -> Vec4
mul
Multiply all components by scalar.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::mul
fn mul(self: Vec4, scalar: Fixed) -> Vec4
div
Divide all components by scalar.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::div
fn div(self: Vec4, scalar: Fixed) -> Vec4
rem
Remainder of all components divided by scalar.
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Trait::rem
fn rem(self: Vec4, scalar: Fixed) -> Vec4
Impls
Impls
Vec4Impl
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl
impl Vec4Impl of Vec4Trait;
Impl functions
new
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::new
fn new(x: Fixed, y: Fixed, z: Fixed, w: Fixed) -> Vec4
splat
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::splat
fn splat(v: Fixed) -> Vec4
abs
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::abs
fn abs(self: Vec4) -> Vec4
dot
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::dot
fn dot(self: Vec4, rhs: Vec4) -> Fixed
floor
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::floor
fn floor(self: Vec4) -> Vec4
norm
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::norm
fn norm(self: Vec4) -> Fixed
add
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::add
fn add(self: Vec4, scalar: Fixed) -> Vec4
sub
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::sub
fn sub(self: Vec4, scalar: Fixed) -> Vec4
mul
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::mul
fn mul(self: Vec4, scalar: Fixed) -> Vec4
div
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::div
fn div(self: Vec4, scalar: Fixed) -> Vec4
rem
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Impl::rem
fn rem(self: Vec4, scalar: Fixed) -> Vec4
Vec4Print
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Print
impl Vec4Print of PrintTrait<Vec4>;
Impl functions
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Print::print
fn print(self: Vec4)
Vec4Add
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Add
impl Vec4Add of Add<Vec4>;
Impl functions
add
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Add::add
fn add(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Div
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Div
impl Vec4Div of Div<Vec4>;
Impl functions
div
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Div::div
fn div(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Mul
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Mul
impl Vec4Mul of Mul<Vec4>;
Impl functions
mul
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Mul::mul
fn mul(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Rem
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Rem
impl Vec4Rem of Rem<Vec4>;
Impl functions
rem
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Rem::rem
fn rem(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Sub
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Sub
impl Vec4Sub of Sub<Vec4>;
Impl functions
sub
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Sub::sub
fn sub(lhs: Vec4, rhs: Vec4) -> Vec4
Vec4Copy
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Copy
impl Vec4Copy of Copy<Vec4>;
Vec4Drop
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Drop
impl Vec4Drop of Drop<Vec4>;
Vec4Serde
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Serde
impl Vec4Serde of Serde<Vec4>;
Impl functions
serialize
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Serde::serialize
fn serialize(self: @Vec4, ref output: Array<felt252>)
deserialize
Fully qualified path: cairo_fp::f64::types::vec4::Vec4Serde::deserialize
fn deserialize(ref serialized: Span<felt252>) -> Option<Vec4>
utils
Felt Utilities
Utility functions for working with signed felt252 values using
sign-magnitude representation.
Functions
felt_sign- Determine the sign of a felt valuefelt_abs- Get the absolute value of a felt
Fully qualified path: cairo_fp::utils
Constants
| HALF_PRIME | Half of the prime field modulus. Used as the boundary between positive and negative values in sign-magnitude representation. Values above this are negative. |
Free functions
| felt_sign | Returns the sign of a signed felt252 . Uses sign-magnitude representation where values greater than HALF_PRIME are considered negative…. |
| felt_abs | Returns the absolute value of a signed felt252 . If the value is negative (per sign-magnitude representation), returns its negation. Otherwise returns the value unchanged. |
Constants
Constants
| HALF_PRIME | Half of the prime field modulus. Used as the boundary between positive and negative values in sign-magnitude representation. Values above this are negative. |
HALF_PRIME
Half of the prime field modulus.
Used as the boundary between positive and negative values in sign-magnitude representation. Values above this are negative.
Fully qualified path: cairo_fp::utils::HALF_PRIME
const HALF_PRIME: felt252 =
1809251394333065606848661391547535052811553607665798349986546028067936010240;
Free functions
Free functions
| felt_sign | Returns the sign of a signed felt252 . Uses sign-magnitude representation where values greater than HALF_PRIME are considered negative…. |
| felt_abs | Returns the absolute value of a signed felt252 . If the value is negative (per sign-magnitude representation), returns its negation. Otherwise returns the value unchanged. |
felt_sign
Returns the sign of a signed felt252.
Uses sign-magnitude representation where values greater than
HALF_PRIME are considered negative.
Returns
trueif the value is negativefalseif the value is positive or zero
Fully qualified path: cairo_fp::utils::felt_sign
fn felt_sign(a: felt252) -> bool
felt_abs
Returns the absolute value of a signed felt252.
If the value is negative (per sign-magnitude representation), returns its negation. Otherwise returns the value unchanged.
Fully qualified path: cairo_fp::utils::felt_abs
fn felt_abs(a: felt252) -> felt252