Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distinguish zero and negative zero

I have run into a situation in my code where a function returns a double, and it is possible for this double to be a zero, a negative zero, or another value entirely. I need to distinguish between zero and negative zero, but the default double comparison does not. Due to the format of doubles, C++ does not allow for comparison of doubles using bitwise operators, so I am unsure how to procede. How can I distinguish between the two?

like image 338
Dan Brenner Avatar asked Jan 06 '14 09:01

Dan Brenner


1 Answers

Call std::signbit() to determine the state of the sign bit.

like image 166
David Heffernan Avatar answered Sep 21 '22 20:09

David Heffernan