Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-05-11 09:05:03


----- Original Message -----
From: Paul A. Bristow <pbristow_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, May 11, 2001 8:06 AM
Subject: RE: [boost] Math Constants Library formal review results

> There has been a lot of dissention about the format of my proposed
> mathematical constants.
>
> It is clear that there is no one solution that will satisfy all users.
> And that there is no acceptable compromise.
>
> I therefore propose to re-submit the constants in ALL the formats
proposed,
> in a separate .h and .hpp files.
>
I think this is very flexible, and I agree.
But don't know the boost usual politics.

> 1 MACROs - these will be useful to C programmers, and C++ users
> who have some very special requirement.
>
> #define BOOST_PI 31459L
>
> NOT in a namespace. math_constants.h
>
> 2 Since naive C and C++ users (but ace physicists!)
> only want const double so they can write
> double area = pi * r * r;
>
> a collection of
> namespace math_double_constants
> {
> const double pi = 31459;
> }
> (This is probably 98% of use, so a template solution is
> cosmetically unacceptable).
>
> in math_double_constants.hpp
>
> 3 A collection of long double constants
>
> namespace math_constants
> {
> const long double pi = 31459L;
> }
>
> in math_constants.hpp
>
> 4 A collection of templated constants in math_template_constants.hpp
>
> namespace boost
> {
> namespace math
> {
> // Following B Stroustrup ISBN 0 201 70073 5, p 854
> template<typename T> struct constants
> {
> public: // redundant if struct, but good documentation.
> static const T pi; //
> }; // template constants
>
There is a problem with storing constants inside a struct.
I used the above some years ago but found the following:

As a user, I do: boost::math::constants::pi, which is nice;

Now, suppose I later need some other constant, say e (the natural base); it
would make sense to have
e inside constants, just like pi, so as a user I could use:
boost::math::constants::e ; but this is not possible becuase 'constants'
is a struct!
One solution is to name structs something more specific, such as
'regular_constants', so later I add 'extra_constants';
but this approach tends to create a mess!

That's why I use free functions inside namespaces, like a proposed.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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