Subject: Re: [boost] Boost.Math and Math Constants
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-12-17 14:41:48
on Sat Dec 17 2011, John Maddock <boost.regex-AT-virgin.net> wrote:
>> For what it's worth, I've been doing some experiments with constexpr in
>> GCC and it's now possible to compute maximally-precise
>> statically-initialized constants for any floating type via series
>> expansion, at compile-time. Crazy stuff.
> Crazy indeed - can you have loops in such code? Either way I'd love
> to see some example code if that's possible,
No, you have to use recursion. But you can use pointer indirections(!)
I've got some examples lying about. https://gist.github.com/1457531#L33
demonstrates feasibility but I this is not the best way to calculate pi
and plus I don't know how to tell where a 2d grid actually converges.
It would be better to use Machin's formula, but was more interested in
the challenge than in actually getting a good pi and I'm just out of
time for playing around with it now.
I can also show you a version that doesn't rely on memoization in the
compiler (which GCC has) but instead builds its own linked-list
containing a history of earlier values at compile-time.
Again, it has
the same problem of not knowing how to tell where it has converged, but
again, I was just interested in the challenge.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk