Boost logo

Boost :

Subject: Re: [boost] New Boost.XInt Library, request preliminary review
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-04-02 14:07:03


On 2 April 2010 13:43, Chad Nelson <chad.thecomfychair_at_[hidden]> wrote:
>
> Yes, by that definition it's definitely a number. But it's not a
> *countable* number, which is the definition that I was using. :-) In
> relation to the XInt library, I'd say that an infinity value should also
> be counted as a not-a-number, in that an is_nan function should return
> true for it
>

Well, iirc some infinities are countable and others are not, but...

I think is_nan(Inf) should be false, but is_finite(Inf) should also be false.

>
> it's not something that can be calculated with, generally.
>
> [...]
>
> If I don't add an infinity value, I could. I'm leaning toward adding one
> (with sign), but it will act exactly like a NaN except for comparisons.
>

Actually, you *can* calculate with infinity. That's the reason for
having it separate from NaN, and why it needs a sign. Any operation
with NaN gives a NaN, but at least the following for Infs don't give
NaNs (for any x, y where is_finite(x) && !is_nan(y)):

    -(Inf) => -Inf
    -(-Inf) => Inf
    x + Inf => Inf
    x - Inf => -Inf
    x % Inf => x
    Inf + Inf => Inf
    -Inf - Inf => -Inf
    x < Inf => true
    x > -Inf => true
    y <= Inf => true
    y >= -Inf => true
    x / Inf => 0
    x / -Inf => 0
    if (y != 0) y * Inf => sign(y)Inf
    if (y != 0) y * -Inf => sign(-y)Inf

But the indeterminate forms do, of course, give NaNs:

    Inf - Inf => NaN
    -Inf + Inf => NaN
    0 * Inf => NaN
    0 * -Inf => NaN
    Inf / Inf => NaN
    Inf / -Inf => NaN
    Inf % y => NaN

Hopefully that'll make you lean further :P


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk