Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-04-22 07:15:26

From: "Ed Brey" <brey_at_[hidden]>

> AFAICT, it is impossible to have a single interface that works for both:
> (a) compile-time computation of expressions, and
> (b) custom-binary values, which are more accurate than the compiler
> can produce.

Here's my take on this:

// Documented interface

namespace boost
    float const pi_f;
    double const pi;
    long double const pi_l;

// Possible implementation 1

namespace boost
    double const pi = 3.141592653...;

// Possible implementation 2

namespace boost
    extern double const pi;

// Possible implementation 3

namespace boost
    unsigned char const _pi[] = { insert suitably non-portable values
here };
    double const & pi = *(double*)_pi;

The user can hardly tell the difference between 1), 2) and 3).

For generic code, this may be supplemented with a numeric_limits-like
template, although I think that a static_cast<T>(pi_l) would probably

Peter Dimov
Multi Media Ltd.

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