The mathematical concept of zero has no sign. It's neither positive nor negative (or if you prefer, it's both). The concept of a signed zero is used in floating-point numbers to represent a value that's so small that it can't be distinguished from zero, but which may not be an actual zero. Such a non-zero number does have a sign. But mathematically, a negative zero is simply zero.
However, the XInt library does have limited support for a "negative zero," for use in a planned future unlimited-precision floating point library built on it. To get a negative zero, negate a normal zero value with the unary minus, like so:
integer z = ... integer nz = -z;
A negative zero will act exactly like a "normal" zero in all respects. The only way to detect a sign on it is by calling the sign function with the signed_zero
parameter true
. With that parameter, it will return -1 on any negative number, including zero.
Note that the unary minus operator is the only function that will ever return a negative zero.
© Copyright Chad Nelson, 2010-2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)