C programming math.h signbit


In C programming the <math.h> signbit() function determine if the ‘sign‘ of the argument is negative.The declaration of the ‘signbit’ functions are given below.

bool signbit(float x);
bool signbit(double x);
bool signbit(long double x);

Parameters:
x -A floating point value whose sign is to be determined.

Return type
bool -Returns true if the sign is negative.

All the three functions are the same.The only difference between than is the type of argument accepted by the function.

The sign determination is not limited to only normal values(integer and floating point value) but it can also determine the sign of NaN,infinity,subnormal,0.It can determine the sign of all types of values.

Code example

double d1=12 , d2=-182 ;

printf( “%i”, signbit( d1 ) );
printf( “\n%i”, signbit( d2 ) );
printf( “\n%i”, signbit( -0.0 ) );
printf( “\n%i”, signbit( -INFINITY ) );

Output,

0
1
1
1

‘INFINITY’ is the macro that represent the infinite value.