Boost logo

Boost :

From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2000-07-12 18:06:51


> From: jmaurer_at_[hidden]
> Subject: Re: [boost] Standard Constants?
>
> Your suggested header file looks like it still needs some boost-ification.
> boost seems to prefer all lower-case identifiers with underscores as
> separators, so it's "half_pi" instead of "halfPi". Aliases (sqrtTwo
> and rootTwo) should be avoided. The naming should be consistent
> (gammaThird vs. thirdPi and sqrtE vs. eSqr). Probably define
> an explicit naming policy so that others can add further constants
> with a compatible naming.

I am concerned that the use of _ within names will make them unacceptably
long.
oneDivSqrtTwoPi versus one_div_sqrt_two_pi.
(Of course my preference is colored by my use of the mixed case style).
But I willing to be guided if there are strong views on this.

> Include guards should be applied to the header file.
[PAB] Agreed. Will do.
>
> Oh, and we need a test file, which would compare the constants
> to on-the-fly FPU computed values with a certain accuracy.
[PAB] I have it ready.

> You should upload your package to the boost "files" section
> at www.egroups.com/files/boost in a new directory.
[PAB] I will do this when some style details are resolved.
>
> > typedef double real_type; // float or double or long double.
[PAB] Indeed ugly, but your suggested:

#include <iostream>

namespace boost
{
        template<class T>
                struct mathconst
        {
                static const double pi;
                // ... etc
        };
}

// using mathconst; // Requires template arguments.
// using mathconst<long double>::pi; // Fails
// J:\test\test\testStddef.cpp(15) : error C2885: 'mathconst<long double>::pi'
: a using-declaration as a member

template<class T> const double boost::mathconst<T>::pi =
3.14159265358979323846264338327950288419716939937510L;

int main()
{
        using boost::mathconst;
// const long double longPi = mathconst<long double>::pi; // C2653
'mathconst<long double>' : is not a class or namespace name
        const long double longPi = boost::mathconst<long double>::pi;
        std::cout << longPi << std::endl;
        return 0;
} // main

Also has some ugliness when the user needs it.

const long double longPi = boost::mathconst<long double>::pi;

[PAB] is pretty long winded. What do others think about this?
[PAB] In practice users will nearly always only use float, double, or long
double.

> I think we need pi, e and the euler constant, but the rest can
> be computed (with a possible loss of accuracy, of course).
> Probably we should offer only a basic set of constants to gain
> more experience before expanding things further.
[PAB] A major design objective, from bitter experience, is to get and maintain
maximum accuracy.
So having quite a lot of predefined ones like one_div_sqrt_two_pi IS useful,
and cheap.
[PAB] Any doing statistics needs most of the ones I have provided.
What others are needed?

> If we ever consider physical constant, they should be in a different
> header file.
[PAB} agreed.
>
> > const real_type realMax = std::numeric_limits<real_type>::max();
> > const real_type eps = std::numeric_limits<real_type>::epsilon();
> Are redundant [PAB] A left-over convenience from my use. Will go.

> I think the compiler is allowed to parse 3.14..., store it as
> a "double"
> internally and convert it to a "long double" afterwards (when
> real_type == long double). This makes all the countless digits rather
> useless. Thus, all constants should be given as "long double", e.g.
> 3.14......L.
[PAB] Surprising to me, but I'm sure you are right, and no problem to change.
[PAB] (Can't test as MSVC only does double really - long double is exactly the
same as double).

> Jens Maurer


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