Boost logo

Boost :

From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2003-12-11 07:28:27

Le lun 08/12/2003 à 23:10, Daniel Frey a écrit :
> Hi,
> I added milestone 2 of the constant library to the files section. It is a
> framework for representing constants like 'pi' with some advanced
> auto-type-selection. Please have a look at the code if you are
> interested. Some notes:


> - Paul (and anyone interested in the interval library): Please check if
> the constant library provides what you need. If you have questions,
> I'll try to answer them. Have a look at the mappers, I hope they are
> useful for you.


My question may seem a bit dumb, but I don't see the relation between
this constant library and the interval library. Does the constant
library provide anything at all to help with interval arithmetic?

If I understand correctly your example with pi and std::complex, you get
a complex<T> pi by using the T version of pi and then implicitly
converting it to std::complex<T>. Is this the correct use of the

If it is, it can't be used to automatically create interval versions of
the constants. The reason is: if you want an enclosing interval for a
given type, you can't use an implicit conversion (because you don't have
any information on the precision of the constant).

For example the definition of an interval<float> pi constant would still
need to be explicit, something like:

static const float pi_f_l = 13176794.0f/(1<<22);
static const float pi_f_u = 13176795.0f/(1<<22);
template< typename T >
struct pi_value : constant_value< pi_value, T > {};
template< typename Policies >
struct pi_value< boost::numeric::interval< float, Policies > > {
  typedef boost::numeric::interval< float, Policies > I;
  I operator()() const { return I(pi_f_l, pi_f_u); }

So, is there anything I'm missing?



PS: There is one feature of your library that I find very interesting,
it's what you call "combined constants". I didn't try it, but it seems
that if the program was "interval<float> a = pi * pi;", the
corresponding constant (and the subterms) would automatically be of the
good type. And consequently the obtained interval would really enclose

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