Reputation: 4335
In Visual C++ 2010, I tried this
double d= DBL_MAX;
double dblmaxintpart;
modf(DBL_MAX, &dblmaxintpart);
In the debugger window I put
d == dblmaxintpart
which gave true as result.
Can I assume that DBL_MAX is equal to its integer part as an always valid assertion?
Upvotes: 1
Views: 346
Reputation: 41503
Yes, the integer part of a double
which represents an integer will always be the double
itself, even at DBL_MAX
. In fact, any double
greater than 2^52 will have itself as an integer part, because doubles of that size don't have enough mantissal bits to represent a fraction.
For similar reasons, not all integers above 2^53 are representable as double
s (though when converted to double
s, they will still be integers).
Finally, the fractional part of any double
less than 1 will be exactly itself, and the fractional and integer parts of any double
, when added, will produce exactly the original double
.
Upvotes: 3