 # Boost :

Subject: Re: [boost] [mpl-cf] [RFC] MPL Real Numbers using Continued Fractions
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-11-30 03:20:43

On Mon, Nov 29, 2010 at 18:19, Dave Abrahams <dave_at_[hidden]> wrote:
>
> For some inexplicable reason, the very fact that there's someone on
> this list who knows enough about math to ask that question makes me
> really, really happy.
>

I'm glad :)

For anyone else who wants to know just about as much as me:
<http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfINTRO.html>
:)

I did a quick experiment, and it seems for phi, you need about 20 ones
for a float and 40 ones for a double:

typedef float T; // or double

cout << setprecision(numeric_limits<T>::digits10+2);
cout << (sqrt((T)5) + 1) / 2 << "\n\n";

int steps = 1;
T value = 1;
while (1 + 1/(1 + 1/value) != value) {
++steps;
value = 1 + 1/value;
cout << steps << ": " << value << "\n";
}

I don't think that's practical to specify, as such :P

However, perhaps you could limit it to some smaller number, but allow
the last term to be a repeating specifier of some kind. It would be
much more palatable to specify (ignoring that the constants would
probably have to be int_c):

typedef cf<1, repeat<1>> phi;
typedef cf<0, 2> half;
typedef cf<1, repeat<2>> root_2;
typedef cf<1, repeat<8, 2>> half_of_root_5;

This still isn't a full solution, though, since the one everyone will
ask about can't be nicely shortened:

typedef cf<3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3> pi; //
hopefully enough...

And it obviously makes implementing math and comparisons much harder.

BTW, how do you avoid floating point annoyances when calculating the
runtime value? I'd assume that cascading inversions would be a
terrible idea.

~ Scott