On Wednesday, 10 June 2015 17:51:01 UTC+3, Peng Yu wrote:
> I don't find how to express signed zeros in C++/C.
> Does anybody know what is the proper way to do so? Are they
> just -0.0 and +0.0?
In C++ '-0.0' and '+0.0' are not 'double' literals by
its parsing rules.
These are expressions where unary minus or plus
operators are applied to 'double' literal '0.0'.
What such floating point arithmetic does (like those
unary operators) is not regulated by C or C++
standard. It is left implementation-specific.
Target platform may for example (and often does)
follow IEC 559/IEEE 754 standard of floating point
arithmetic. You can check if it does with
'std::numeric_limits<double>::is_iec559'. It works
compile-time so you can 'static_assert' if your code
assumes that it does.
#include <iostream>
#include <limits>
int main()
{
std::cout << (std::numeric_limits<double>::is_iec559
? "double follows IEEE 754 on your platform"
: "RTFM about double on your platform") << '\n';
double someZero = -0.0;
std::cout << "Some zero:" << someZero << '\n'
<< "Some zero negated:" << -someZero << std::endl;
return 0;
The link that you posted answers that question.
Can't you read it? Either use 'copysign' from <cmath>
or see if '1/someZero' produces negative or positive
infinity.