Boost logo

Boost :

From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2000-07-19 06:48:46


I am posting to boost files a draft of math constants using templates
for a few sample constants.

There are several things I am uncertain about:

1 It seems that, as with numeric_limits, integral constants
are different. Should I follow the inplmentation of
limits to create two template classes, perhaps with
inheritance? Or is this
an unnecessary complication? - users who instantiate
math_const<int>::pi will just get a link failure,
which probably serves them right!

But it doesn't seem quite nice.

2 MSVC++ 6 SP3, the compiler we love to hate does not
seem to allow initialisation of integral types within
the class, as C++ Primer P 643 says should be allowed.
however I am not sure if this is possible with a
template anyway

        template <typename T>
        class int_math_const
        {
                static const T zero;
                // static const int zero = 0; won't compile MSVC++ 6 SP3
                // but should do for integral types only? C++ Primer p 643
        }; // int_math_const

        // So must explicit instantiate for all integral types?
        const int int_math_const<int>::zero = 0;
        // But how to do others without changing the name?

Or am I being silly here?

3 I have built in a MACRO switch _THROW0() with
the default to never give a throw() specification.

4 I have opted for the
static_cast<Type>(3.141592653589793238462643383279502884197L)

because it allows the same values to be used in all types, float, double,
long.
and with lots of values there some work and a risk of mistakes
changing to 3.14159265358F, for example.

Comments please before I expand the number of constants.

Paul

Dr Paul A. Bristow, hetp Chromatography
4 Victoria Road, Wilmslow, Cheshire SK9 5HN UK
Phone +44 1625 520193 FAX & Voicemail +44 1625 252495
email mailto:pbristow_at_[hidden]


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