using Chebyshev expansions, where is real. For , the real part of the principal value of the integral is taken. The value is infinite, and so, when , S13AAF exits with an error and returns the largest representable machine number.
In both cases, .
For , the approximation is based on expansions proposed by Cody and Thatcher Jr. (1969). Precautions are taken to maintain good relative accuracy in the vicinity of , which corresponds to a simple zero of Ei().
S13AAF guards against producing underflows and overflows by using the parameter ; see the Users' Note for your implementation for the value of . To guard against overflow, if the routine terminates and returns the negative of the largest representable machine number. To guard against underflow, if the result is set directly to zero.
Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Cody W J and Thatcher Jr. H C (1969) Rational Chebyshev approximations for the exponential integral Ei Math. Comp.23 289–303
1: X – REAL (KIND=nag_wp)Input
On entry: the argument of the function.
2: IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to , . If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value is recommended. If the output of error messages is undesirable, then the value is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is . When the value is used it is essential to test the value of IFAIL on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6 Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
On entry, and the function is infinite. The result returned is the largest representable machine number.
The evaluation has been abandoned due to the likelihood of overflow. The argument , and the result is returned as the negative of the largest representable machine number.
Unless stated otherwise, it is assumed that .
If and are the relative errors in argument and result respectively, then in principle,
so the relative error in the argument is amplified in the result by at least a factor . The equality should hold if is greater than the machine precision ( due to data errors etc.) but if is simply a result of round-off in the machine representation, it is possible that an extra figure may be lost in internal calculation and round-off.
The behaviour of this amplification factor is shown in the following graph:
It should be noted that, for absolutely small , the amplification factor tends to zero and eventually the error in the result will be limited by machine precision.
For absolutely large ,
the absolute error in the argument.
For , empirical tests have shown that the maximum relative error is a loss of approximately decimal place.
8 Further Comments
The following program reads values of the argument from a file, evaluates the function at each value of and prints the results.