Boost logo

Boost :

Subject: Re: [boost] New Boost.XInt Library, request preliminary review
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-03-29 20:42:21


On 29 March 2010 02:32, Chad Nelson <chad.thecomfychair_at_[hidden]> wrote:
>
> Not completely. There *are* the two functions that return Not-a-Number
> as part of their normal operation, not counting the string- and
> stream-reading functions. As I said on the rationales page of the
> documentation, I tried using Boost.Optional for those, but it made the
> library harder for people not already familiar with Boost.Optional to
> understand. An error code is an idiom that every C or C++ developer
> already understands well and knows how to deal with.
>

Those two functions, invmod and random_prime, can use xint() as their
error code, if the relevant exception is blocked, since 0 is obviously
neither a multiplicative inverse or a prime. That even lets you use
them like error codes:

    xint z = invmod(x, y);
    if (z) { ... worked ... }
    else { ... no inverse exists ... }

Though personally I think I'd still prefer an exception. If I'm doing
RSA and there's no inverse, something has gone drastically wrong.


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