2

Lispに問題があります。問題を見つけることができる場所にここに置きます。

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

この数行を実行しようとすると、2 番目の while 条件で問題が見つかります。それは非常に奇妙です..それについて何か考えはありますか?

ありがとう、デニス

編集:質問の誤りを修正しました

4

1 に答える 1

4

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

1e-10 は、AutoCAD が既定で 2 つの実数を比較するために使用するものです。

于 2015-08-22T07:36:23.317 に答える