#include <cstdint>
#include <cmath>
#include <iostream>
template <int32_t B, int32_t E>
struct Pow {
static int32_t const value = Pow<B,E-1>::value * B;
};
template <int32_t B>
struct Pow<B,0> {
static int32_t const value = 1;
};
template <int8_t E>
struct AcceptableError {
static double const value = 1.0 / Pow<10,E>::value;
};
template <typename Error = AcceptableError<1> >
class Double {
private :
double num;
public:
Double( double value ) : num( value ) { }
bool equals ( Double const & rhs ) const {
return fabs (num - rhs.num ) < Error::value;
}
};
int main() {
using namespace std;
Double<> a( 1e-1 ), b( 1e-2 );
cout << boolalpha << a.equals(b) << endl;
Double< AcceptableError<8> > c( 1e-1 ), d( 1e-2 );
cout << boolalpha << c.equals(d) << endl;
}
I2luY2x1ZGUgPGNzdGRpbnQ+CiNpbmNsdWRlIDxjbWF0aD4KCiNpbmNsdWRlIDxpb3N0cmVhbT4KCnRlbXBsYXRlIDxpbnQzMl90IEIsIGludDMyX3QgRT4Kc3RydWN0IFBvdyB7CiAgIHN0YXRpYyBpbnQzMl90IGNvbnN0IHZhbHVlID0gUG93PEIsRS0xPjo6dmFsdWUgKiBCOwp9OwoKdGVtcGxhdGUgPGludDMyX3QgQj4Kc3RydWN0IFBvdzxCLDA+IHsKICAgc3RhdGljIGludDMyX3QgY29uc3QgdmFsdWUgPSAxOwp9OwoKdGVtcGxhdGUgPGludDhfdCBFPgpzdHJ1Y3QgQWNjZXB0YWJsZUVycm9yIHsKICAgc3RhdGljIGRvdWJsZSBjb25zdCB2YWx1ZSA9IDEuMCAvIFBvdzwxMCxFPjo6dmFsdWU7Cn07CgoKdGVtcGxhdGUgPHR5cGVuYW1lIEVycm9yID0gQWNjZXB0YWJsZUVycm9yPDE+ID4KY2xhc3MgRG91YmxlIHsKcHJpdmF0ZSA6CiAgIGRvdWJsZSBudW07CgpwdWJsaWM6CgogICBEb3VibGUoIGRvdWJsZSB2YWx1ZSApIDogbnVtKCB2YWx1ZSApIHsgfQoKICAgYm9vbCBlcXVhbHMgKCBEb3VibGUgY29uc3QgJi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