NAG Library Routine Document

s01baf (log_shifted)


    1  Purpose
    7  Accuracy


s01baf returns a value of the shifted logarithmic function, ln1+x, via the function name.


Fortran Interface
Function s01baf ( x, ifail)
Real (Kind=nag_wp):: s01baf
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: x
C Header Interface
#include nagmk26.h
double  s01baf_ (const double *x, Integer *ifail)


s01baf computes values of ln1+x, retaining full relative precision even when x is small. The routine is based on the Chebyshev expansion
ln1+p2+2px- 1+p2-2px- =4k=0p2k+1 2k+1 T2k+1x-.  
Setting x-= x1+p2 2px+2 , and choosing p= q-1 q+1 , q=24 the expansion is valid in the domain x 12-1,2-1 .
Outside this domain, ln1+x 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


1:     x – Real (Kind=nag_wp)Input
On entry: the argument x of the function.
Constraint: x>-1.0.
2:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry 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:
On entry, x-1.0.
The result is returned as zero.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


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 ln1+x, in s01baf.

Parallelism and Performance

s01baf is not threaded in any implementation.

Further Comments

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.


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

Program Text

Program Text (s01bafe.f90)

Program Data

Program Data (s01bafe.d)

Program Results

Program Results (s01bafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017