4 ms·
That would allow a double with a fractional part to return true though, which is not the intention. If you do this before the casted comparison, the cast should
by mulle_nat 7y ago
That would allow a double with a fractional part to return true though, which is not the intention. If you do this before the casted comparison, the cast shouldn't produce an undefined value.
I think this is a good solution without using the math library and having
access to the FP status registers. Otherwise the lrint solution seems better.
int fits_long(double value)
{
double max = (double) (1L << 52)
double min = (double) -max;
if( min <= value && value <= max)
return( (double) (long) value == value);
return( 0);
}