|
Boost : |
Subject: Re: [boost] New Boost.XInt Library, request preliminary review
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2010-03-28 18:11:05
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/28/2010 04:50 PM, Scott McMurray wrote:
> What operations result in NaNs, anyways?
Copying from the documentation:
- ---------------------8<----------------------
To create a Not-a-Number, use the integer constructor that exists solely
for that purpose. No other library function will return a Not-a-Number
except under the following circumstances:
* If a function that returns a non-reference integer tries to throw a
blockable exception, but exceptions are blocked;
* If the string-to-integer functions are asked to convert the string
"#NaN#";
* If you call the function invmod, and there is no valid inverse;
* If you call the function random_prime with a callback, and the
callback function cancels it.
- ---------------------8<----------------------
> Are there any whose preconditions can't be trivially checked?
If you know your modular math, and never block exceptions, then no.
> The only ones that come to mind are checking for 0 before division
> and checking for negatives before taking a square root, both of which
> are just as easily checked outside the operation as inside it.
Hm... you're right, taking the square root of a negative number *should*
throw an exception. The library presently (and erroneously) returns
zero. Thanks for the accidental catch. ;-)
> So I'd say just throw instead of generating the NaN in the first
> place. With unbounded integers there's no underflow or overflow to
> worry about, so the advantage of the special values is questionable.
> (And I could make a wrapper to add the special values -- NaN, +Inf,
> -Inf, 1/+Inf, 1/-Inf -- if I needed.)
As mentioned in my last response to Jeffrey Hellrung, the NaN value is
returned when the library needs to throw a blockable exception, but
exceptions are blocked. Throwing an exception in that case is exactly
what I *don't* want to do.
- --
Chad Nelson
Oak Circle Software, Inc.
*
*
*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkuv0/kACgkQp9x9jeZ9/wQA8gCgrxkYowV1b/7ZEkFVtPPqXhvP
2oYAnjY2BmDuELhqpz5OdA0RpPQvPOb2
=QNcb
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk