2
0

math_utils.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. local ffi = require("ffi")
  2. ffi.cdef
  3. [[
  4. bool math_equals(float a, float b);
  5. bool math_test_bitmask(int32_t value, int32_t bitmask);
  6. int32_t math_set_bitmask(int32_t value, int32_t bitmask);
  7. int32_t math_unset_bitmask(int32_t value, int32_t bitmask);
  8. float math_deg_to_rad(float deg);
  9. float math_rad_to_deg(float rad);
  10. uint32_t math_next_pow_2(uint32_t x);
  11. bool math_is_pow_2(uint32_t x);
  12. float math_ceil(float x);
  13. float math_floor(float x);
  14. float math_sqrt(float x);
  15. float math_inv_sqrt(float x);
  16. float math_sin(float x);
  17. float math_cos(float x);
  18. float math_asin(float x);
  19. float math_acos(float x);
  20. float math_tan(float x);
  21. float math_atan2(float y, float x);
  22. float math_abs(float x);
  23. float math_fmod(float n, float d);
  24. ]]
  25. Math = {}
  26. Math.equals = lib.math_equals
  27. Math.test_bitmask = lib.math_test_bitmask
  28. Math.set_bitmask = lib.math_set_bitmask
  29. Math.unset_bitmask = lib.math_unset_bitmask
  30. Math.deg_to_rad = lib.math_deg_to_rad
  31. Math.rad_to_deg = lib.math_rad_to_deg
  32. Math.next_pow_2 = lib.math_next_pow_2
  33. Math.is_pow_2 = lib.math_is_pow_2
  34. Math.ceil = lib.math_ceil
  35. Math.floor = lib.math_floor
  36. Math.sqrt = lib.math_sqrt
  37. Math.sin = lib.math_sin
  38. Math.cos = lib.math_cos
  39. Math.asin = lib.math_asin
  40. Math.acos = lib.math_acos
  41. Math.tan = lib.math_tan
  42. Math.atan2 = lib.math_atan2
  43. Math.abs = lib.math_abs
  44. Math.fmod = lib.math_fmod