本文介绍了为什么我的double值可以包含低于机器epsilon的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用双精度求解方程,并且得到了-7.07649e-17而不是0的解决方案.

I was solving an equation using double precision and I got -7.07649e-17 as a solution instead of 0.

我同意它已经足够接近,可以说它相等了,但是我已经阅读了该机器C ++双重类型的epsilon是2^-52 ,它大于我得到的值.

I agree it's close enough that I can say it's equal but I've read that the machine epsilon for the C++ double type is 2^-52 which is larger than the value I get.

那么为什么我的价值不如机器epsilon?为什么值不能四舍五入?

So why do I have an inferior value than the machine epsilon?Why isn't the value rounded to zero?

这没什么大不了的,但是当我进行逻辑测试时,我的值似乎不为零...

It's not a big deal but when I do a logical test it appears that my value is not zero...

推荐答案

这个故事有两个不同的常量.一个是epsilon,这是一个最小值,当添加到1.0时会产生不同于1.0的值.如果将较小的值添加到1.0,您将再次得到1.0,因为计算机中数字表示存在物理限制.但是有些值小于epsilon但大于零.对于通过std::numeric_limits<double>::min获得的double,此类数字最小.

There are two different constants in this story. One is epsilon, which is a minimal value that when added to 1.0 produces a value different from 1.0. If you add a smaller value to 1.0 you will again get a 1.0, because there are physical limits to the representation of a number in a computer. But there are values that are less than epsilon and greater than zero. Smallest such number for a double you get with std::numeric_limits<double>::min.

作为参考,您将获得带有std::numeric_limits<double>::epsilon的epsilon.

For reference, you get epsilon with std::numeric_limits<double>::epsilon.

这篇关于为什么我的double值可以包含低于机器epsilon的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 04:47