Skip to content

Arithmetic utilities

  • Safe comparison of integers with std::cmp_equal/not_equal/less,/less_equal/greater/greater_equal
    Problem: -2 < 5 is false (because -2 is automatically converted from signed to unsigned)
    Use safe compare functions to get correct results:
    std::cmp_less(-2, 5) is true
    To compare int and double use old syntax: myDouble < myInt
  • mathematical constants std::numbers::pi/inv_pi/sqrt2/sqrt3/e/log2e/log10e
  • Midpoint of 2 numbers std::midpoint
  • Linear interpolation/extrapolation std::lerp(a,b,t)
    a + t(b-a)