diff options
author | chai <chaifix@163.com> | 2021-12-01 13:52:38 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-12-01 13:52:38 +0800 |
commit | 1308cb4e2db1eb117b53372bc4fe964cf2d96813 (patch) | |
tree | b18d1bbddde2afc98589540bd937d38778dda4ce /Client/Source/Phy2DLite/Settings.h | |
parent | 09abf1b529b4226f585ecfbb20866715b901755b (diff) |
*fpm增加一些float类型的方法
Diffstat (limited to 'Client/Source/Phy2DLite/Settings.h')
-rw-r--r-- | Client/Source/Phy2DLite/Settings.h | 56 |
1 files changed, 51 insertions, 5 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 |