First, it should be noted that in the floating point IEEE754 values 1.5, 0.5and 2.0all are accurately represented. So, in this particular example it 1.5never will be 1.499999999999.
, , , , . , 1.1.
:
#include <iostream>
#include <iomanip>
int main() {
std::cout << std::setprecision(30);
double d1(1.1);
std::cout << d1 << "\n";
double d2(11);
double eps = d2/10 - d1;
std::cout << d2 << "\n";
std::cout << eps << "\n";
bool equal = (d1 == d2);
std::cout << equal << "\n";
}
, , , d1 d2 1.1.
, 1/2 , 1/10 .
: , - . 1/7 . . , 1/7 . , 1/10 , , .
, (32 ), (64 ). , , ( ) .
, , .