dbl_max -dbl_min等于dbl_min多长时间

发布于 2025-01-23 00:21:46 字数 227 浏览 2 评论 0原文

我在图书馆和其他一些内容中遗漏了阅读,但是我想知道下面的代码要花多长时间,我在15分钟后停止了它,因为我的计算机认为这是一种病毒。

int main(){

double min = __DBL_MIN__;
double current = __DBL_MAX__;

while ( current > min ){

    current = current - min;
}

I left out reading in the libraries and some other stuff, but I was wondering how long the code below would take to run, I stopped it after like 15 mins because my computer thought it was a virus.

int main(){

double min = __DBL_MIN__;
double current = __DBL_MAX__;

while ( current > min ){

    current = current - min;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅渡 2025-01-30 00:21:46

永远。
当前 - 最小回合当前

带有浮动的浮点数存储值显着。不要期望指数值在指数值上具有极端差异的值可以准确地执行扣除。

Forever.
current - min rounds to current.

Floating point numbers store value with a floating significand. Do not expect values with an extreme difference in exponential value to perform a subtraction exactly.

始终不够爱げ你 2025-01-30 00:21:46

要在 @chux的(正确)上展开一些答案:

典型的double将具有大约10 -308 到10 +308 的正数范围sup>。但是它只有大约16个重要数字。

这意味着对于一个接近10 +308 的数字,您可以减去更改值的最小数字约为10 (308-16) = 10 292 < /sup>。

这只是一个粗糙的近似值,但是附近的某个地方是下限,并且任何小于该限制的数字都可以从10 308 中减去,并且结果将保持不变。

To expand a bit on @chux's (correct) answer:

A typical double will have a range of positive numbers from approximately 10-308 to 10+308. But it will only have around 16 significant digits.

That means for a number near 10+308, the smallest number you can subtract that will change the value is approximately 10(308-16) = 10292.

That's only a rough approximation, but somewhere in that vicinity is a lower limit, and any number smaller than that limit can be subtracted from 10308 as often as you like, and the result will remain unchanged.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文