What is signbit in C?

The signbit function in C determines whether a floating-point number is negative.

The signbit of a negative number is set as 1

This function checks if the given number’s signbit is set.

Library

The signbit function can be accessed via the math.h library.

#include <math.h>

Parameters

The signbit function only takes one parameter: the floating-point number that needs to be ascertained as negative.

Syntax

The syntax for the function call is:

int returned_val = signbit(x);

Return value

The function will return 0 if the floating-point parameter is non-negative (i.e., the signbit is not set). Otherwise, the number is negative and a non-zero number is returned.

Code

#include <stdio.h>
#include <math.h>
int main() {
double num1 = 1.2;
double num2 = -1.2;
// signbit returns 0
printf("num1 is %s\n", signbit(num1)? "negative" : "not negative");
// signbit returns non-zero number
printf("num2 is %s\n", signbit(num2)? "negative" : "not negative");
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved