Skip to content

Commit

Permalink
Fix issues with negative float conversion on some platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
TollyH committed May 2, 2024
1 parent 34d8c97 commit 2024a90
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2761,20 +2761,22 @@ is not (ulong)StatusFlags.Sign and not (ulong)StatusFlags.Overflow)
floatingInitial = BitConverter.UInt64BitsToDouble(ReadMemoryRegister(operandStart));
switch (opcodeLow)
{
// "(ulong)(long)" cast is used as casting negative floating point values directly to unsigned integers
// causes unexpected results on some platforms, so a signed integer must be used as an intermediary.
case 0x0: // FLPT_FTS reg
result = (ulong)floatingInitial;
result = (ulong)(long)floatingInitial;
Registers[(int)Register.rpo]++;
break;
case 0x1: // FLPT_FCS reg
result = (ulong)Math.Ceiling(floatingInitial);
result = (ulong)(long)Math.Ceiling(floatingInitial);
Registers[(int)Register.rpo]++;
break;
case 0x2: // FLPT_FFS reg
result = (ulong)Math.Floor(floatingInitial);
result = (ulong)(long)Math.Floor(floatingInitial);
Registers[(int)Register.rpo]++;
break;
case 0x3: // FLPT_FNS reg
result = (ulong)Math.Round(floatingInitial);
result = (ulong)(long)Math.Round(floatingInitial);
Registers[(int)Register.rpo]++;
break;
default:
Expand Down

0 comments on commit 2024a90

Please sign in to comment.