
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. https://gist.github.com/1491172 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. Cheers, -- Dave Abrahams BoostPro Computing http://www.boostpro.com