Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-10-24 13:59:49

From: "Peter Dimov" <pdimov_at_[hidden]>

> From: "Noah Stein" <noah_at_[hidden]>
> > > I don't really see what's wrong with the simple
> > >
> > > namespace math
> > > {
> > > double const pi = 3.14159265358...;
> > > }
> >
> > For me, it's an enormous burden. I work on hardware that only supports
> > floats. I'd have to cast the constants every time I use them.
> Why?
> float const pi_f = math::pi;

This fits well with the school of thought "Always use double unless you have a good reason not to." Noah's situation is a good reason not to. However, if that situation is rare, it is quite reasonable to ask the user to define his own pi_f (or pi in his own namespace). The advantage is that for the majority of users, the constants are available from a "constants" namespace.

But, there's a catch: What about long double? The user can't just define his own pi_ld. Perhaps the namespace landscape should look like this:
namespace boost {
    namespace math {
        namespace constants {
            double const pi;
            namespace long_double {
                long double const pi;

This keeps the amount of qualification work that a common user would need to do to a minimum. (Getting rid of the math or constants namespaces would make the using directive problematic; this is one case where it can be quite useful.)

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