diff options
author | chai <chaifix@163.com> | 2021-12-01 13:34:22 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-12-01 13:34:22 +0800 |
commit | 09abf1b529b4226f585ecfbb20866715b901755b (patch) | |
tree | 16929f2a6bee3ad4667bdd006cfcc1e683ab7210 /Client/ThirdParty/fpm/tests/arithmetic_int.cpp | |
parent | 84d961f754c905b37420f4d1b3fee8f4e523e58a (diff) |
+fpm
Diffstat (limited to 'Client/ThirdParty/fpm/tests/arithmetic_int.cpp')
-rw-r--r-- | Client/ThirdParty/fpm/tests/arithmetic_int.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Client/ThirdParty/fpm/tests/arithmetic_int.cpp b/Client/ThirdParty/fpm/tests/arithmetic_int.cpp new file mode 100644 index 0000000..be9c176 --- /dev/null +++ b/Client/ThirdParty/fpm/tests/arithmetic_int.cpp @@ -0,0 +1,45 @@ +#include "common.hpp" + +TEST(arithmethic_int, addition) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(10.5), P(3.5) + 7); +} + +TEST(arithmethic_int, subtraction) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(-3.5), P(3.5) - 7); +} + +TEST(arithmethic_int, multiplication) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(-24.5), P(3.5) * -7); +} + +TEST(arithmethic_int, division) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(3.5 / 7), P(3.5) / 7); + EXPECT_EQ(P(-3.5 / 7), P(-3.5) / 7); + EXPECT_EQ(P(3.5 / -7), P(3.5) / -7); + EXPECT_EQ(P(-3.5 / -7), P(-3.5) / -7); + +#ifndef NDEBUG + EXPECT_DEATH(P(1) / 0, ""); +#endif +} + +TEST(arithmethic_int, division_range) +{ + using P = fpm::fixed<std::int32_t, std::int64_t, 12>; + + // These calculation will overflow and produce + // wrong results without the intermediate type. + EXPECT_EQ(P(32), P(256) / 8); +}
\ No newline at end of file |