C Standard Library

C <math.h> - signbit()



The C <math.h> signbit() macro returns true if the given argument is negative, else returns false. This can be also applied to infinity, NaN and zero (if zero is unsigned, it is considered positive).

Syntax

signbit(x)           

Parameters

x Specify a floating-point value.

Return Value

Returns true (non-zero value) if the argument is negative, else returns false (zero value).

Example:

The example below shows the usage of signbit() macro.

#include <stdio.h>
#include <math.h>
 
int main (){

  printf("signbit(10.5): %d\n", signbit(10.5));
  printf("signbit(1.0/0.0): %d\n", signbit(1.0/0.0));
  printf("signbit(-1.0/0.0): %d\n", signbit(-1.0/0.0));
  printf("signbit(sqrt(-1.0)): %d\n", signbit(sqrt(-1.0)));
  return 0;
}

The output of the above code will be:

signbit(10.5): 0
signbit(1.0/0.0): 0
signbit(-1.0/0.0): 128
signbit(sqrt(-1.0)): 128

❮ C <math.h> Library