Bug in arithmetic
Martiner
✭
Hi, I wrote this code, ran it in the real controller and I was really surprised.
VAR num ii
VAR num AngleStep:=0.1
FOR i FROM 0 TO 360 STEP AngleStep DO
ii:=ii + AngleStep
ENDFOR
result is ... ii = 359.918
0
Comments
-
Hi Martiner.
In Microsoft Visual Basic, with Single precision variables, the result is 360.0128
Probably the FOR statement is implemented in a slightly different way, causing an iteration less, so your error is 0.018; more or less ...
But from a theorical point of view your code is very poor. Using floating point numbers always introduce an error. Iterating a sum 3600 times will multiply the error by 3600. Better is:
FOR i FROM 0 TO 3600 DO
ii := i / 10
!
! I think you do something here
!
ENDWHILE
Regards
Claudio
claudio2007-2-1 18:17:360
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 800 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings