Scheme 函数 inexact->exact 是如何操作的?
SICP 中描述的Scheme 过程inexact->exact
是如何运行的?
How does the Scheme procedure inexact->exact
, described in SICP, operate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Scheme 标准仅对如何记录精确性/不精确性给出了一些一般约束,但大多数 Scheme 实现(直至标准 R5RS)的操作如下(MIT Scheme,即 SICP 的“母语”,也以这种方式工作):
几点:第一,不同的方案标准在运营商给出的准确与否上存在差异;标准不足以决定会发生什么。例如,几个Scheme实现具有精确有理数的表示,允许精确地表示
(/ 1 3)
,而仅具有浮点数的Scheme实现必须不精确地表示这一点。其次,R6RS 的传染概念与 SICP 和早期标准不同,因为坦率地说,旧标准已经被打破。
The Scheme standard only gives some general constraints on how exactness/inexactness is recorded, but most Scheme implementations, up to standard R5RS, operate as follows (MIT Scheme, which is SICP's "mother tongue", also works this way):
Some points: first, different scheme standards vary in when operators give exactness or not; the standards underdetermine what happens. For example, several Scheme implementations have representations for exact rationals, allowing
(/ 1 3)
to be represented exactly, where a Scheme implementation with only floats must represent this inexactly.Second, R6RS has a different notion of contagion from that of SICP and earlier standards, because the older criterion is, frankly, broken.
精确性只是数字的一个属性:它不会改变数字本身的值。因此,对于使用标志来指示精确性的实现,
inexact->exact
只需在该数字上设置精确性标志即可。Exactness is simply a property of a number: it doesn't change the value of the number itself. So, for an implementation that uses a flag to indicate exactness,
inexact->exact
simply sets the exactness flag on that number.