Boost logo

Boost :

Subject: Re: [boost] New Boost.XInt Library, request preliminary review
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-04-02 15:43:55

Chad Nelson wrote:
> On 04/02/2010 02:32 PM, Jeffrey Hellrung wrote:
>> Don't forget (assuming a single unsigned 0):
>> x / 0 => NaN
> Eh? I thought we'd decided that anything divided by zero, other than
> zero itself, was infinity (or negative infinity, if x is negative)?

Of course you can define whatever arithmetic you like, but I think it
makes more sense for products and quotients of like signs being
positive, of opposite signs being negative, and anything involving
(unsigned) zero giving either (unsigned) zero or NaN.

>> Another topic: Chad, how natural is it, implementation-wise, to have a
>> signed zero? I'm guessing you have a sign bit, leading naturally to
>> either providing both a +0 or a -0, or ensuring after each operation
>> that -0 is normalized to +0.
> It wouldn't be a problem to implement it, and yes, I do have a sign bit
> (or rather, a sign Boolean, but that's essentially the same thing).
>> What are the arguments against a signed zero?
> That there's no need for it in an integer library.
> As such, there's no real need for it in XInt.

I was looking more for objections based purely on logical
inconsistencies. Can you think of any?

>> Is it possible to simply be agnostic to the sign bit when the
>> mantissa is 0?
> Isn't that the same as saying that -0 is identical to +0?

If you don't have any infinities or NaNs to worry about, yes! For this
case, I'm just suggesting you may not have to normalize zeros if -0
behaves exactly the same as +0. But it still may be useful to
distinguish between them for libraries built on top of the core
implementation. An arbitrary-precision floating point type may make a
distinction between +0 and -0, and it would be convenient if the
underlying integer core allowed this distinction naturally.

Additionally, in the presence of an infinity value, you can then say

x / +0 = +infinity
x / -0 = -infinity

if x > 0. Other than that (and maybe a few more exceptional cases), +0
and -0 behave identically. This has the (minute) advantage that you
have simpler sign relationships on divisions:

+ / + = - / - = +
+ / - = - / + = -
NaN / x = x / NaN = NaN

This really only makes sense if your natural representations for +0 and
-0 naturally behave identically, thus incurring no overhead (and perhaps
simplifying implementation by avoiding a renormalization to "+0").

What do you think?

- Jeff

Boost list run by bdawes at, gregod at, cpdaniel at, john at