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 |