However, sometimes it preferable to have small numbers printed in natural notation.
The following (relocatable) code does that.
Because a significant decimal is lost in the process, numbers smaller than 1e-8 are rounded down to 0.
Set the USR() vector to the start of the code and have USR() work as an alternative to STR$().
Example:
Code: Select all
PRINT STR$(1E-4)
1E-04
PRINT USR(1E-4)
.0001
Regards,
Wim.
Code: Select all
jsr $cd8d ; check type numeric
lda $61
cmp #$7b ; between -0.015625 and 0.015625 ?
bcs l500 ; branch if large enough
cmp #$66 ; between -1e-8 and 1e-8
bcc l200 ; set it to zero
lda $66 ; get sign
pha ; save sign
lsr $66 ; set sign to positive
lda #$bc
ldy #$d9
jsr $d867 ; add 1.0
pla ; retrieve sign
sta $66 ; restore it
jsr $dddf ; perform STR$
l300 iny
lda $00ff,y ; one position to the left
sta $00fe,y
bne l300
jmp $d46d ; exit
l200 lda #$00
sta $61
l500 jmp $d468