From b62f87c9496cb38f9c49139386edf85d4fa14390 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 2 Dec 2021 21:07:58 +0800 Subject: *misc --- Client/Source/Phy2D/Common/Settings.h | 24 +++++++++++++++++++----- Client/Source/Phy2D/Tests/test_math.cpp | 11 ++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'Client/Source/Phy2D') diff --git a/Client/Source/Phy2D/Common/Settings.h b/Client/Source/Phy2D/Common/Settings.h index 318a76c..b03ecad 100644 --- a/Client/Source/Phy2D/Common/Settings.h +++ b/Client/Source/Phy2D/Common/Settings.h @@ -1,16 +1,19 @@ #pragma once -#define NUMBER_FLOAT 1 -#define NUMBER_LIBFIX 2 -#define NUMBER_FPM 3 +#define NUMBER_FLOAT 1 +#define NUMBER_LIBFIX 2 +#define NUMBER_FPM 3 +#define NUMBER_FIX32 4 -#define NUMBER_ALIAS NUMBER_FPM +#define NUMBER_ALIAS NUMBER_FIX32 #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" +#elif NUMBER_ALIAS == NUMBER_FIX32 +#include "fix32/fix32.hpp" #endif namespace Phy2D @@ -28,7 +31,6 @@ namespace Phy2D #elif NUMBER_ALIAS == NUMBER_LIBFIX - // 同时一定要开启内联函数扩展,否则执行效率会非常低 typedef Fix16 fixed; #define NUMBER_MAX (fix16_maximum) #define NUMBER_MIN (fix16_minimum) @@ -92,6 +94,18 @@ namespace Phy2D #define COS(a) (fpm::cos((a))) #define PI (fixed::pi()) +#elif NUMBER_ALIAS == NUMBER_FIX32 + + typedef Fix32 fixed32; // Q32.32 + typedef fixed32 fixed; + +#define NUMBER_MAX (CONST_MAX) +#define NUMBER_MIN (CONST_MIN) +#define SQRT(a) ((a).sqrt()) +#define SIN(a) ((a).sin()) +#define COS(a) ((a).cos()) +#define PI (CONST_PI) + #endif } \ No newline at end of file diff --git a/Client/Source/Phy2D/Tests/test_math.cpp b/Client/Source/Phy2D/Tests/test_math.cpp index f88170d..36e834c 100644 --- a/Client/Source/Phy2D/Tests/test_math.cpp +++ b/Client/Source/Phy2D/Tests/test_math.cpp @@ -4,17 +4,18 @@ #include #include "../Common/Math.h" +#include "../Common/Settings.h" #include "fix32/fix32.hpp" -using namespace std; +using namespace Phy2D; int main(int argc, char **argv) { - Fix32 a = 1.3; - Fix32 b = 2.4; - Fix32 c = a * b; + fixed32 a = 1111.33333; + fixed32 b = 23333.44444; + fixed32 c = a / b; - cout << (double)c; + std::cout << (double)c; getchar(); -- cgit v1.1-26-g67d0