From 80c8e77b19a44ebbf8ddc7277b1c22fb461e4e4f Mon Sep 17 00:00:00 2001 From: Rangi Date: Thu, 23 Jul 2026 00:33:16 -0400 Subject: [PATCH] Fixed-point `FMOD` and `LOG` explicitly return 0 for some invalid inputs This is consistent with `fix_Div`'s explicit error handling, and does not rely on subtle C/C++ `fmod` or `log` IEEE 754 behavior. --- src/asm/fixpoint.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/asm/fixpoint.cpp b/src/asm/fixpoint.cpp index eb261f21..05e199e4 100644 --- a/src/asm/fixpoint.cpp +++ b/src/asm/fixpoint.cpp @@ -77,7 +77,11 @@ int32_t fix_Div(int32_t i, int32_t j, int32_t q) { } int32_t fix_Mod(int32_t i, int32_t j, int32_t q) { - return double2fix(fmod(fix2double(i, q), fix2double(j, q)), q); + double divisor = fix2double(j, q); + if (fpclassify(divisor) == FP_ZERO) { + return 0; + } + return double2fix(fmod(fix2double(i, q), divisor), q); } int32_t fix_Pow(int32_t i, int32_t j, int32_t q) { @@ -86,6 +90,9 @@ int32_t fix_Pow(int32_t i, int32_t j, int32_t q) { int32_t fix_Log(int32_t i, int32_t j, int32_t q) { double divisor = log(fix2double(j, q)); + if (isnan(divisor) || isinf(divisor)) { + return 0; + } if (fpclassify(divisor) == FP_ZERO) { return INT32_MAX; }