4

This might be a silly question, but I really have an issue here with 0 and minus 0.

I am calculating a slope of a function and depending on the vector ( right or left ) it is 0 or -0.

Is it possible to do a if condition and find out if the slope is 0 or -0 ? Doing the below doesnt work.

if ( slope == 0.0f )
std::cout << "direction vector towards right";
else if ( slope == -0.0f )
std::cout << "direction vector towards left"

I deliberatly didnt put working source code, because I think it is irrelevant for the question. A simple answer for the above will help.

infoclogged
  • 3,641
  • 5
  • 32
  • 53

1 Answers1

10

You're looking for std::signbit. Both zeroes are equal to each other so your check doesn't work, but the signbit is different.

MSalters
  • 173,980
  • 10
  • 155
  • 350