Skip to content

Commit 44280dd

Browse files
[Soft-Float] - Fixes add/sub edge cases for denormals handling.
This commit fixup a calculation mistake in add/sub when dealing with booth numbers that are denormals.
1 parent 7a5ed15 commit 44280dd

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

pcsx2/PS2Float.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,14 @@ PS2Float PS2Float::Add(PS2Float addend)
185185
else if (!IsDenormalized() && addend.IsDenormalized())
186186
return PS2Float(sign, Exponent(), Mantissa());
187187
else if (IsDenormalized() && addend.IsDenormalized())
188-
return PS2Float(sign, 0, 0);
188+
{
189+
if (!Sign() || !addend.Sign())
190+
return PS2Float(false, 0, 0);
191+
else if (Sign() && addend.Sign())
192+
return PS2Float(true, 0, 0);
193+
else
194+
Console.Error("Unhandled addition operation flags");
195+
}
189196
else
190197
Console.Error("Both numbers are not denormalized");
191198

@@ -227,7 +234,14 @@ PS2Float PS2Float::Sub(PS2Float subtrahend)
227234
else if (!IsDenormalized() && subtrahend.IsDenormalized())
228235
return PS2Float(sign, Exponent(), Mantissa());
229236
else if (IsDenormalized() && subtrahend.IsDenormalized())
230-
return PS2Float(sign, 0, 0);
237+
{
238+
if (!Sign() || subtrahend.Sign())
239+
return PS2Float(false, 0, 0);
240+
else if (Sign() && !subtrahend.Sign())
241+
return PS2Float(true, 0, 0);
242+
else
243+
Console.Error("Unhandled subtraction operation flags");
244+
}
231245
else
232246
Console.Error("Both numbers are not denormalized");
233247

@@ -883,31 +897,11 @@ bool PS2Float::DetermineMultiplicationDivisionOperationSign(PS2Float a, PS2Float
883897

884898
bool PS2Float::DetermineAdditionOperationSign(PS2Float a, PS2Float b)
885899
{
886-
if (a.IsZero() && b.IsZero())
887-
{
888-
if (!a.Sign() || !b.Sign())
889-
return false;
890-
else if (a.Sign() && b.Sign())
891-
return true;
892-
else
893-
Console.Error("Unhandled addition operation flags");
894-
}
895-
896900
return a.CompareOperands(b) >= 0 ? a.Sign() : b.Sign();
897901
}
898902

899903
bool PS2Float::DetermineSubtractionOperationSign(PS2Float a, PS2Float b)
900904
{
901-
if (a.IsZero() && b.IsZero())
902-
{
903-
if (!a.Sign() || b.Sign())
904-
return false;
905-
else if (a.Sign() && !b.Sign())
906-
return true;
907-
else
908-
Console.Error("Unhandled subtraction operation flags");
909-
}
910-
911905
return a.CompareOperands(b) >= 0 ? a.Sign() : !b.Sign();
912906
}
913907

0 commit comments

Comments
 (0)