TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: leekh on July 22, 2020, 11:11:29 PM
-
command: t1
dist 0.2 chk
down point:
up point:
chk : 2.83107e-15
command:
command: t2
dist 0.2 chk
down point:
up point:
chk : 2.83107e-15
_$ (- (cadr pt2) (cadr pt1))
0.2
_$ (- (- (cadr pt2) (cadr pt1)) 0.2)
2.83107e-15 <=error 0.0 ok
_$
_$ (distance pt1 pt2)
0.2
_$ (- (distance pt1 pt2) 0.2)
2.83107e-15 <=error 0.0 ok
_$
_$ (distance pt1 pt2)
0.2
_$ (= (distance pt1 pt2) 0.2) <-=error T ok
nil
getpoint or distance error help me
EDIT (John): Added code tags
-
command offset 0.2 work
_$ (- (distance pt1 pt2) 0.2)
-1.13798e-14
error
_$ (- (read (vl-princ-to-string (distance pt1 pt2))) 0.2)
0.0
ok
(- (distance pt1 pt2) 0.2) I don't know why I am getting the error?
-
(rtos (distance pt1 pt2) 2 16)
-
(rtos (distance pt1 pt2) 2 16)
pt1 pt2 dist = 0.2
offset 0.2 use
_$ (rtos (distance pt1 pt2) 2 16)
"0.1999999999999993"
why not "0.1999999999999993" is "0.2" ?
-
because you are asking for it to be accurate to 16 significant digits. This is a result of the way floating point math works on computers. GOOGLE "Floating-point error mitigation"
The error is your assumtion that anything that is computed by AutoCAD (which is almost everything) has the value you think it does i.e. the distance between two points is 0.2 where it could be 0.200000000000001 or 0.199999999999998. To all intents and purposes this is 0.2 since (equal 0.199999999999998 0.2 1.0e-13) will return T. AutoCAD's smallest unit is the angstrom (1.0e-10) so the error is insignificant as it is a 1/1000000th of an angstrom. The largest IIRC is the parsec 3.0e16 metres where such an error will be significant, but this is only because of the limited number of computational registers when doing the math, and who apart from astronomers or astrophysicist works with parsecs.
-
Related:
https://www.theswamp.org/index.php?topic=54883.msg592690#msg592690
https://www.theswamp.org/index.php?topic=44694
https://www.theswamp.org/index.php?topic=53285
https://www.theswamp.org/index.php?topic=8787.msg112317#msg112317
https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems
-
@Dlanor:
What you are saying is confusing. Internally AC works with drawing units (DU). They can be considered mm, inches, angstrom etc. A tolerance of 1.0e-13 DU would be relatively the same whatever 1 DU represents.
-
@leekh:
Some decimal numbers cannot be exactly translated to the binary floating point format. Some loss of accuracy therefore has to be taken into account.
-
because you are asking for it to be accurate to 16 significant digits. This is a result of the way floating point math works on computers. GOOGLE "Floating-point error mitigation"
The error is your assumtion that anything that is computed by AutoCAD (which is almost everything) has the value you think it does i.e. the distance between two points is 0.2 where it could be 0.200000000000001 or 0.199999999999998. To all intents and purposes this is 0.2 since (equal 0.199999999999998 0.2 1.0e-13) will return T. AutoCAD's smallest unit is the angstrom (1.0e-10) so the error is insignificant as it is a 1/1000000th of an angstrom. The largest IIRC is the parsec 3.0e16 metres where such an error will be significant, but this is only because of the limited number of computational registers when doing the math, and who apart from astronomers or astrophysicist works with parsecs.
Thank you for your explanation Now I can understand
-
Related:
https://www.theswamp.org/index.php?topic=54883.msg592690#msg592690
https://www.theswamp.org/index.php?topic=44694
https://www.theswamp.org/index.php?topic=53285
https://www.theswamp.org/index.php?topic=8787.msg112317#msg112317
https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems
Thank you for your explanation Now I can understand
-
@leekh:
Some decimal numbers cannot be exactly translated to the binary floating point format. Some loss of accuracy therefore has to be taken into account.
Thank you for your explanation Now I can understand