summaryrefslogtreecommitdiff
path: root/tests/test_fixed_point.cpp
diff options
context:
space:
mode:
authorbatsumaru <>2026-08-09 17:26:31 +0900
committerbatsumaru <>2026-08-09 17:26:31 +0900
commit653ebf6675f42dde3cbda1fc088f84a7264ec013 (patch)
tree945dd971842b07ac9982c5a6f94356253c67c2b6 /tests/test_fixed_point.cpp
parent7bb49794297b46aa1c577e89da24d39b4348c6d4 (diff)
Added fp_t division
Diffstat (limited to 'tests/test_fixed_point.cpp')
-rw-r--r--tests/test_fixed_point.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_fixed_point.cpp b/tests/test_fixed_point.cpp
index 6d1a594..8c5c269 100644
--- a/tests/test_fixed_point.cpp
+++ b/tests/test_fixed_point.cpp
@@ -50,3 +50,49 @@ TEST_CASE("fp_t multiplication drops percision under 1 ULP") {
fp_t b = fp_t::from_raw(0);
CHECK(a * a == b);
}
+
+TEST_CASE("fp_t division is basic") {
+ fp_t a = fp_t::from_int(10);
+ fp_t b = fp_t::from_int(2);
+ fp_t c = fp_t::from_int(5);
+ CHECK(a / b == c);
+}
+
+TEST_CASE("fp_t division is sign-symmetric") {
+ fp_t a = fp_t::from_int(1);
+ fp_t b = fp_t::from_raw(-3);
+ fp_t neg_a = fp_t::from_raw(-a.raw);
+ fp_t neg_b = fp_t::from_raw(-b.raw);
+ CHECK(neg_a / b == a / neg_b);
+}
+
+TEST_CASE("fp_t division rounds to nearest") {
+ fp_t a = fp_t::from_int(1);
+ fp_t b = fp_t::from_int(3);
+ fp_t c = fp_t::from_raw(21845);
+ CHECK(a / b == c);
+}
+
+TEST_CASE("fp_t division handles negative operands") {
+ fp_t a = fp_t::from_int(-10);
+ fp_t b = fp_t::from_int(2);
+ fp_t c = fp_t::from_int(-5);
+ CHECK(a / b == c);
+
+ fp_t d = fp_t::from_int(10);
+ fp_t e = fp_t::from_int(-2);
+ fp_t f = fp_t::from_int(-5);
+ CHECK(d / e == f);
+
+ fp_t g = fp_t::from_int(-10);
+ fp_t h = fp_t::from_int(-2);
+ fp_t i = fp_t::from_int(5);
+ CHECK(g / h == i);
+}
+
+TEST_CASE("fp_t division truncates precision below 1 ULP") {
+ fp_t a = fp_t::from_raw(1);
+ fp_t b = fp_t::from_int(100000);
+ fp_t c = fp_t::from_raw(0);
+ CHECK(a / b == c);
+}