ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
RE: [boost] RE: math constant - generic function circle_area example.
by Paul A. Bristow other posts by this author
Jan 28 2003 11:16AM messages near this date
Re: [boost] RE: math constant - generic function circle_area example. | [boost] MPL usage for code generation
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 fl
oat 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@[...].uk
mailto:pbristow@[...].com


>  -----Original Message-----
>  From: boost-bounces@[...].org
>  [mailto:boost-bounces@[...].org]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.
> 

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Joerg Walter
Paul A. Bristow
Joerg Walter
Paul A. Bristow
Paul A. Bristow
Joerg Walter
Paul A. Bristow
Joerg Walter
Paul A. Bristow

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved