# NAG FL Interfaces13aaf (integral_​exp)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

s13aaf returns the value of the exponential integral ${E}_{1}\left(x\right)$, via the function name.

## 2Specification

Fortran Interface
 Function s13aaf ( x,
 Real (Kind=nag_wp) :: s13aaf Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x
#include <nag.h>
 double s13aaf_ (const double *x, Integer *ifail)
The routine may be called by the names s13aaf or nagf_specfun_integral_exp.

## 3Description

s13aaf calculates an approximate value for
 $E1 (x) = -Ei (-x) = ∫x∞ e-u u du .$
using Chebyshev expansions, where $x$ is real. For $x<0$, the real part of the principal value of the integral is taken. The value ${E}_{1}\left(0\right)$ is infinite, and so, when $x=0$, s13aaf exits with an error and returns the largest representable machine number.
For $0,
 $E1(x)=y(t)-ln⁡x=∑′rarTr(t)-ln⁡x,$
where $t=\frac{1}{2}x-1$.
For $x>4$,
 $E1(x)=e-xxy(t)=e-xx∑′rarTr(t),$
where $t=-1.0+\frac{14.5}{\left(x+3.25\right)}=\frac{11.25-x}{3.25+x}$.
In both cases, $-1\le t\le +1$.
For $x<0$, 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 ${x}_{0}\approx -0.372507\dots \text{}$, which corresponds to a simple zero of Ei($-x$).
s13aaf guards against producing underflows and overflows by using the argument ${x}_{\mathrm{hi}}$ , see the the Users' Note for your implementation for the value of ${x}_{\mathrm{hi}}$. To guard against overflow, if $x<-{x}_{\mathrm{hi}}$ the routine terminates and returns the negative of the largest representable machine number. To guard against underflow, if $x>{x}_{\mathrm{hi}}$ the result is set directly to zero.
NIST Digital Library of Mathematical Functions
Cody W J and Thatcher Jr. H C (1969) Rational Chebyshev approximations for the exponential integral Ei$\left(x\right)$ Math. Comp. 23 289–303

## 5Arguments

1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: the argument $x$ of the function.
Constraint: $-{x}_{\mathrm{hi}}\le {\mathbf{x}}<0.0$ or ${\mathbf{x}}>0.0$.
2: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{x}}=0.0$ and the function is infinite.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{x}}=⟨\mathit{\text{value}}⟩$ and the constant ${x}_{\mathrm{hi}}=⟨\mathit{\text{value}}⟩$. The evaluation has been abandoned due to the likelihood of overflow.
Constraint: ${\mathbf{x}}\ge -{x}_{\mathrm{hi}}$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

Unless stated otherwise, it is assumed that $x>0$.
If $\delta$ and $\epsilon$ are the relative errors in argument and result respectively, then in principle,
 $|ε|≃ | e-x E1 (x) ×δ|$
so the relative error in the argument is amplified in the result by at least a factor ${e}^{-x}/{E}_{1}\left(x\right)$. The equality should hold if $\delta$ is greater than the machine precision ($\delta$ due to data errors etc.) but if $\delta$ 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: Figure 1
It should be noted that, for absolutely small $x$, the amplification factor tends to zero and eventually the error in the result will be limited by machine precision.
For absolutely large $x$,
 $ε∼xδ=Δ,$
the absolute error in the argument.
For $x<0$, empirical tests have shown that the maximum relative error is a loss of approximately $1$ decimal place.

## 8Parallelism and Performance

s13aaf is not threaded in any implementation.

None.

## 10Example

The following program reads values of the argument $x$ from a file, evaluates the function at each value of $x$ and prints the results.

### 10.1Program Text

Program Text (s13aafe.f90)

### 10.2Program Data

Program Data (s13aafe.d)

### 10.3Program Results

Program Results (s13aafe.r)
{"ft_lang_label":"__label__en","ft_lang_prob":0.8649104,"math_prob":0.9972454,"size":3820,"snap":"2021-31-2021-39","text_gpt3_token_len":814,"char_repetition_ratio":0.1192348,"word_repetition_ratio":0.040498443,"special_character_ratio":0.20994765,"punctuation_ratio":0.122733615,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9992743,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-25T18:39:27Z\",\"WARC-Record-ID\":\"<urn:uuid:5c213672-8cea-4a71-8f02-59883f7b210c>\",\"Content-Length\":\"90725\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7d056652-35b6-47b5-9fae-845c09f0f778>\",\"WARC-Concurrent-To\":\"<urn:uuid:7e7a1d19-3518-4046-859d-9d8e3107df78>\",\"WARC-IP-Address\":\"78.129.168.4\",\"WARC-Target-URI\":\"https://www.nag.com/numeric/nl/nagdoc_27.1/flhtml/s/s13aaf.html\",\"WARC-Payload-Digest\":\"sha1:KELEVYQOGKPAI63U2RTRME4HL4RWEOQL\",\"WARC-Block-Digest\":\"sha1:PGEXEOWPF2G2Z22UFXEB5JWNAQBFPZXW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057733.53_warc_CC-MAIN-20210925172649-20210925202649-00346.warc.gz\"}"}