dbl_max -dbl_min等于dbl_min多长时间
我在图书馆和其他一些内容中遗漏了阅读,但是我想知道下面的代码要花多长时间,我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
永远。
当前 - 最小
回合当前
。带有浮动的浮点数存储值显着。不要期望指数值在指数值上具有极端差异的值可以准确地执行扣除。
Forever.
current - min
rounds tocurrent
.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.
要在 @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.