Vlisp autocad:即使a等于b,条件(>;a b)也为真。为什么?

Vlisp autocad:即使a等于b,条件(>;a b)也为真。为什么?,lisp,autocad,autolisp,Lisp,Autocad,Autolisp,我的口齿不清有问题。 我把它放在你能找到问题的地方 ;values for debug (setq l_max 2 delta_sup 60 phi_superiore 10 delta_inf 40 phi_inferiore 10 lunghezza 10.0) ;code starts here (setq l_ferri_sup l_max l_ferri_inf l_max n 1 dis

我的口齿不清有问题。 我把它放在你能找到问题的地方

;values for debug
(setq l_max 2
      delta_sup 60
      phi_superiore 10
      delta_inf 40
      phi_inferiore 10
      lunghezza 10.0)

;code starts here
(setq l_ferri_sup l_max
      l_ferri_inf l_max
      n 1
      distanza l_max)
(while (> lunghezza distanza)
      (setq distanza (- (+ distanza l_max) (/ (* delta_sup phi_superiore) 1000.0))
            n (1+ n))
)

(setq l_ferri_sup (- (* n l_max) (- distanza lunghezza))
      n 1
      distanza l_max)


(while (> lunghezza distanza) ;WHEN "distanza" is 10.0, condition still true
      (setq distanza (- (+ distanza l_max) (/ (* delta_inf phi_inferiore) 1000.0))
            n (1+ n))
)

(setq l_ferri_inf (- (* n l_max) (- distanza lunghezza)))
如果您尝试运行这几行,您将在第二个while条件下发现问题。 这很奇怪。。 你知道吗

谢谢,丹尼斯


编辑:我已更正问题中的一个错误

l_max
是一个整数(32位),
distanza
是一个实数(64位双精度浮点)。这可能会导致一些舍入错误:

(- 3.6 2.4) ; Returns 1.2
(= 1.2 (- 3.6 2.4)) ; Returns nil
(equal 1.2 (- 3.6 2.4) 1e-6) ; Returns T
尝试用实数初始化
l_max

(setq l_max 2.0)
或者使用ε:

 (> lunghezza (+ distanza 1e-10))

默认情况下,AutoCAD使用1e-10来比较2个实数。

必须以这种方式编写,才能得到我想要的:(>lunghezza(+distanza 0.01))