Imprecision

imprecision.h
1
2
3
4
5
6
7
8
#ifndef EXAMPLES_IMPRECISION_H_
#define EXAMPLES_IMPRECISION_H_

#include <iostream>

void showImprecision();

#endif /* EXAMPLES_IMPRECISION_H_ */
imprecision.cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include "imprecision.h"

using namespace std;

void showImprecision()
{
    double x = -1.0;

    while (x <= 0.0)
    {
        cout << x << " ";
        x = x + 0.1;
    }
    cout << endl;

    cout << "0.01 - 0.1 * 0.1 = " << (0.01 - 0.1 * 0.1) << endl;
}