C++ cmath fpclassify

int fpclassify(float x );
int fpclassify(double x );
int fpclassify(long double x);

The cmath fpclassify macro classifies its argument value as NaN,infinite,normal,subnormal,zero or into another implementation-defined category.

x -The value whose type is to be checked for.

Return type
int -Returns the value of the number classification macro appropriate to the value of its argument.

Some points to note:

 i) If any,argument is represented in a format wider than its semantic type,it is converted to its semantic type.Then classification is based on the type of the argument.This simply means if the value passed as argument has a precision and range wider than the type than it might be converted to the appropriate type first.Sometimes a normal long double type might become subnormal if converted to double type or 0 when converted to float type.

 ii) The value specifying each type is compiler dependent and it will vary from compiler to compiler.For instance,MinGW/Code::Blocks gives 1024 for normal type but,Visual Studio compiler gives -1.Do check out the value for your compiler.

 iii) If int type is passed as parameter the double version is called or another appropriate function may be called depending on your compiler.

Code example

float f=90;

cout<< “fpclassify(90)=” << fpclassify(f) << endl ;

/*Passing INFINITY */
cout<< “fpclassify(INFINITY)=” << fpclassify(INFINITY) << endl ;

/*Passing NAN */
cout<< “fpclassify(NAN)=” << fpclassify(NAN) << endl ;

Output in Code::blocks

fpclassify(90)= 1024
fpclassify(INFINITY)= 1280
fpclassify(NAN)= 256

Output in Visual Studio

fpclassify(90)= -1
fpclassify(INFINITY)= 1
fpclassify(NAN)= 2