Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-05-17 12:49:44

----- Original Message -----
From: Matthew Austern <austern_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, May 17, 2001 2:31 PM
Subject: Re: [boost] Math Constants Library formal review results

> "Paul A. Bristow" wrote:
> >
> > Matt Austern wrote
> >
> > > I'm not convinced that 1 and 0 belong in a numeric constants class;
> > > seem more like things that belong in a numeric type traits class, or
> > > even something that's still more general. There are plenty of types
> > > which you can reasonably ask for the additive or multiplicative
> > > element, but where these transcendental constants make no sense.
> > > (Integers,
> > > NxN matrices, quaternions,... There's a sensible "zero" even for
> > > strings.)
> >
> > Agree with what you say
> >
> > - but since math_constants in a separate namespace,
> > is there any significant disadvantage
> > to having them with other numeric constants?
> > Completeness has some merit?
> But we don't have completeness. We never can.
> You've got sqrt(2), but not, if I'm remembering right,
> sqrt(3) or sqrt(5). You've got pi and e, but not, if
> I'm remembering right, Euler's constant (a.k.a. gamma).
> You don't have the zeros of the Bessel functions. And
> once you start including derived quantities, there's
> no end to it: do you include pi/2, pi/3, 2*pi, 4*pi,
> a/pi, pi^2...? How about e^2 (a.k.a. exp(2)), or ln(2),
> or ln(10)? All of those are useful.
> Please note: I'm not criticizing you for providing an
> incomplete selection of constants. You have to draw
> a line somewhere, and I don't know of any non-arbitrary
> way to draw one.
I addressed this before.
If constants are provided in a namespace -not in a struct-, there's really
no line at all becuase constants
can be added freely without clutering the interface:

// header.hpp

namespace boost {
namespace constants {
template<class T> inline T const& whatever() const { return
static_cast<T>(whatever_constant) ; }

// file.cpp
void foo()
    double v = boost::constants::whatever() ;

It isn't important for the users who/when was the constant provided.

BTW, I have used constants Zero and One many times when working with
user-defined types.
The reason is that those values have to be *really constructed* if the type
is user defined, so having pre-created 0s and 1s helps
a lot improving the performance of some algorithms.

Fernando Cacciola
Sierra s.r.l.

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