Library for math with quotients in cairo

Hi everyone, I’ve created a simple utility library with a ratio struct that lets you do math with quotients.

Current functionality:

  • multiply ratios
  • divide ratios
  • raise ratio to power
  • take nth root of ratio
  • add ratios
  • absolute value of difference between ratios
  • check if one ratio is less than or equal to another

I haven’t added testing or overflow safety yet but would love some feedback on the general idea and implementation.

My motivation for this implementation is I needed something that I could take the nth root of for implementing a balancer like invariant in a liquidity pool.

Looking forward to hearing from you all.

7 Likes

I’ve added some hypothesis testing and a really accurate nth_root method (nth_root_by_digit)

5 Likes