Consider the following C++ code:
double someZero = 0; std::cout << 0 - someZero << '\n'; // prints 0 std::cout << -someZero << std::endl; // prints -0
The question arises: what is negative zero good for, and should it be defensively avoided (i.e. use subtraction instead of smacking a minus onto a variable)?
One may obtain negative zero as the result of certain computations, for instance as the result of arithmetic underflow on a negative number (other results may also be possible), or −1.0×0.0 , or simply as −0.0 .
There's no such thing as negative zero. For a binary integer, setting the sign bit to 1 and all other bits to zero, you get the smallest negative value for that integer size. (Assuming signed numbers.) Negative zero is actually used in mathematical analysis, especially in limit calculations.
Floating point numbers can be positive or negative. Ethereal provides two types of floating point numbers: regular floating point numbers, and double-precision floating point numbers.
Actually, zero is neither a negative or a positive number. The whole idea of positive and negative is defined in terms of zero. Negative numbers are numbers that are smaller than zero, and positive numbers are numbers that are bigger than zero.
From Wikipedia:
It is claimed that the inclusion of signed zero in IEEE 754 makes it much easier to achieve numerical accuracy in some critical problems[1], in particular when computing with complex elementary functions[2].
The first reference is "Branch Cuts for Complex Elementary Functions or Much Ado About Nothing's Sign Bit" by W. Kahan, that is available for download here.
One example from that paper is 1/(+0)
vs 1/(-0)
. Here, the sign of zero makes a huge difference, since the first expression equals +inf
and the second, -inf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With