Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-01-28 06:16:51


I have applied to your workaround, initialising

 constant< float, pi_tag > const pi = constant< float, pi_tag >();

and this compiles and runs OK with MSVC 7.0. And better still, it not longer
requires MSVC language extensions, nor produces warnings at level 4. So I think
we can be confident it is more correct. Sad about other compilers - this is the
snag with this representation of constants - it stresses compilers.

< As far as I understand long double is optional (in IEEE 754).

It is up to the compiler what it provides for long double - C++ says it must
provide something. MSVC only provides 64 bit same as double, gcc goes to 80
bit, others up to 128 bit. (See a big table of examples of floating-point
formats in my math constants documentation).

< This would mean you'd have to provide the double constant, too.
The MACRO solution proposed by Michael Kenniston assumed that the macro constant
only defined a number with no suffix F or L, and used a macro to add F or L, if
necessary, thus

#define BOOST_REAL_CONSTANT( name, \
        float_value, double_value, long_double_value ) \
                struct name##_tag ; \
                typedef real_type< name##_tag > name##_t; \
                extern name##_t name; \
                inline float constant_value( const float *, const name##_t & ) { return
float_value##F; } \ <<<<<<<<<<<<<<<<< add F
                inline double constant_value( const double *, const name##_t & ) { return
double_value; } \ <<<<<<<<<<<<<<<<<<<<<< don't add any suffix
                inline long double constant_value( const long double *, const name##_t & ) {
return long_double_value##L; } <<<<<<<<<<<<<<< add L

This avoids any conversion by the compiler from writing double d = 3.1459L;
(which ought to be OK, but we should avoid the risk).

The bottom line is that you should get what the compiler gives you, so the
program is portable, but the numerical results may differ. But given the
language specification, this is the 'Right Thing To Do'.

Paul

Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]
mailto:pbristow_at_[hidden]

> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]]On Behalf Of Joerg Walter
> Sent: Monday, January 27, 2003 10:07 PM
> To: Boost mailing list
> Subject: Re: [boost] RE: math constant - generic function circle_area
> example.
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk