Fix div() and ldiv() to return properly-signed remainders.

They could previously give the wrong sign on the remainder in certain cases where one or both of the arguments were negative, because they were using the wrong condition to decide whether to negate it.
This commit is contained in:
Stephen Heumann 2018-09-10 17:09:28 -05:00
parent efab82784d
commit 27fc6836cc
1 changed files with 2 additions and 2 deletions

View File

@ -282,7 +282,7 @@ addr equ 1
jsl ~DIV2
sta div_t save the results
stx div_t+2
tay if the result is negative then
lda n if the numerator is negative then
bpl lb1
sub2 #0,div_t+2,div_t+2 make the remainder negative
lb1 lla addr,div_t return the address
@ -427,7 +427,7 @@ addr equ 1
jsl ~DIV4
pl4 div_t
pl4 div_t+4
lda div_t+2 if the result is negative then
lda n+2 if the numerator is negative then
bpl lb1
sub4 #0,div_t+4,div_t+4 make the remainder negative
lb1 lla addr,div_t return the result