Math Signbit Function

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:

Example

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

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.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
   int x=9;
   cout<<"value of x is :"<<x<<'\n';
   cout<<"signbit(x) : "<<signbit(x);
   return 0;
}

Output:

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.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
   int x= -2;
   cout<<"value of x is : "<<x<<'\n';
   cout<<"signbit(x) : "<<signbit(x);
   return 0;
}

Output:

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.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
  float x=11.0/0.0;
  cout<<"value of x is : "<<x<<'\n';
  cout<<"signbit(x) : "<<signbit(x);
  return 0;
}

Output:

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.

Input Required

This code uses input(). Please provide values below: