D2F$, an infinite-precision decimal-to-fraction converter
by Joe Horn

This program lets you do things like find the most accurate
fractional representation for pi, square root of 2, etc.
It is just a rewrite of DEC2FRAC from Goodies Disk #3, which
was only accurate to 12 digits.  D2F$, on the other hand, is
as accurate as you want (theoretically to thousands of digits).
(See DEC2FRAC.DOC on GD3 for details of the algorithm used.)

This program requires the LongFloat Library (LONG.LIB), which in
turn requires the ALG48 library.  Both can be found on this Goodies
Disk.

BEFORE USING: Store the desired number of digits of accuracy
into a variable called 'DIGITS' in the HOME directory.  Make
sure it's a big enough number (100 should be plenty), or
round-off errors may accumulate.  While the program is running,
the growing denominator is displayed so that you have some idea
what's happening.  Runtime depends on the setting of DIGITS and
the requested maximum denominator; when DIGITS=100 and the max
denominator is 1E12, runtimes average about 2 minutes.

Input:

2: Decimal number, in string form
1: Maximum desired denominator, in string form

Example: What fraction is closest to sqrt(.5), as long as the
denominator is limited to 12 digits?

Solution:
  HOME  100  'DIGITS'  STO
  ".5"  FSQRT
  "1E12"
             627013566048
  D2F$  -->  ------------
             886731088897

Use FDIV to verify that this fraction is indeed very close to
sqrt(.5); in fact, it's accurate to 23 places!  Notice too that
in this case DIGITS=20 would have given the same result twice
as fast.  I don't know how to predict what value DIGITS should
have before a run; if you figure out a way, please let me know.
