Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

ratio

Ratio & Proportion Calculations

Utility functions for ratio calculations in DeFi contexts.

Functions

  • proportion - Calculate part/total ratio
  • scale_by_ratio - Multiply amount by ratio
  • inverse_ratio - Calculate 1/ratio
  • weighted_average - Compute weighted average
  • percentage_change - Calculate % change between values
  • percentage_diff - Calculate absolute % difference

All functions that could divide by zero return Option<Fixed>.

Fully qualified path: cairo_fp::f128::math::ratio

Free functions

proportionCalculates the proportion of part to total….
scale_by_ratioMultiplies an amount by a ratio. Semantic wrapper around multiplication for clarity in DeFi contexts.
inverse_ratioCalculates the inverse of a ratio (1 / ratio)….
weighted_averageCalculates the weighted average of values….
percentage_changeCalculates the percentage change between two values. Returns (new - old) / old as a ratio. Multiply by 100 to get percentage….
percentage_diffCalculates the absolute percentage difference. Returns