TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Peter2 on July 27, 2014, 10:42:37 AM
-
I tried the "rem"-function (http://www.theswamp.org/~john/avlisp/#rem), and many results are OK.
But why - look at the second part of the code - "(rem 1.8 0.3)" and others give a remainder? Normally, 1.8 : 0.3 = 6; 0 remainder ..
0
1
1
-1
0
0.1
0.9
-0.9
-0.1
-0.1
0
0
-0.1
0.1
0.1
0.0
0.8
0.0
0.2
1.11022e-016
1.11022e-016
0.0
Befehl: (/ 1.8 0.6)
3.0
-
Maybe this tread will help:
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Rem-function-question/td-p/822420 (http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Rem-function-question/td-p/822420)
and this one
http://www.theswamp.org/index.php?topic=27412.5
-
In short, when supplying the rem function with doubles (reals) that are ostensibly divisible, the absolute value returned by rem will either be very close to zero or very close to the divisor, depending on whether the rounding of the doubles is above or below the value displayed.
Hence, some tolerance is required for comparisons, e.g.:
_$ (div-p 1.8 0.3)
T
_$ (div-p 1.9 0.1)
T
_$ (div-p -1.9 0.1)
T
-
I'm always scared how this floating-point / double-stuff affects on really simple things like "1.8 : 0.2" ... :x
Thanks to CAB and Lee.
-
I'm always scared how this floating-point / double-stuff affects on really simple things like "1.8 : 0.2" ... :x
Its all manageable :-)
I think the pros of the floating-point format outweigh the cons -
That said, this is obvious, as we would have long abandoned its use by now if they didn't...