Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-06-11 08:49:05


| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Daniel Frey
| Sent: Wednesday, June 11, 2003 8:41 AM
| To: boost_at_[hidden]
| Subject: [boost] Re: Math Constants Formal Review - is extensible.
|
| I think that most people are able to look up pi (and any other constant)
| on the internet if they need more precision.

Of course, but I believe there is great merit in avoiding this by having a
collection of the widely used constants all of which have the same precision and
are used by everywhere (unless there is some exceedingly special reason for
higher precision - can you suggest who needs more than 40 decimal digits - apart
from number theoretic work. Should be enough even for accountants!).

| But as shown in the example
| for the Roguewave-type, it's possible to allow the user to extend the
| system. If the pi_value-stuff is placed in a header called
| constant_values.hpp and the definition of the variable pi itself is in
| another header, the user could add a specialization for 1000 digits if
| he likes. See the example I gave for 'g'. The main point in doing this
| is, that you only need to change the header of your project to add a new
| type, not the code where pi is used. Here in the company, we use doubles
| to develop the code, the RWDecimal<>-class for the production system and
| we might replace the latter by another type as we don't want to use
| Roguewave in the future. Of course it might be a nice idea to provide a
| string representation of a constant, probably as a specialization:
|
| template<> struct pi_value< std::string > {
| std::string operator()() const {
| return "3.1415926535897932384626422832794";
| }
| };
|
| Now we could even provide the default case for classes that have a ctor
| taking a string like this:
|
| template< typename T > struct pi_value {
| T operator()() const {
| return T( pi_value< std::string >()() );
| }
| };
|
| And the user is still able to specify his own version like shown:
|
| template<> struct pi_value< RWDecimal< RWMP3Int > > {
| const RWDecimal< RWMP3Int >& operator()() const {
| static const RWDecimal< RWMP3Int > value( "...1000digits..." );
| return value;
| }
| };

I don't believe that anything I propose conflicts with these sensible ideas.

The proposal is for several header files each containing the same constants,
only one of which would be used for any compilation. (Users have been warned
against using more than one! Nobody has suggested a way to guard against this
mistake, but I think that it would be apparent pretty soon, probably at compile
time, and at link time if not.) The macros constants header is the simplest and
could be used to provide the appropiate value(s) above.

|
| Now I'm getting closer to it. And if it is in a separate header, it
| would not mix up the above design, would it?

No, you would only use the intervals constants header if you were using the
interval library. (And if you were not, it would not compile).

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]

|
| Regards, Daniel
|
| --
| Daniel Frey
|
| aixigo AG - financial training, research and technology
| Schloß-Rahe-Straße 15, 52072 Aachen, Germany
| fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
| eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
|
|
| _______________________________________________
| Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
|
|


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