一个编程的小问题
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 4 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:EnyaLinn (等级:4 - 马马虎虎,发帖:885) 发表:2006-08-09 00:49:13  楼主  关注此帖评分:
一个编程的小问题
在scheme里面,把数字平方,会出这样的结果:
比如说,平方1.2,结果是1.2100000000000002。
平方3.4,结果是11.559999999999999。
以前在java里面也遇到过这种情形,为什么算出来是这样的结果呢,
明明是个准确值。。。
我坐在我的象牙塔里,看看书,想想你。
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:hash (等级:7 - 出类拔萃,发帖:5077) 发表:2006-08-09 01:02:55  2楼
试试把1.2转换成二进制数
in IEEE standard, the double precision number 1.2 is represented by 0x3ff3333333333333 (8byte), and you have a round-off error.

for more details:
http://en.wikipedia.org/wiki/IEEE_754

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2006-08-15 18:49:42  3楼
"平方1.2,结果是1.2100000000000002" means you got a typo, :P
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:simon (等级:10 - 炉火纯青,发帖:6860) 发表:2008-09-02 18:19:45  4楼
taken from wiki:Scheme_(programming language)
"The numeric type is further divided into a numerical tower, with subtypes complex, real, rational and integer. (Note that these subtypes are not disjoint; in fact each type is a subset of the previous one). While it is not required that a Scheme implementation support the entire numerical tower, most implementations do. In addition to these traditional properties, Scheme numbers may have the property of "exactness". Integers and rational numbers are exact. An arithmetic operation involving numbers one or more of which is inexact has an inexact result.[1]"

In other words, some implementation of real numbers of scheme is imprecise.
Besides, I don't think Java has such problem.

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 4 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码