为什么在JAVA中 
0.2d*0.2d的输出结果是0.04000000000000001
0.2f*0.2f的输出结果是0.040000003

另外在API帮助文档里,Math类的说明:
实现规范的质量涉及到两种属性,即返回结果的准确性和方法的单调性。浮点 Math 方法的准确性根据 ulp(units in the last place,最后一位的进退位)来衡量。对于给定的浮点格式,特定实数值的 ulp 是包括该数值的两个浮点值的差。当作为一个整体而不是针对具体参数讨论方法的准确性时,引入的 ulp 数用于任何参数最差情况下的误差。如果一个方法的误差总是小于 0.5 ulp,那么该方法始终返回最接近准确结果的浮点数;这种方法就是正确舍入。一个正确舍入的方法通常能得到最佳的浮点近似值;然而,对于许多浮点方法,进行正确舍入有些不切实际。相反,对于 Math 类,某些方法允许误差在 1 或 2 ulp 的范围内。非正式地,对于 1 ulp 的误差范围,当准确结果是可表示的数值时,应该按照计算结果返回准确结果;否则,返回包括准确结果的两个浮点值中的一个。对于值很大的准确结果,括号的一端可以是无穷大。除了个别参数的准确性之外,维护不同参数的方法之间的正确关系也很重要。因此,大多数误差大于 0.5 ulp 的方法都要求是半单调的:只要数学函数是非递减的,浮点近似值就是非递减的;同样,只要数学函数是非递增的,浮点近似值就是非递增的。并非所有准确性为 1 ulp 的近似值都能自动满足单调性要求。 到底是什么意思?
有朋友帮忙解释一下吗?谢谢啦!

解决方案 »

  1.   

    public final class Mathextends ObjectThe class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Unlike some of the numeric methods of class StrictMath, all implementations of the equivalent functions of class Math are not defined to return the bit-for-bit same results. This relaxation permits better-performing implementations where strict reproducibility is not required. By default many of the Math methods simply call the equivalent method in StrictMath for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of Math methods. Such higher-performance implementations still must conform to the specification for Math. The quality of implementation specifications concern two properties, accuracy of the returned result and monotonicity of the method. Accuracy of the floating-point Math methods is measured in terms of ulps, units in the last place. For a given floating-point format, an ulp of a specific real number value is the distance between the two floating-point values bracketing that numerical value. When discussing the accuracy of a method as a whole rather than at a specific argument, the number of ulps cited is for the worst-case error at any argument. If a method always has an error less than 0.5 ulps, the method always returns the floating-point number nearest the exact result; such a method is correctly rounded. A correctly rounded method is generally the best a floating-point approximation can be; however, it is impractical for many floating-point methods to be correctly rounded. Instead, for the Math class, a larger error bound of 1 or 2 ulps is allowed for certain methods. Informally, with a 1 ulp error bound, when the exact result is a representable number, the exact result should be returned as the computed result; otherwise, either of the two floating-point values which bracket the exact result may be returned. For exact results large in magnitude, one of the endpoints of the bracket may be infinite. Besides accuracy at individual arguments, maintaining proper relations between the method at different arguments is also important. Therefore, most methods with more than 0.5 ulp errors are required to be semi-monotonic: whenever the mathematical function is non-decreasing, so is the floating-point approximation, likewise, whenever the mathematical function is non-increasing, so is the floating-point approximation. Not all approximations that have 1 ulp accuracy will automatically meet the monotonicity requirements. Since: 
    JDK1.0 
      

  2.   

    double*(double/float)=double,
    float*float=float
    查看各种数据类型之间的运算后的数据类型是什么,自然会很清楚,数据的二进制的表示法,那就再清楚不过的,参考API 的类 BigDecimal