Math Signbit Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Signbit Function

Math Signbit Function

BLUF: Mastering Math Signbit Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Signbit Function

C++ is renowned for its efficiency. Learn how Math Signbit Function enables low-level control and high-performance computing in the tutorial below.

C++ Math signbit

The function determines if a provided number is negative by checking its sign. It will output 1 if the number is negative, otherwise it will output 0.

The signbit function is applicable to infinite, NAN, and zero values as well.

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 when the value of x is negative; otherwise, it returns 0, indicating a non-negative value.

Example 1

Let's examine a straightforward instance where the value assigned to 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 instance, the signbit(x) function identifies the positivity of the value of x, resulting in a return value of 0.

Example 2

Let's examine a straightforward scenario where the value assigned to 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 instance, the signbit(x) function identifies whether the value of x is negative, and subsequently, it outputs 1.

Example 3

Let's examine a straightforward scenario where the value of x is unbounded.

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 instance, the signbit(x) function identifies that the value of x represents positive infinity, resulting in a return value of 0.

Input Required

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

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience