Boost logo

Boost :

Subject: Re: [boost] [math][distributions] superfluous checking ofparameters?
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-10-29 12:46:00

>> Why is that? It's done in a consistent way across all distributions. Can
>> we remove the check
> inside the non
>> member functions that are already checked in the constructor?
> As I recollect, I think we thought there were circumstances when this
> check wasn't redundant (but I
> can't remember the exact case. Users changes the distribution
> parameters?).
> And because it was believed better to be safe than sorry, and the check
> was very cheap (at runtime),
> we kept it that way.

The issue is like this:

* If the current policy (a template param) is to throw on domain errors (the
default), then the second check in the non-member functions is redundant as
any errors will have triggered an exception in the distribution constructor.
On the other hand:
* If the current policy is to not throw (return NaN on domain errors), then
the constructor checks are redundant and the non-member function checks are
the required ones.

If it really is a performance bottleneck, then we could add a check on the
current exception policy so that those two mutually exclusive options get
optimized at compile time.

HTH, John.

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