如何将正无穷大和负无穷大输入到 MIT Scheme 中?
How does one input positive and negative infinities into MIT Scheme?
Section 4.7.2 of the MIT/GNU Scheme Reference Manual 表示
The IEEE floating-point number specification supports three special ‘numbers’: positive infinity (+inf
), negative infinity (-inf
), and not-a-number (NaN
).
这些常量除了是明确定义的 IEEE 浮点值外,对于范围运算也很有用。但是,我无法在我的程序中使用它们:
1 ]=> +inf
;Unbound variable: +inf
生成这些值也不容易:看起来应该计算为浮点无穷大的表达式根本就没有:
1 ]=> (flo:/ 1. 0.)
;Floating-point division by zero
如何在 MIT Scheme 中输入或生成无穷大的浮点常量?
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]
,但不能那样输入。
Section 4.7.2 of the MIT/GNU Scheme Reference Manual 表示
The IEEE floating-point number specification supports three special ‘numbers’: positive infinity (
+inf
), negative infinity (-inf
), and not-a-number (NaN
).
这些常量除了是明确定义的 IEEE 浮点值外,对于范围运算也很有用。但是,我无法在我的程序中使用它们:
1 ]=> +inf
;Unbound variable: +inf
生成这些值也不容易:看起来应该计算为浮点无穷大的表达式根本就没有:
1 ]=> (flo:/ 1. 0.)
;Floating-point division by zero
如何在 MIT Scheme 中输入或生成无穷大的浮点常量?
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]
,但不能那样输入。