C++ Math signbit()
The function checks whether the sign of a given number is negative or not. If the sign of a number is negative, it returns 1 otherwise 0.
The signbit() function can also be applied to infinite, NAN and zero value.
Syntax
Suppose a number is ‘x’.Syntax would be:
Parameter
x: It is a floating point value.
Return value
It returns 1, if the value of x is negative otherwise 0(false).
Example 1
Let’s see the simple example when the value of x is 9.
Output:
value of x is :9 signbit(x) : 0
In this example, signbit(x) function determines that the value of x is positive. Therefore, it returns 0.
Example 2
Let’s see the simple example when the value of x is -2.
Output:
value of x is : -2 signbit(x) : 1
In this example, signbit(x) function determines that the value of x is negative. Therefore, it returns 1.
Example 3
Let’s see the simple example when the value of x is infinite.
Output:
value of x is : inf signbit(x) : 0
In this example, signbit(x) function determines that the value of x is positive infinite. Therefore, it returns 0 value.