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;
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, , , , , .