Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

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 compounding
  • decay - 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 present
  • effective_annual_rate - Convert nominal to effective rate

Fully qualified path: cairo_fp::f64::math::interest

Free functions

linear_interpolateLinear interpolation between start and end. Returns start + (end - start) × t for 0 ≤ t ≤ 1.
exponential_growthCalculates exponential growth: initial × (1 + rate)^periods.
decayCalculates exponential decay: initial × (1 - rate)^periods. Requires rate < 1 for meaningful results.
compoundCalculates compound interest. Formula: principal × (1 + rate/n)^(n×t)…
simple_interestCalculates simple interest: principal × (1 + rate × time).
continuous_compoundCalculates continuously compounded interest: principal × e^(rate × time).
present_valueCalculates present value from future value. Formula: FV / (1 + rate)^periods
effective_annual_rateCalculates effective annual rate from nominal rate. Formula: (1 + r/n)^n - 1