# HG changeset patch # User William Astle # Date 1697584356 21600 # Node ID 6ac267da2216b05902f0614e713fc8e243992012 # Parent ecca1fcfc34b57b9b6c2c9e90682048eae03962f Correctly calculate existing significand digits for fp to ascii conversion You need to start at the end of the digits and work left to find the first nonzero digit if you want the number of real digits in the significand. Going the other way looking for zeroes causes it to bail out too soon and lop off digits at the first zero encountered within the number, even if it isn't a trailing zero. diff -r ecca1fcfc34b -r 6ac267da2216 src/fps.s --- a/src/fps.s Tue Oct 17 17:03:37 2023 -0600 +++ b/src/fps.s Tue Oct 17 17:12:36 2023 -0600 @@ -803,17 +803,17 @@ bpl fps_toascii1 ; brif not lda #'- ; negative sign sta -1,u -fps_toascii1 clra ; set number of significant digits that exist - ldx #fpa0+fpa.sig ; point to significand -fps_toascii2 ldb ,x+ ; get digit pair - bitb #0xf0 ; is left digit set? - beq fps_toascii3 ; brif not - we've counted all the significant digits - inca ; count digit - bitb #0x0f ; is right digit set? - beq fps_toascii3 ; brif not - we've counted all the sigificant digits - inca ; count the digit - cmpx #fpa0+fpa.sig+5 ; done all significant digits? - blo fps_toascii2 ; brif not +fps_toascii1 lda #10 ; assume 10 significant digits exist + ldx #fpa0+fpa.sig+5 ; point to significand +fps_toascii2 ldb ,-x ; get digit pair + bitb #0x0f ; is right digit zero? + bne fps_toascii3 ; brif not - we've counted all the significant digits + deca ; trailing zero - uncount it + bitb #0xf0 ; is left digit zero? + bne fps_toascii3 ; brif not - we've counted all the sigificant digits + deca ; trailing zero - uncount it + cmpx #fpa0+fpa.sig ; done all significant digits? + bhi fps_toascii2 ; brif not fps_toascii3 sta fpaextra ; save significant digits that exist lda fpa0+fpa.exp ; fetch exponent suba #64 ; remove bias