diff --git a/AK/Math.h b/AK/Math.h index fbaa8901eb8..8424ec8f2f1 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -65,23 +65,29 @@ template constexpr T fmod(T x, T y) { CONSTEXPR_STATE(fmod, x, y); - T res; - asm( - "fprem" - : "=t"(res) - : "0"(x), "u"(y)); - return res; + u16 fpu_status; + do { + asm( + "fprem\n" + "fnstsw %%ax\n" + : "+t"(x), "=a"(fpu_status) + : "u"(y)); + } while (fpu_status & 0x400); + return x; } template constexpr T remainder(T x, T y) { CONSTEXPR_STATE(remainder, x, y); - T res; - asm( - "fprem1" - : "=t"(res) - : "0"(x), "u"(y)); - return res; + u16 fpu_status; + do { + asm( + "fprem1\n" + "fnstsw %%ax\n" + : "+t"(x), "=a"(fpu_status) + : "u"(y)); + } while (fpu_status & 0x400); + return x; } }