FOR LOOP "STEP" ?
|
01-31-2015, 04:27 PM
Post: #1
|
|||
|
|||
FOR LOOP "STEP" ?
This is peculiar to say the least:
Quote:EXPORT Test() I was trying to step around a circle, and could not get the STEP increment in a FOR loop to work for me. It worked as expected using other approaches. What's going on with the FOR's <STEP> increment? -Dale- |
|||
01-31-2015, 06:50 PM
Post: #2
|
|||
|
|||
RE: FOR LOOP "STEP" ?
(01-31-2015 04:27 PM)DrD Wrote: This is peculiar to say the least: This could be a simple example for one of the many numerical pitfalls when working with reals. ;-) (01-31-2015 04:27 PM)DrD Wrote: It's generally not a good idea to compare reals with "=". Just a slight roundoff error in the last digit, and the test will fail. This may (!) be the crucial point here. You may try a different less error-prone test instead, something like IF abs(angl – pi/3) < 1E–9 THEN ... Or, even better, use an integer counter variable: Code: FOR k FROM 0 to 6 DO Dieter |
|||
02-02-2015, 07:38 AM
Post: #3
|
|||
|
|||
RE: FOR LOOP "STEP" ?
Hello
Quote:This is peculiar to say the least: Yes, you are correct! interestingly, if you print the successive values of A, you will see that the 2nd value is not what you would expect it to be. The reason for it is that the 'step' is done in a full 15 digit precision add instead of a rounded 12 digit. This is what causes the issue. Sorry about that. cyrille |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)