At 09:39 18/06/2001 +0200, you wrote:
>As I see a question about FOR/NEXT loops, I have mine:
>the subsequent peice of code gives me an unexpected result 
>FOR n = 2.95 to 3.05 STEP 0.01 : print n, INT(n)
>Why ?

Cumulative roundoff; .01 is not representable exactly in binary, so
that after 5
steps you have n = 2.999999..., which PRINT rounds correctly to 3 but
INT truncates to 2.

I try to avoid fractional STEPs, unless they are inverse powers of 2
or sums thereof, i.e., exact _binary_ steps.

The following avoids the _cumulative_ roundoff entirely:
  FOR m = 295 TO 305: n = m/100: PRINT n, INT(n)
>
>Claude
>(I am using QPC2v2.00 and SMSQ/e v2.98)
>
>

Reply via email to