Java - 一次双加/减的最大精度损失 [英] Java - maximum loss of precision in one double addition/subtraction

查看:117
本文介绍了Java - 一次双加/减的最大精度损失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java(加/减)中处理两个 double 值时,是否可以建立甚至大致的最大精度损失?可能最糟糕的情况是当两个数字不能被精确地表示,然后对它们执行一个操作,这将导致一个值也不能被精确地表示。

Is it possible to establish, even roughly, what the maximum precision loss would be when dealing with two double values in java (adding/subtracting)? Probably the worst case scenario is when two numbers cannot be represented exactly, and then an operation is performed on them, which results in a value that also cannot be represented exactly.

推荐答案

看看 Math.ulp(double) double ulp 是下一个最高值的增量。例如,如果你添加到数字,而一个小于另一个的ulp,那么你知道这个添加将不起作用。如果您乘以两个双打,您可以乘以其溃疡,以获得结果的最大错误。

Have a look at Math.ulp(double). The ulp of a double is the delta to the next highest value. For instance, if you add to numbers and one is smaller than the ulp of the other, you know that the addition will have no effect. If you multiply two doubles, you can multiply their ulps to get the maximum error of the result.

这篇关于Java - 一次双加/减的最大精度损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