calc.h 623 B

123456789101112131415161718
  1. // Calculates the modulo of a number. Works correctly for negative numbers.
  2. int modulo(int x, int N);
  3. // Wraps a number between min and max (inclusive).
  4. int wrap(int x, int min, int max);
  5. // Wraps a number between min and max (inclusive). When wrapping around, the result will always be min or max.
  6. int wrap_single(int x, int min, int max);
  7. // Linearly interpolates between a and b.
  8. int lerp(int a, int b, float t);
  9. // Calculates the inverse linear interpolation of x between a and b.
  10. float inverse_lerp(int a, int b, int x);
  11. // Maps a number from one range to another.
  12. int map(int a0, int b0, int a1, int b1, int x);