From ac3616d42c51b1717e97459e21fb84f4fc548658 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Fri, 22 May 2015 04:51:20 +0000 Subject: [PATCH] [FAST486] Fix Fast486FpuToInteger. svn path=/trunk/; revision=67846 --- reactos/lib/fast486/fpu.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/reactos/lib/fast486/fpu.c b/reactos/lib/fast486/fpu.c index 7eb9f392c63..f70c51202b3 100644 --- a/reactos/lib/fast486/fpu.c +++ b/reactos/lib/fast486/fpu.c @@ -310,8 +310,7 @@ Fast486FpuToInteger(PFAST486_STATE State, return TRUE; } - if (FPU_IS_NAN(Value) || !FPU_IS_NORMALIZED(Value) - || (UnbiasedExp < 0) || (UnbiasedExp > 63)) + if (FPU_IS_NAN(Value) || !FPU_IS_NORMALIZED(Value) || (UnbiasedExp >= 63)) { /* Raise an invalid operation exception */ State->FpuStatus.Ie = TRUE; @@ -328,11 +327,31 @@ Fast486FpuToInteger(PFAST486_STATE State, } } - Bits = 63 - UnbiasedExp; + if (UnbiasedExp >= 0) + { + Bits = 63 - UnbiasedExp; - /* Calculate the result and the remainder */ - *Result = (LONGLONG)(Value->Mantissa >> Bits); - Remainder = Value->Mantissa & ((1 << Bits) - 1); + /* Calculate the result and the remainder */ + *Result = (LONGLONG)(Value->Mantissa >> Bits); + Remainder = Value->Mantissa & ((1 << Bits) - 1); + } + else + { + /* The result is zero */ + *Result = 0LL; + + if (UnbiasedExp > -64) + { + Bits = 65 + UnbiasedExp; + Remainder = Value->Mantissa >> (64 - Bits); + } + else + { + /* Too small to even have a remainder */ + Bits = 1; + Remainder = 0ULL; + } + } /* The result must be positive here */ ASSERT(*Result >= 0LL);