From 84adb385feed5bcf6848f68eac010e6fb58e78fd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:18:16 +0000 Subject: [PATCH] test: Add edge case tests for fixp_pow in test_fixp.cpp Adds robust edge cases tests for `fixp_pow` in `test_fixp.cpp`, covering zero-valued bases and exponents, negative bases, and extremely large exponents (e.g. `UINT32_MAX`, which acts as an implicit wrapping for `-1`), ensuring `fixp_pow` handles boundary conditions stably in this fixed-point math library. Co-authored-by: perim <436583+perim@users.noreply.github.com> --- tests/test_fixp.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_fixp.cpp b/tests/test_fixp.cpp index a1a7f2e..29fc72d 100644 --- a/tests/test_fixp.cpp +++ b/tests/test_fixp.cpp @@ -4,6 +4,7 @@ #include #include #include +#include static inline double dotf(ivec2 a, ivec2 b) { return a.x.todouble() * b.x.todouble() + a.y.todouble() * b.y.todouble(); } @@ -73,6 +74,15 @@ int main() assert(fixp_dot(a.min, a.max) == dotf(a.min, a.max)); //a.min.x * a.max.x + a.min.y * a.max.y); assert(fixp_pow(f5, 1) == 2); assert(fixp_pow(f5, 2) == 4); + assert(fixp_pow(0, 5) == 0); + assert(fixp_pow(f5, 0) == 1); + assert(fixp_pow(fn1, 2) == 4); + assert(fixp_pow(fn1, 3) == -8); + assert(fixp_pow(fn1, 0) == 1); + assert(fixp_pow(f5, -1) == 0); // Large exponent via negative unsigned wrap-around + assert(fixp_pow(f5, UINT32_MAX) == 0); + fixp f_half = 0.5; + assert(fixp_pow(f_half, -1) == 0); assert(fixp_sqrt(f5).toint() == 1); assert(fixp_sqrt(f5).tofloat() > 1.4f); assert(fixp_sqrt(f5).tofloat() < 1.5f);