The following warnings occurred:
Warning [2] Undefined array key 0 - Line: 1677 - File: showthread.php PHP 8.2.31 (Linux)
File Line Function
/inc/class_error.php 157 errorHandler->error
/showthread.php 1677 errorHandler->error_callback
/showthread.php 916 buildtree




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Float variable stores only integer value. Why ?
#1
I'm doing my first tests with ZX Basic. I've tried to create a timer and I found the following issue

Code:
REM timer test DIM t1 as float = 0.00 border 0:paper 0:ink 2:cls while (0=0) t1 = (65536 * peek 23674 +256 * peek 23673 + peek 23672) /50 pause int(10+25*RND) t1 = ((65536 * peek 23674 +256 * peek 23673 + peek 23672) /50) -t1 REM t1 ignores decimal part and has been declared as float print at 0,0;t1 REM result is always 0 or 1 if inkey$="s" then end end if wend

In example, t1 is declared as float but the variable only stores the integer value, and the final result is wrong. In this case print result is always 0 or 1, ignoring the decimal part
There is something that escapes me or i don't understand?
The same example adapted to Sinclair basic displays and store decimal part correctly.

Thanks in advance
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)