aboutsummaryrefslogtreecommitdiff
path: root/Client/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Source')
-rw-r--r--Client/Source/Phy2DLite/Settings.h56
-rw-r--r--Client/Source/Phy2DLite/Tests/test_p2d.cpp4
2 files changed, 53 insertions, 7 deletions
diff --git a/Client/Source/Phy2DLite/Settings.h b/Client/Source/Phy2DLite/Settings.h
index e976e26..e50646c 100644
--- a/Client/Source/Phy2DLite/Settings.h
+++ b/Client/Source/Phy2DLite/Settings.h
@@ -4,13 +4,59 @@
#define NUMBER_LIBFIX 2
#define NUMBER_FPM 3
-#define NUMBER_ALIAS NUMBER_LIBFIX
+#define NUMBER_ALIAS NUMBER_FPM
#if NUMBER_ALIAS == NUMBER_LIBFIX
#include "libfixmath/libfixmath/fixmath.h"
#elif NUMBER_ALIAS == NUMBER_FPM
#include "fpm/include/fpm/fixed.hpp"
#include "fpm/include/fpm/math.hpp"
+
+template <typename T>
+struct Limits {};
+
+template <>
+struct Limits<fpm::fixed_16_16>
+{
+ static constexpr bool is_signed() noexcept { return true; }
+ static constexpr int digits() noexcept { return 31; }
+ static constexpr int max_digits10() noexcept { return 5 + 5; }
+ static constexpr int min_exponent() noexcept { return -15; }
+ static constexpr int max_exponent() noexcept { return 15; }
+ static constexpr int min_exponent10() noexcept { return -4; }
+ static constexpr int max_exponent10() noexcept { return 4; }
+ static constexpr fpm::fixed_16_16 min() noexcept { return fpm::fixed_16_16::from_raw_value(-2147483647 - 1); }
+ static constexpr fpm::fixed_16_16 max() noexcept { return fpm::fixed_16_16::from_raw_value(2147483647); }
+};
+
+template <>
+struct Limits<fpm::fixed_24_8>
+{
+ static constexpr bool is_signed() noexcept { return true; }
+ static constexpr int digits() noexcept { return 31; }
+ static constexpr int max_digits10() noexcept { return 7 + 3; }
+ static constexpr int min_exponent() noexcept { return -7; }
+ static constexpr int max_exponent() noexcept { return 23; }
+ static constexpr int min_exponent10() noexcept { return -2; }
+ static constexpr int max_exponent10() noexcept { return 6; }
+ static constexpr fpm::fixed_24_8 min() noexcept { return fpm::fixed_24_8::from_raw_value(-2147483647 - 1); }
+ static constexpr fpm::fixed_24_8 max() noexcept { return fpm::fixed_24_8::from_raw_value(2147483647); }
+};
+
+template <>
+struct Limits<fpm::fixed_8_24>
+{
+ static constexpr bool is_signed() noexcept { return true; }
+ static constexpr int digits() noexcept { return 31; }
+ static constexpr int max_digits10() noexcept { return 3 + 8; }
+ static constexpr int min_exponent() noexcept { return -23; }
+ static constexpr int max_exponent() noexcept { return 7; }
+ static constexpr int min_exponent10() noexcept { return -7; }
+ static constexpr int max_exponent10() noexcept { return 2; }
+ static constexpr fpm::fixed_8_24 min() noexcept { return fpm::fixed_8_24::from_raw_value(-2147483647 - 1); }
+ static constexpr fpm::fixed_8_24 max() noexcept { return fpm::fixed_8_24::from_raw_value(2147483647); }
+};
+
#endif
namespace Phy2D
@@ -38,13 +84,13 @@ typedef Fix16 number;
#elif NUMBER_ALIAS == NUMBER_FPM
typedef fpm::fixed_16_16 number;
-#define NUMBER_MAX (number::max())
-#define NUMBER_MIN (number::min())
+#define NUMBER_MAX (Limits<number>::max())
+#define NUMBER_MIN (Limits<number>::min())
#define SQRT(a) (fpm::sqrt((a)))
#define SIN(a) (fpm::sin((a)))
#define COS(a) (fpm::cos((a)))
+#define PI (number::pi())
#endif
-}
-
+} \ No newline at end of file
diff --git a/Client/Source/Phy2DLite/Tests/test_p2d.cpp b/Client/Source/Phy2DLite/Tests/test_p2d.cpp
index a668301..69737f6 100644
--- a/Client/Source/Phy2DLite/Tests/test_p2d.cpp
+++ b/Client/Source/Phy2DLite/Tests/test_p2d.cpp
@@ -292,7 +292,7 @@ static void Demo7(Body* b, Joint* j)
float dampingRatio = 0.7f;
// frequency in radians
- float omega = (number)2.0f * fix16_pi * frequencyHz;
+ float omega = (number)2.0f * PI * frequencyHz;
// damping coefficient
float d = 2.0f * mass * dampingRatio * omega;
@@ -418,7 +418,7 @@ static void Demo9(Body* b, Joint* j)
float dampingRatio = 0.7f;
// frequency in radians
- float omega = (number) 2.0f * fix16_pi * frequencyHz;
+ float omega = (number) 2.0f * PI * frequencyHz;
// damping coefficient
float d = 2.0f * mass * dampingRatio * omega;