一个编程的小问题在scheme里面,把数字平方,会出这样的结果:
比如说,平方1.2,结果是1.2100000000000002。
平方3.4,结果是11.559999999999999。
以前在java里面也遇到过这种情形,为什么算出来是这样的结果呢,
明明是个准确值。。。
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.
In other words, some implementation of real numbers of scheme is imprecise.
Besides, I don't think Java has such problem.
You may say I'm a dreamer
but I'm not the only one...