How to use signbit() function to determine if a given floating point number is negative in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	cout << "signbit(+0.0) = " << signbit(+0.0) << endl;
	cout << "signbit(-0.0) = " << signbit(-0.0) << endl;
	cout << "signbit(3.0 / 1.0) = " << signbit(3.0 / 1.0) << endl;
	cout << "signbit(-3.0 / 1.0) = " << signbit(-3.0 / 1.0) << endl;

	return 0;
}

// Return value: non-zero (true) if the sign of N is negative, ​0​ otherwise

/*
run:

signbit(+0.0) = 0
signbit(-0.0) = 1
signbit(3.0 / 1.0) = 0
signbit(-3.0 / 1.0) = 1

*/

 



answered Mar 29, 2016 by avibootz
...