0

As the title mentioned, why is the result of boost::math::float_distance(1.0, 0.0), which is -4.60718e+18, so big?

According to this definition about ULP: In general, if the floating-point number d.d...d × e is used to represent z, then it is in error by d.d...d - (z/e)p-1 units in the last place. Source: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

The result shouldn't be such a big number, isn't it?

Hot
  • 3
  • 3
  • Could you post the code you're testing with, please? – Ja_cpp Dec 22 '17 at 08:39
  • I'm just a rookie to float point approximation and want to test the properties of boost::math::float_distance. The code is: int main() { std::cout << float_distance(1.0, 0.0) << std::endl; return 0} @Ja_cpp – Hot Dec 22 '17 at 08:42
  • Can't find the dupe, right now, but if you multiply all the possible values representable by a 52 bit significand (in a IEEE754 64-bit double), which is 2^52 = 4.5E15 times 1023 (the difference between the exponents in the same representation), you get that number. – Bob__ Dec 22 '17 at 09:12
  • Thanks, @Bob__ ,I find it. It's the total distinct numbers of double between [0.0, 1.0], which is the difference between pow(2, 62) - pow(2, 52) – Hot Dec 22 '17 at 09:24

0 Answers0