“双精度浮点格式"的准确性如何? [英] How accurate is "double-precision floating-point format"?

查看:138
本文介绍了“双精度浮点格式"的准确性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我使用Java输入

Let's say, using java, I type

双数;

如果我需要使用非常大或非常小的值,它们的精度如何? 我试图阅读双打和浮球的工作原理,但我并没有真正理解它.

If I need to use very big or very small values, how accurate can they be? I tried to read how doubles and floats work, but I don't really get it.

对于我的编程入门学期项目,我可能需要使用具有较大价值范围(许多数量级)的不同数字.

For my term project in intro to programming, I might need to use different numbers with big ranges of value (many orders of magnitude).

假设我创建了一个while循环,

Let's say I create a while loop,

while (number[i-1] - number[i] > ERROR) {
     //does stuff
}

ERROR的限制是否取决于数字[i]的大小?如果是这样,如何确定ERROR才能退出循环?

Does the limitation of ERROR depend on the size of number[i]? If so, how can I determine how small can ERROR be in order to quit the loop?

我知道老师有时会对此进行解释,但是我似乎无法在笔记中找到它.

I know my teacher explained it at some point, but I can't seem to find it in my notes.

推荐答案

ERROR的限制是否取决于数字[i]的大小?

Does the limitation of ERROR depend on the size of number[i]?

是的

如果是这样,我如何确定ERROR的大小才能退出循环?

If so, how can I determine how small can ERROR be in order to quit the loop?

您可以使用 Math.nextUp (或使用Math.nextDown的下一个最小"),例如

You can get the "next largest" double using Math.nextUp (or the "next smallest" using Math.nextDown), e.g.

double nextLargest = Math.nextUp(number[i-1]);
double difference = nextLargest - number[i-1];

Radiodef 指出,您还可以直接使用

As Radiodef points out, you can also get the difference directly using Math.ulp:

double difference = Math.ulp(number[i-1]);

(但是我认为下一个最小的"没有等效的方法)

(but I don't think there's an equivalent method for "next smallest")

这篇关于“双精度浮点格式"的准确性如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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