Add a function to implement the FP comparison macros in <math.h>.

These macros differ from the normal comparison operators in that they will not signal invalid due to the operands being unordered. However, this implementation will still signal invalid for SNaNs. That is clearly OK according to the wording in draft C23. C17 and earlier do not mention that possibility, but they do not really specify the behavior of SNaNs in general.
This commit is contained in:
Stephen Heumann 2021-11-02 21:56:30 -05:00
parent b8605de33f
commit fb5683a14d
2 changed files with 47 additions and 0 deletions

View File

@ -153,3 +153,44 @@ __signbit start
creturn 2:val
end
****************************************************************
*
* int __fpcompare(long double x, long double y, short mask);
*
* Compare two floating-point values, not signaling invalid
* if they are unordered.
*
* Inputs:
* x,y - values to compare
* mask - mask of bits as returned in X register from FCMP
*
* Outputs:
* 1 if x and y have one of the relations specified by mask
* 0 otherwise
*
****************************************************************
*
__fpcompare start
csubroutine (10:x,10:y,2:mask),0
tdc
clc
adc #x
pea 0
pha
tdc
clc
adc #y
pea 0
pha
FCMPX
txa
and mask
beq lb1
lda #1
lb1 sta mask
creturn 2:mask
end

View File

@ -121,3 +121,9 @@
LDX #$090A
JSL $E10000
MEND
MACRO
&LAB FCMPX
&LAB PEA $08
LDX #$090A
JSL $E10000
MEND