TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Red Nova on November 28, 2017, 11:36:41 AM
-
Hi gens,
I faced this situation a few times. Sometimes if I get some length from the drawing and then try to work with it in lisp some functions do not return proper values.
For example Length of a segment is 12.5 (taken from the drawing), when I compare it to a real number
(<= 12.5 SEGMENTLENGTH) might return nil.
Well as far as I know 12.5 is equal to 12.5 :thinking:, so I assume the issue has to do with precision.
Maybe in reality it considers for example 12.5000001, but the Watch Window will only show that SEGMENTLENGTH is 12.5.
Questions:
1. How can I see in the Watch Window the exact value instead of 12.5 in this case?
2. Is the only solution rounding the variable before I compare it?
Thanks
-
Use equal with fuzz value.
(equal 12.5 12.500000001 1e
-8
)
-
Or maybe work with a given precision:
-
(defun _Fix ( n prec )
(/ (fix (+ (if (minusp n) -0.5 0.5) (* n (setq prec (expt 10.0 prec)))))
prec
)
)
(_Fix pi 3) >> 3.142
-
Thank you guys.
I already knew of methods described by Grrr1337 and MP while Grrr1337 suggested something new to me. Using equal with fuzz value is nice, it would be great it >= <= would also accept fuzz value...
And what about vlide Watch Window? Can I setup precision for it?
-
Given _Fix's def ...
(defun _FuzzyComp ( ? a b prec )
;; (_FuzzyComp = 3.145 3.1454 3) >> T
;; (_FuzzyComp eq 3.145 3.1454 3) >> T
;; (_FuzzyComp < 3.145 3.1454 3) >> nil
;; (_FuzzyComp <= 3.145 3.1454 3) >> T
(? (_Fix a prec) (_Fix b prec))
)
-
it would be great it >= <= would also accept fuzz value...
There is this of course:
(>= (- num fuzz) 10.0)
-
Just to make certain on the math - what's the comparison relationship? Are you checking that the segment length is less than or equal to 12.5? Or the other way around?
(<= SEGMENTLENGTH 12.5)
(<= 12.5 SEGMENTLENGTH)
-
MP - looks nice. Thanks. :)
dgorsman - math I was looking for is for both logics.
-
You're welcome RN, thx for the thx. :)
-
Hmm... I still think that
(<= (- 12.5 fuzz) SEGMENTLENGTH)
would be the most obvious solution for the OP's problem.
-
To his second problem, I don't think there is a way to modify the precision of the VLIDE watch window.
-
Thanx for posts.
roy_043 I was looking for a universal way: +fuzz or -fuzz
Master_Shake :-(