Boost logo

Boost :

From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2002-10-17 07:47:31

On Thu, 17 Oct 2002, Paul A. Bristow wrote:


> Does this look at all promising, if ugly.
> Paul

You got back to something that looks like what we did in the Interval
library. That's unfortunate; I was hoping you would find a nice way to
represent "exact" constants. But maybe this problem is intrinsically ugly,
and so is any solution.

Reading your example and the explanations about 'long double' in MSVC, I
thought about a way to avoid defining all the constants. Maybe somebody
already proposed it before. Here is what I suggest (I didn't test it at

  template<class T>
  struct pi {
    T lower() { return pi< prev_type<T> >::lower(); }
    T upper() { return pi< prev_type<T> >::upper(); }

  struct pi<int> {
    int lower() { return 3; }
    int upper() { return 4; }

  struct pi<float> {
    float lower() { return pi_f_lower; }
    float upper() { return pi_f_upper; }

In this example, 'pi' is only specialized for 'int' and 'float' (the
values for 'float' are the one you generated). When there is no
specialization, the functions return some less precise values.

The exact meaning of 'prev_type' (a really bad name) would be something
like: 'prev_type<T>' is the most precise type which is exactly convertible
to 'T' (and which isn't 'T'). So, for example, 'prev_type<double>' would
be 'float'; and 'prev_type<long double>' would be 'double'. Maybe an
existing part of Boost is already able to give this type.

So, my suggestion doesn't help at all with defining constants; I can't
think of anything better than what you already did. But it can help with
missing constants.



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