Extra digits to fpprec for calculation of Gamma



Hello,

we know that in the calculation of the Gamma function in bigfloat precision
always some digits of prescision are missing. Because the Gamma function is one
of the basic functions which is needed for a lot of further calculations it
seems to me quite useful to extend the precision. 

The most simple way would be to give some extra digits in the call to the
function bffac or cbbfac e.g. bffac(z,fpprec+extradigits). I have done some
tests to find the extra digits needed to get more correct results (the relative
error is lower than the desired precision). This is the result for a precision
up to 2048 digits and values for the Gamma function up to 1000:

        Values for gamma up to
        75  150  200  250  500 1000
fpprec
  16    +3   +3   +3   +3   +3   +4
  32    +3   +3   +3   +3   +4   +4
  64    +3   +3   +3   +4   +4   +4
 128    +3   +4   +3   +4   +4   +4
 256    +4   +4   +4   +4   +4   +5
 512    +4   +4   +4   +4   +5   +5
1024    +5   +5   +6   +6
2048    +5   +6   +6   +6

We need more digits with increasing argument and increasing precision. If we
choose generally +5 extra digits the Gamma function would give the desired
precision up to a fpprec:512 and an argument up to 1000. 

Actually the precsion of bffac is controlled by the forumla

k:2*(entier(0.41*fpprec)+1)

The +5 extra digits contribute with 4 extra terms in the loop to calculate
Gamma. If we would optimize the speed e.g. for fpprec:16 up to 500 only +3 extra
digits are needed and 2 extra terms have to be added in the loop.

At first we could do something like:

(defvar $gamma_incfpprec 5
  "Extra digits in call to bffac to achive full precision of gamma")

...
bffac(z,$fpprec+$gamma_incfpprec)
...

This should be documented for the user. Perhaps it is possible to find a more
general formula for the value of k, so we do not need an extra flag.

Dieter Kaiser