5 ms·
With the help of your comments, I could now write the conclusion to my article. In a nutshell this is the solution: #include <math.h> #include <fenv.h>
by mulle_nat 7y ago
With the help of your comments, I could now write the conclusion to my article. In a nutshell this is the solution:
#include <math.h>
#include <fenv.h>
int fits_long( double d)
{
long l_val;
double d_val;
// may be needed ?
// #pragma STDC FENV_ACCESS ON
feclearexcept( FE_INVALID);
l_val = lrint( d);
d_val = (double) l_val;
if( fetestexcept( FE_INVALID))
return( 0);
return( d_val == d);
}
The article explains it in more detail. Thanks for the help.