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

Vlisp autocad: condition (> a b) is true even when a is equal b. Why?

我的口齿不清有问题。 我会把问题放在这里。

;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)

或使用 epsilon:

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

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