Again SVI-3x8

Page 6/6
1 | 2 | 3 | 4 | 5 |

By NYYRIKKI

Enlighted (4497)

NYYRIKKI's picture

16-03-2017, 09:24

Manuel wrote:

It doesn't? Did you check for 'scientific notation' in the format command? Smile

Enlighten me if you know something more... I don't say that it can't be done... It can be done by extracting & evaluating exponent of %E result and when needed selecting %f or replacing in loop "0E" and ".E" combinations with "E" until they are not found... As that "0.0001" is perfectly understandable both to humans and MSX-BASIC, I don't think it is worth the hassle...

Here is definition of %G: If the exponent is less than -4 or greater than or equal to the precision, then convert floating-point number as for %E. Otherwise convert as for %f. Trailing zeroes and a trailing decimal point are omitted.

MSX seems to use same rule except that the limit is "exponent is less than -2"

By NYYRIKKI

Enlighted (4497)

NYYRIKKI's picture

16-03-2017, 12:28

Hmm... ok... I think I figured out quite an easy workaround:
Edit: Didn't work due to octal number conversion... fixed...

proc make_msx_double {num} {
     set n [format "% .14E" $num]
     set e [expr [scan [string range $n 18 20] %d ]]
     if {[expr ($e <-2 && $e >-5)]} {
        return [format "%g" [string range $n 0 16]]E$e
     } else {
        return [format "%.14G" $num]
     }
}
Page 6/6
1 | 2 | 3 | 4 | 5 |
My MSX profile