|
Boost : |
Subject: Re: [boost] [mpl-cf] [RFC] MPL Real Numbers using Continued Fractions
From: Hal Finkel (half_at_[hidden])
Date: 2010-11-29 12:57:16
On Mon, 2010-11-29 at 10:24 -0500, Hal Finkel wrote:
> On Mon, 2010-11-29 at 11:07 +0100, Mathias Gaunard wrote:
> > On 28/11/2010 22:30, Hal Finkel wrote:
> > > Hello,
> > >
> > > A few months ago, I created an MPL extension type for representing real
> > > numbers.
> >
> > I find that idea very interesting.
> >
> >
> > > The current default is 20 to allow an effective
> > > precision near that of a double. Also, continued fractions, being "based
> > > on" rational numbers, can exactly represent any rational (for example,
> > > 1/3) so the computations can be more accurate than those using a
> > > floating-point representation.
> >
> > It would be nice to know what minimum value is necessary to provide
> > correctly rounded results for IEEE754 floats and doubles.
> >
>
> This depends on the number: For a rational, you need only two
> integers ;)
Actually, ignore that statement. You only need two integers for a0 +
1/a1, in general you need more. For example, if you look at the test
program (basic.cpp in the archive), it provides some examples (where the
floating-point output is float, double, long double):
3/2 + 1/4 = [ 1 1 3]
1.75
1.75
1.75
1/7 + 1/15 = [ 0 4 1 3 2 2]
0.209524
0.20952380952381
0.209523809523809524
There are other continued fraction representations where any rational
can be represented with a fixed number of integers (a0 + b0/(a1 + ...)),
but the algorithms are a little more complicated, and I fear the compile
times would increase.
-Hal
> For a general real number, it depends on the rate of
> convergence. In my experience, you get about one decimal digit per
> integer coefficient, so 10 is sufficient for single precision, 20 for
> double precision (and long double too on an x86, since the extended type
> there is only 18 digits). The MPL containers generally come in
> max-size-increments of 10, but it would not be too hard to generate
> something else.
>
> -Hal
>
> >
> > _______________________________________________
> > 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