std:numeric_limits<double>::epsilon definition
numeric_limits::espilon
returns the difference between 1 and the next double. So, should I understand that the distance between two adjacent doubles is not always the same, for instance between 2 and the next double?
And if yes could I have a piece of explanation 开发者_如何学C?
The "density" of floating-point numbers decreases a lot as you get farther away from zero.
This is because IEEE floating-point is stored essentially as scientific notation, so range is favored over uniform precision. (If it was uniform precision, it would be fixed-point, not floating-point.)
In other words, numbers are stored in the form Significand * 2exponent, so if the exponent gets large, a small change in the significand produces a large change in the number (and vice-versa).
So no, you can't assume that the difference between 2 and the next double is the same as epsilon; it isn't.
Doubles are floating point numbers. They consist of a signum, a significand and an exponent.
The higher the exponent, the larger the difference between a double and its successor.
The lower the exponent, the smaller the difference between a double and its successor.
精彩评论