1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iomanip>
#include <iostream>
#include <boost/math/special_functions/fpclassify.hpp>
using namespace std;
void display( const char* name, double d )
{
cout << left << setw( 16 ) << name << " : ";
cout << ((boost::math::isnan)( d ) ? "NaN" : " ") << ", ";
cout << ((boost::math::isinf)( d ) ? ((d < 0) ? "-INF" : "+INF") : " ") << ", ";
cout << ((boost::math::isnormal)( d ) ? "normal" : " ") << ", ";
cout << d << endl;
}
#define DISPLAY( x ) display( #x, x )
int main()
{
double not_a_number = 0.0/0.0;
double infinite_number = 5.0/0.0;
double ninfinite_number = -5.0/0.0;
double normal_number = 5.0;
cout << "NAME : ISNAN, ISINF, ISNORMAL, VALUE\n";
DISPLAY( not_a_number );
DISPLAY( infinite_number );
DISPLAY( ninfinite_number );
DISPLAY( normal_number );
return 0;
}
|
NAME : ISNAN, ISINF, ISNORMAL, VALUE
not_a_number : NaN, , , NaN
infinite_number : , +INF, , Infinity
ninfinite_number : , -INF, , Infinity
normal_number : , , normal, 5 |