Is it right to say that the first number that comes up with uniform accuracy is 131072.02? (positive, given 2 digits as the mantissa)

I tried to figure this out for my audio application, if I floatcan use it to correctly represent the range of parameters that I will use.

The “biggest” mask that it needs is frequency parameters that are positive and allow a maximum of two digits as a mantissa (ie from 20.00 to 22000.00 Hz). Conceptually, the following numbers will be rounded, so I don’t care.

So, I made this script to check the first number that comes up with one precision:

float temp = 0.0;
double valueDouble = 0.0;
double increment = 1e-2;

bool found = false;
while(!found) {
    double oldValue = valueDouble;
    valueDouble += increment;
    float value = valueDouble;

    // found
    if(temp == value) {
        std::cout << "collision found: " << valueDouble << std::endl;
        std::cout << "   collide with: " << oldValue << std::endl;
        std::cout << "float stored as: " << value << std::endl;
        found = true;
    }

    temp = value;        
}

131072.02 ( 131072.01, 131072.015625), 22000.00. , float.

, . ?

, XXXXX.YY(7 digits) , ( single precision 6 digits)

: , 1024.0002998145910169114358723163604736328125 1024.000199814591042013489641249179840087890625, , , , , .

+4
2

IEEE 754

  • 1
  • 8 : 2 ^ -126 2 ^ 127 ~ 10 ^ -38 10 ^ 38)
  • 23 (mantissa) : )

22k 16384 = 2 ^ 14, 23- 2 ^ 14/2 ^ 23 = 1/2 ^ 9 = 0,001953125... .

131072.01 131072 = 2 ^ 17, 2 ^ 17/2 ^ 23 = 1/2 ^ 6 = 0,015625, , 0,01

+3

, , .

, valueDouble ( 0.01 ) - "20.01" .

DBL_EPSILON , .

, "20.00" "22000.00" , scanf, , , .

+1

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


All Articles