S Chapter Contents
S Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentS01BAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

S01BAF returns a value of the shifted logarithmic function, $\mathrm{ln}\left(1+x\right)$, via the function name.

## 2  Specification

 FUNCTION S01BAF ( X, IFAIL)
 REAL (KIND=nag_wp) S01BAF
 INTEGER IFAIL REAL (KIND=nag_wp) X

## 3  Description

S01BAF computes values of $\mathrm{ln}\left(1+x\right)$, retaining full relative precision even when $\left|x\right|$ is small. The routine is based on the Chebyshev expansion
 $ln⁡1+p2+2px- 1+p2-2px- =4∑k=0∞p2k+1 2k+1 T2k+1x-.$
Setting $\stackrel{-}{x}=\frac{x\left(1+{p}^{2}\right)}{2p\left(x+2\right)}$, and choosing $p=\frac{q-1}{q+1}$, $q=\sqrt{2}$ the expansion is valid in the domain $x\in \left[\frac{1}{\sqrt{2}}-1,\sqrt{2}-1\right]$.
Outside this domain, $\mathrm{ln}\left(1+x\right)$ is computed by the standard logarithmic function.
Lyusternik L A, Chervonenkis O A and Yanpolskii A R (1965) Handbook for Computing Elementary Functions p. 57 Pergamon Press

## 5  Parameters

1:     X – REAL (KIND=nag_wp)Input
On entry: the argument $x$ of the function.
Constraint: ${\mathbf{X}}>-1.0$.
2:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. 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 $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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}}\le -1.0$.
The result is returned as zero.

## 7  Accuracy

The returned result should be accurate almost to machine precision, with a limit of about $20$ significant figures due to the precision of internal constants. Note however that if $x$ lies very close to $-1.0$ and is not exact (for example if $x$ is the result of some previous computation and has been rounded), then precision will be lost in the computation of $1+x$, and hence $\mathrm{ln}\left(1+x\right)$, in S01BAF.

Empirical tests show that the time taken for a call of S01BAF usually lies between about $1.25$ and $2.5$ times the time for a call to the standard logarithm function.

## 9  Example

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

### 9.1  Program Text

Program Text (s01bafe.f90)

### 9.2  Program Data

Program Data (s01bafe.d)

### 9.3  Program Results

Program Results (s01bafe.r)