Circle-clicking rhythm game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

  1. /*
  2. * Copyright (C) 2018-2019 Alexandros Theodotou <alex at zrythm dot org>
  3. *
  4. * This file is part of Zrythm
  5. *
  6. * Zrythm is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Zrythm is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __UTILS_MATH_H__
  20. #define __UTILS_MATH_H__
  21. #include <float.h>
  22. #include <math.h>
  23. #include <stdint.h>
  24. #define MATH_FLOATS_EQUAL(a,b,epsilon) \
  25. (fabsf (a - b) < epsilon)
  26. /**
  27. * Checks if 2 floating points are equal.
  28. *
  29. * @param epsilon The allowed differene.
  30. */
  31. static inline int
  32. math_floats_equal (
  33. const float a,
  34. const float b,
  35. const float epsilon)
  36. {
  37. return fabsf (a - b) < epsilon;
  38. }
  39. /**
  40. * Checks if 2 doubles are equal.
  41. *
  42. * @param epsilon The allowed differene.
  43. */
  44. static inline int
  45. math_doubles_equal (
  46. const double a,
  47. const double b,
  48. const double epsilon)
  49. {
  50. return fabs (a - b) < epsilon;
  51. }
  52. #endif