Section 4.7.2 of the MIT/GNU Scheme Reference Manual表示
IEEE浮点数规范支持三个特殊的“数字”:正无穷大(
+inf
),负无穷大(-inf
)和非数字(NaN
)
这些常量除了定义良好的IEEE浮点值外,对范围算法也很有用。但是,我无法在我的程序中使用它们:
1 ]=> +inf
;Unbound variable: +inf
生成这些值并不容易:表达式似乎应该评估浮点无穷大只是不:
1 ]=> (flo:/ 1. 0.)
;Floating-point division by zero
如何在MIT Scheme中输入或生成无限浮点常数?
答案 0 :(得分:2)
tests/runtime/test-arith.scm建议使用flo:with-exceptions-untrapped
:
;;; XXX The nonsense about IDENTITY-PROCEDURE here serves to fake
;;; out bogus constant-folding which needs to be fixed in SF (and
;;; probably LIAR too).
(define (zero)
(identity-procedure 0.))
(define (nan)
(flo:with-exceptions-untrapped (flo:exception:invalid-operation)
(lambda ()
(flo:/ (zero) (zero)))))
(define (inf+)
(flo:with-exceptions-untrapped (flo:exception:divide-by-zero)
(lambda ()
(flo:/ +1. (zero)))))
(define (inf-)
(flo:with-exceptions-untrapped (flo:exception:divide-by-zero)
(lambda ()
(flo:/ -1. (zero)))))
结果显示为#[NaN]
,#[+inf]
,#[-inf]
但不能以这种方式输入。