From b01800ff773a49e8aba3606108bbc3610f8aaaaa Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 30 Nov 2021 20:19:57 -0600 Subject: [PATCH] Fix rounding issues introduced by SANE bug workarounds. The lrint functions could give the wrong result for negative numbers in upward/downward rounding modes. Casts to comp could also have different rounding behavior. --- fpextra.asm | 6 ++++++ fpextra.macros | 6 ++++++ math2.asm | 11 +++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fpextra.asm b/fpextra.asm index 798e680..7698c03 100644 --- a/fpextra.asm +++ b/fpextra.asm @@ -81,6 +81,12 @@ fpextra private dummy segment **************************************************************** * ~CompPrecision start + tsc round to integer + clc + adc #4 + pea 0 + pha + FRINTX lda 4+8,s pha save original sign asl a force sign to positive diff --git a/fpextra.macros b/fpextra.macros index ddba238..bda9964 100644 --- a/fpextra.macros +++ b/fpextra.macros @@ -34,3 +34,9 @@ LDX #$090A JSL $E10000 MEND + MACRO +&LAB FRINTX +&LAB PEA $0014 + LDX #$090A + JSL $E10000 + MEND diff --git a/math2.asm b/math2.asm index 2fd2ff7..807d3e0 100644 --- a/math2.asm +++ b/math2.asm @@ -1136,17 +1136,20 @@ lrintl entry csubroutine (10:x),0 pei x+8 save sign of x - asl x+8 x = abs(x) - lsr x+8 - tdc convert to integer + tdc clc adc #x pea 0 pha pea 0 pha - FX2C + pea 0 + pha + FRINTX round x to integer + asl x+8 x = abs(x) + lsr x+8 + FX2C convert to comp lda x+4 if x is out of range of long ora x+6