NumberHelpers.cs 831 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. namespace UnityEngine.InputSystem.Utilities
  3. {
  4. internal static class NumberHelpers
  5. {
  6. public static int AlignToMultipleOf(this int number, int alignment)
  7. {
  8. var remainder = number % alignment;
  9. if (remainder == 0)
  10. return number;
  11. return number + alignment - remainder;
  12. }
  13. public static uint AlignToMultipleOf(this uint number, uint alignment)
  14. {
  15. var remainder = number % alignment;
  16. if (remainder == 0)
  17. return number;
  18. return number + alignment - remainder;
  19. }
  20. public static bool Approximately(double a, double b)
  21. {
  22. return Math.Abs(b - a) < Math.Max(1E-06 * Math.Max(Math.Abs(a), Math.Abs(b)), double.Epsilon * 8);
  23. }
  24. }
  25. }