How to find out dynamic dynamics with floating point?

Due to the difficulty with which the machine accurately represents floating point values, we use the technique from Write Great Code: Understanding the machine to perform floating point comparisons:

from the editor: please insert your code here. See HTML comment in the question source 

Currently, we have hardcoded the "error" value. But the error is different on different machines. Is there any good way to find out the error for a particular machine instead of hard tolerance coding?

+3
source share
4 answers

64- IEEE 754 , , 1.0 + e != 1.0 e = 2.2204460492503131e-016. (DBL_EPSILON float.h C, std::numeric_limits<double>().epsilon() <limits> ++). , , 64- IEEE 754.

, , . , 1e-300 + 2e-300 , 1 + 1e-300 == 1. 1e30 + 1 == 1e30.

+3

, , , . , . , , ,

  • , .
  • , !
  • : epsilon , . 0 , , 2 ^ 300. , , epsilon. Sinan Unur, , , , , , .
  • , !
+3

" ", , epsilon.

, - *:

float number = 1.0;      // precision of this number
float epsilon = 1.0;

while ((number + epsilon) != number)
{
    epsilon /= 2.0f;
}

(*This is off the top of my head. Don't use this code without checking.)

.

.

And one more here: Floating point: precision machine with theory and equations for calculating epsilon.

+1
source

Source: https://habr.com/ru/post/1714834/


All Articles