I have this interresting problem, it occured just here, in other situations, the script works fine.
I am counting length from coordinates:
Command: (setq bod1 ppo_bod1) (-0.821965 -1.7232 0.0) Command: (setq bod2 ppo_bod2) (25.428 13.1268 0.0) Command: !mfac 0.025 Command: (setq x (atoi (rtos(/ (abs (- (car bod2) (car bod1))) mfac)))) 1050 Command: (setq y (atoi (rtos(/ (abs (- (cadr bod2) (cadr bod1))) mfac)))) 593 Command: (- (cadr bod2) (cadr bod1)) 14.85 Command: (/ (abs (- (cadr bod2) (cadr bod1))) mfac) 594.0 Command: (rtos(/ (abs (- (cadr bod2) (cadr bod1))) mfac)) "593.99999998" Command: (atoi (rtos(/ (abs (- (cadr bod2) (cadr bod1))) mfac))) 593
As you can see, the conversion from 594.0 (real) to string causes an inaccuracy, which is strange, because the length really is 594.0
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
This is because doubles are allocated a limited amount of memory for storage and hence are expressed to a limited precision; consequently, small rounding errors will be introduced at the lowest level of precision and these will accumulate for every arithmetic operation thereafter. This effect is described in more detail here.
To circumvent the problems that arise from this inherent behaviour, you should use appropriate tolerances when comparing doubles (such as provided with the AutoLISP equal function) and round the values when an integer is required (for example, using the rtos function).
In your example:
_$ (atoi (rtos (/ (abs (- (cadr bod2) (cadr bod1))) mfac) 2 0)) 594
Can't find what you're looking for? Ask the community or share your knowledge.