# §4.45 Methods of Computation

## §4.45(i) Real Variables

### Logarithms

The function $\ln x$ can always be computed from its ascending power series after preliminary scaling. Suppose first $1/10\leq x\leq 10$. Then we take square roots repeatedly until $|y|$ is sufficiently small, where

 4.45.1 $y=x^{2^{-m}}-1.$ ⓘ Symbols: $m$: integer, $x$: real variable and $y$: real variable Permalink: http://dlmf.nist.gov/4.45.E1 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

After computing $\ln\left(1+y\right)$ from (4.6.1)

 4.45.2 $\ln x=2^{m}\ln\left(1+y\right).$ ⓘ Symbols: $\ln\NVar{z}$: principal branch of logarithm function, $m$: integer, $x$: real variable and $y$: real variable Permalink: http://dlmf.nist.gov/4.45.E2 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

For other values of $x$ set $x=10^{m}\xi$, where $1/10\leq\xi\leq 10$ and $m\in\mathbb{Z}$. Then

 4.45.3 $\ln x=\ln\xi+m\ln 10.$ ⓘ Symbols: $\ln\NVar{z}$: principal branch of logarithm function, $m$: integer and $x$: real variable Permalink: http://dlmf.nist.gov/4.45.E3 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

### Exponentials

Let $x$ have any real value. First, rescale via

 4.45.4 $\displaystyle m$ $\displaystyle=\left\lfloor\frac{x}{\ln 10}+\frac{1}{2}\right\rfloor,$ $\displaystyle y$ $\displaystyle=x-m\ln 10.$

Then

 4.45.5 $e^{x}=10^{m}e^{y},$ ⓘ Symbols: $\mathrm{e}$: base of natural logarithm, $m$: integer, $x$: real variable and $y$: real variable Permalink: http://dlmf.nist.gov/4.45.E5 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

and since $|y|\leq\frac{1}{2}\ln 10=1.15\dots$, $e^{y}$ can be computed straightforwardly from (4.2.19).

### Trigonometric Functions

Let $x$ have any real value. We first compute $\xi=x/\pi$, followed by

 4.45.6 $\displaystyle m$ $\displaystyle=\left\lfloor\xi+\tfrac{1}{2}\right\rfloor,$ $\displaystyle\theta$ $\displaystyle=\pi(\xi-m).$ ⓘ Symbols: $\pi$: the ratio of the circumference of a circle to its diameter, $\left\lfloor\NVar{x}\right\rfloor$: floor of $x$ and $m$: integer Permalink: http://dlmf.nist.gov/4.45.E6 Encodings: TeX, TeX, pMML, pMML, png, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

Then

 4.45.7 $\displaystyle\sin x$ $\displaystyle=(-1)^{m}\sin\theta,$ $\displaystyle\cos x$ $\displaystyle=(-1)^{m}\cos\theta,$ ⓘ Symbols: $\cos\NVar{z}$: cosine function, $\sin\NVar{z}$: sine function, $m$: integer and $x$: real variable Permalink: http://dlmf.nist.gov/4.45.E7 Encodings: TeX, TeX, pMML, pMML, png, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

and since $|\theta|\leq\frac{1}{2}\pi=1.57\dots$, $\sin\theta$ and $\cos\theta$ can be computed straightforwardly from (4.19.1) and (4.19.2).

The other trigonometric functions can be found from the definitions (4.14.4)–(4.14.7).

### Inverse Trigonometric Functions

The function $\operatorname{arctan}x$ can always be computed from its ascending power series after preliminary transformations to reduce the size of $x$. From (4.24.15) with $u=v=((1+x^{2})^{1/2}-1)/x$, we have

 4.45.8 $2\operatorname{arctan}\frac{x}{1+(1+x^{2})^{1/2}}=\operatorname{arctan}x,$ $0. ⓘ Symbols: $\operatorname{arctan}\NVar{z}$: arctangent function and $x$: real variable Referenced by: Erratum (V1.0.7) for Equations (4.45.8), (4.45.9) Permalink: http://dlmf.nist.gov/4.45.E8 Encodings: TeX, pMML, png Substitution (effective with 1.0.7): The equation that was given originally, $2\operatorname{arctan}\frac{(1+x^{2})^{1/2}-1}{x}=\operatorname{arctan}x$, has been replaced with an equation that leads to a better recurrence for numerically computing $\operatorname{arctan}x$; see (4.45.9). Suggested 2014-02-05 by Masataka Urago See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

Beginning with $x_{0}=x$, generate the sequence

 4.45.9 $x_{n}=\frac{x_{n-1}}{1+(1+x^{2}_{n-1})^{1/2}},$ $n=1,2,3,\dots$, ⓘ Symbols: $\operatorname{arctan}\NVar{z}$: arctangent function, $n$: integer and $x$: real variable Referenced by: (4.45.8), Erratum (V1.0.7) for Equations (4.45.8), (4.45.9) Permalink: http://dlmf.nist.gov/4.45.E9 Encodings: TeX, pMML, png Substitution (effective with 1.0.7): The original recurrence given in this equation, $x_{n}=\frac{(1+x^{2}_{n-1})^{1/2}-1}{x_{n-1}}$ is susceptible to cancellation error when $x_{n}$ is small. It has been replaced with another recurrence that is better for numerically computing $\operatorname{arctan}x$. Suggested 2014-02-05 by Masataka Urago See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

