define double constant as hexadecimal?
Hexadecimal float and double literals do exist. The syntax is 0x1.(mantissa)p(exponent in decimal) In your case the syntax would be
double x = 0x1.fffffffffffffp-1
It's not safe, but something like:
double a;
*(reinterpret_cast<uint64_t *>(&a)) = 0x3FEFFFFFFFFFFFFFL;
However, this relies on a particular endianness of floating-point numbers on your system, so don't do this!
Instead, just put DBL_EPSILON
in <cfloat>
(or as pointed out in another answer, std::numeric_limits<double>::epsilon()
) to good use.
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
int main()
{
double const x = 1.0 - numeric_limits< double >::epsilon();
cout
<< setprecision( numeric_limits< double >::digits10 + 1 ) << fixed << x
<< endl;
}