
Boost : 
From: Eric Ford (eford_at_[hidden])
Date: 20010911 14:40:44
> I have a specific example for your consideration and suggestions
> on how this might be 'interfaced'.
We'd have to choose a function name, but something like...
template <class RetT, class ArgT = RetT, class AccuraceyCheckerT =
default_accuracey_cchecker<RetT,ArgT>, class DomainCheckerT =
default_domain_checker<ArgT>, class ErrorHandelerT =
default_error_handeler>
struct prob_std_normal
{
prob_std_normal(AccuraceyCheckerT AC = AccuraceyCheckerT(),
DomainCheckerT DC = DomainCheckerT(), ErrorHandelerT EH =
ErrorHandelerT() );
RetT operator(ArgT x) const;
}
The simplest useage would be like
double x = 3.;
double y = prob_std_normal<double>()(x);
> Attached is a tranlsation of ACM TOMS 715.f ANORM into C++.
> It does the normal distribution function.
> (NOT yet Boostified before anyone comments!)
>
> (prob.cpp is the function, prob.h just declares it, test.cpp
> and its results in a .txt file (also pasted into the prob.cpp
> at the end)
I was able to download prob.h, but not the other two files. Maybe
it's just being flakey (high net traffic?) and will work later
tonight. But you might want to check and resend if it's not just
me/now.
> Perhaps you would like to comment on how your interface proposals
> might impact on this example. Perhaps this si simple example,
> but many are similarly simple.
>
> There is no real limit on the argument provided  the
> xlow and xupper values are machine specific, but not easily
> computed. Cody gives these examples:
I don't think the user should have to explicitly use these numbers,let
alone pass these numbers to the function. I think the numbers you
list below are more like constants needed by the function. I would
recommend making the private (or maybe protected) static const members
of the prob_std_normal class. Some would probably just be variables,
although other's might require a function to initialize them.
Ideally, a good compiler would evaluate them at compile, but even a
notsooptimizing compiler would allow them to be calculated at
runtime a single time for each set of template parameters. (Not a
significant performane penalty, presuming, the program involves
significant calculations.) Still, does anyone know typical compiler
behavior for initializing static const members from a static member
function?
> C Explanation of machinedependent constants. Let
> C
> C XMIN = the smallest positive floatingpoint number.
> C
> C Then the following machinedependent constants must be declared
> C in DATA statements. IEEE values are provided as a default.
> C
> C EPS = argument below which anorm(x) may be represented by
> C 0.5 and above which x*x will not underflow.
> C A conservative value is the largest machine number X
> C such that 1.0 + X = 1.0 to machine precision.
> C XLOW = the most negative argument for which ANORM does not
> C vanish. This is the negative of the solution to
> C W(x) * (11/x**2) = XMIN,
> C where W(x) = exp(x*x/2)/[x*sqrt(2*pi)].
> C XUPPR = positive argument beyond which anorm = 1.0. A
> C conservative value is the solution to the equation
> C exp(x*x/2) = EPS,
> C i.e., XUPPR = sqrt[2 ln(eps)].
> I see no reason why an exception should be raised if the argument
falls
> outside the values, as the value 0 or 1 should be returned.
I agree.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk