Implement the nan() function.

This parses the NaN code string itself, but it should give equivalent behavior to the SANE parser.
This commit is contained in:
Stephen Heumann 2021-11-22 21:59:50 -06:00
parent c025bba177
commit 14908ebcd6
2 changed files with 72 additions and 0 deletions

View File

@ -820,6 +820,70 @@ ret lda #^t1 return t1 (fractional part)
creturn 4:iptr
end
****************************************************************
*
* double nan(const char *tagp);
*
* Returns a quiet NaN, with NaN code determined by the
* argument string.
*
****************************************************************
*
nan start
nanf entry
nanl entry
using MathCommon2
csubroutine (4:tagp)
phb
phk
plb
stz t1+6 initial code is 0
loop lda [tagp] do
and #$00FF get next character
beq loopdone if end of string, break
cmp #'0'
blt no_code
cmp #'9'+1
bge no_code if not a digit, treat as no code
and #$000F
asl t1+6 code = code*10 + digit
clc
adc t1+6
asl t1+6
asl t1+6
clc
adc t1+6
sta t1+6
inc4 tagp tagp++
bra loop while true
no_code stz t1+6 if no code specified, default to 0
loopdone lda t1+6
and #$00FF use low 8 bits as NaN code
bne codeok if code is 0
lda #21 use NANZERO
codeok ora #$4000 set high bit of f for quiet NaN
sta t1+6
lda #32767 e=32767 for NaN
sta t1+8
stz t1+4 set rest of fraction field to 0
stz t1+2
stz t1
lda #^t1 return a pointer to the result
sta tagp+2
lda #t1
sta tagp
plb
creturn 4:tagp
end
****************************************************************
*
* double nearbyint(double x);

View File

@ -273,6 +273,14 @@
longa on
longi on
.a
mend
macro
&l inc4 &a
&l ~setm
inc &a
bne ~&SYSCNT
inc 2+&a
~&SYSCNT ~restm
mend
MACRO
&LAB FCLASSS