until $x_{n}$ is sufficiently small. We then compute $\operatorname{arctan}x_{n}$ from (4.24.3), followed by

 4.45.10 $\operatorname{arctan}x=2^{n}\operatorname{arctan}x_{n}.$ ⓘ Symbols: $\operatorname{arctan}\NVar{z}$: arctangent function, $n$: integer and $x$: real variable Referenced by: §4.45(i) Permalink: http://dlmf.nist.gov/4.45.E10 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

Another method, when $x$ is large, is to sum

 4.45.11 $\operatorname{arctan}x=\frac{\pi}{2}-\frac{1}{x}+\frac{1}{3x^{3}}-\frac{1}{5x^% {5}}+\dots;$ ⓘ Symbols: $\pi$: the ratio of the circumference of a circle to its diameter, $\operatorname{arctan}\NVar{z}$: arctangent function and $x$: real variable Referenced by: §4.45(i) Permalink: http://dlmf.nist.gov/4.45.E11 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

compare (4.24.4).

As an example, take $x=9.47376$. Then

 4.45.12 $\displaystyle x_{1}$ $\displaystyle=0.90000\dots,$ $\displaystyle x_{2}$ $\displaystyle=0.38373\dots,$ $\displaystyle x_{3}$ $\displaystyle=0.18528\dots,$ $\displaystyle x_{4}$ $\displaystyle=0.09185\dots.$ ⓘ Symbols: $x$: real variable Permalink: http://dlmf.nist.gov/4.45.E12 Encodings: TeX, TeX, TeX, TeX, pMML, pMML, pMML, pMML, png, png, png, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

From (4.24.3) $\operatorname{arctan}x_{4}=0.09160\dots$. From (4.45.10)

 4.45.13 $\operatorname{arctan}x=16\operatorname{arctan}x_{4}=1.46563\dots.$ ⓘ Symbols: $\operatorname{arctan}\NVar{z}$: arctangent function and $x$: real variable Permalink: http://dlmf.nist.gov/4.45.E13 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

As a check, from (4.45.11)

 4.45.14 $\operatorname{arctan}x=1.57079\ldots-0.10555\ldots+0.00039\ldots-\cdots=1.4656% 3\dots.$ ⓘ Symbols: $\operatorname{arctan}\NVar{z}$: arctangent function and $x$: real variable Permalink: http://dlmf.nist.gov/4.45.E14 Encodings: TeX, pMML, png See also: Annotations for §4.45(i), §4.45(i), §4.45 and Ch.4

For the remaining inverse trigonometric functions, we may use the identities provided by the fourth row of Table 4.16.3. For example, $\operatorname{arcsin}x=\operatorname{arctan}\left(x(1-x^{2})^{-1/2}\right)$.

### Hyperbolic and Inverse Hyperbolic Functions

The hyperbolic functions can be computed directly from the definitions (4.28.1)–(4.28.7). The inverses $\operatorname{arcsinh}$, $\operatorname{arccosh}$, and $\operatorname{arctanh}$ can be computed from the logarithmic forms given in §4.37(iv), with real arguments. For $\operatorname{arccsch}$, $\operatorname{arcsech}$, and $\operatorname{arccoth}$ we have (4.37.7)–(4.37.9).

### Other Methods

See Luther (1995), Ziv (1991), Cody and Waite (1980), Rosenberg and McNamee (1976), Carlson (1972a). For interval-arithmetic algorithms, see Markov (1981). For Shift-and-Add and CORDIC algorithms, see Muller (1997), Merrheim (1994), Schelin (1983). For multiprecision methods, see Smith (1989), Brent (1976).

## §4.45(ii) Complex Variables

For $\ln z$ and $e^{z}$

 4.45.15 $\displaystyle\ln z$ $\displaystyle=\ln|z|+i\operatorname{ph}z,$ $-\pi\leq\operatorname{ph}z\leq\pi$, 4.45.16 $\displaystyle e^{z}$ $\displaystyle=e^{\Re z}(\cos\left(\Im z\right)+i\sin\left(\Im z\right)).$

See §1.9(i) for the precise relationship of $\operatorname{ph}z$ to the arctangent function.

The trigonometric functions may be computed from the definitions (4.14.1)–(4.14.7), and their inverses from the logarithmic forms in §4.23(iv), followed by (4.23.7)–(4.23.9). Similarly for the hyperbolic and inverse hyperbolic functions; compare (4.28.1)–(4.28.7), §4.37(iv), and (4.37.7)–(4.37.9).

For other methods see Miel (1981).

## §4.45(iii) Lambert $W$-Function

For $x\in[-1/e,\infty)$ the principal branch $\operatorname{Wp}\left(x\right)$ can be computed by solving the defining equation $We^{W}=x$ numerically, for example, by Newton’s rule (§3.8(ii)). Initial approximations are obtainable, for example, from the power series (4.13.6) (with $t\geq 0$) when $x$ is close to $-1/e$, from the asymptotic expansion (4.13.10) when $x$ is large, and by numerical integration of the differential equation (4.13.4) (§3.7) for other values of $x$.

Similarly for $\operatorname{Wm}\left(x\right)$ in the interval $[-1/e,0)$.