Boost logo

Boost :

Subject: Re: [boost] Numeric constants
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2009-01-30 05:53:59

> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
> Behalf Of John Maddock
> Sent: 30 January 2009 10:35
> To: boost_at_[hidden]
> Subject: [boost] Numeric constants
> Folks, someone's just filed a feature request asking for more numeric
> constants to be added to Boost.Math (these are currently an implementation
> detail, albeit a semi-documented one:
> kit/internals1/constants.html),
> but we know what troubles we had agreeing on anything last time this came
> for review! Even so it appears to be time to fearlessly open up this
> particular can of worms again ;-)
> So, it appears that there is still interest, but as you know last time we
> tried this there was no agreement on interface, some folks felt a template
> interface was essential:
> template <class T> T pi();
> leading to:
> template <class T>
> T circumference(T r)
> {
> return 2 * boost::math::constants::pi<T>() * r;
> }
> While others were absolutely adament that they wouldn't use a syntax other
> than:
> template <class T>
> T circumference(T r)
> {
> return 2 * pi * r;
> }
> Various attempts were made to solve this conundrum via expression
> and/or overloaded operators, but all introduced their own new issues as
> well, and IMO none were wholly satisfactory (not least due to the
> introduced, a complexity that becomes all too apparent to the user if they
> do get a compiler error due to an unsupported use case).
> So.... here's what I think Paul Bristow and I might be persuaded to
> * A library based on the existing Boost.Math code, with pi<T>() as the
> interface / use case.
> * Possibly add constants of specific precision in alternative namespaces,
> we could have:
> double circumference(double r)
> {
> using namspace boost::math::double_constants;
> return 2 * pi * r;
> }
> And that's pretty much it: no overly complex stuff, just a really simple
> library with a few constants in it, that makes it really easy to add new
> constants when required.
> Thoughts?

Well - obviously I am entirely in agreement with John's suggestion. I was
very disappointed that we got bogged down in the presentation issue.

I still have the collection of constants in the vault and I don't think any
of them have changed since 2003 ;-)

Since more than 95% of the use will be people wanting doubles, I think
John's proposal to have specific doubles namespace is a really good idea.

One question I have is the precision needed. My current set are 50 decimal
digits, more than enough for any foreseeable floating point hardware.
John's current code in the Boost.Math package allows much more, and the
constants now defined are to 100 decimal digits. This allows really
accurate computation using an arbitrary precision system like Victor Shoup's
NTL (GPL License) (or a Boost equivalent if we can produce one - a GSoC

My question is - what precision would be useful?


Paul A. Bristow
Prizet Farmhouse
Kendal, UK   LA8 8AB
+44 1539 561830, mobile +44 7714330204

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