Skip to content

Commit 80c8e77

Browse files
committed
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.
1 parent 604c69e commit 80c8e77

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/asm/fixpoint.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ int32_t fix_Div(int32_t i, int32_t j, int32_t q) {
7777
}
7878

7979
int32_t fix_Mod(int32_t i, int32_t j, int32_t q) {
80-
return double2fix(fmod(fix2double(i, q), fix2double(j, q)), q);
80+
double divisor = fix2double(j, q);
81+
if (fpclassify(divisor) == FP_ZERO) {
82+
return 0;
83+
}
84+
return double2fix(fmod(fix2double(i, q), divisor), q);
8185
}
8286

8387
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) {
8690

8791
int32_t fix_Log(int32_t i, int32_t j, int32_t q) {
8892
double divisor = log(fix2double(j, q));
93+
if (isnan(divisor) || isinf(divisor)) {
94+
return 0;
95+
}
8996
if (fpclassify(divisor) == FP_ZERO) {
9097
return INT32_MAX;
9198
}

0 commit comments

Comments
 (0)