MathfEx.cs 990 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. #if REAL_T_IS_DOUBLE
  3. using real_t = System.Double;
  4. #else
  5. using real_t = System.Single;
  6. #endif
  7. namespace Godot
  8. {
  9. public static partial class Mathf
  10. {
  11. // Define constants with Decimal precision and cast down to double or float.
  12. public const real_t E = (real_t) 2.7182818284590452353602874714M; // 2.7182817f and 2.718281828459045
  13. public const real_t Sqrt2 = (real_t) 1.4142135623730950488016887242M; // 1.4142136f and 1.414213562373095
  14. #if REAL_T_IS_DOUBLE
  15. public const real_t Epsilon = 1e-14; // Epsilon size should depend on the precision used.
  16. #else
  17. public const real_t Epsilon = 1e-06f;
  18. #endif
  19. public static int CeilToInt(real_t s)
  20. {
  21. return (int)Math.Ceiling(s);
  22. }
  23. public static int FloorToInt(real_t s)
  24. {
  25. return (int)Math.Floor(s);
  26. }
  27. public static int RoundToInt(real_t s)
  28. {
  29. return (int)Math.Round(s);
  30. }
  31. }
  32. }