Menu

#60 improve printing floating numbers [r896]

Unstable_(example)
open
None
5
2017-09-23
2017-09-23
No

Hi Jim,

Double precision is ugly.
The average user does not need to know this.

1) Test. Set "Number of digits to print numbers" from Settings at least 12.
Now run the program above. Use left and right arrows to add/subtract 0.1 from r.
Add several times or subtract, and then goto 0.0 value again.
You will fail to print 0.0 again.

fastgraphics
r=0.0
loop:
pause 0.1
if keypressed(16777234) then r=r+0.1
if keypressed(16777236) then r=r-0.1
clg blue
color green
text 5,15,"r: "+r
refresh
goto loop

Result. You will get something like this, instead of 0.0:

2) Set "Number of digits to print numbers" from Settings to a value higher than 12. (use 16, why not?) Add and subtract by using arrows keys.
This is the same program, but without pause:

fastgraphics
r=0.0
loop:
if keypressed(16777234) then r=r+0.1
if keypressed(16777236) then r=r-0.1
clg blue
color green
text 5,15,"r: "+r
refresh
goto loop

The ugly double precision strikes again:

PS This update hides the double (lack of) precision. This is not perfect. The double precision effect will be visible more later, after adding/subtracting around 22700 times.

Respectfully,
Florin Oprea

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.