Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_complex_abs (a02ab)

## Purpose

nag_complex_abs (a02ab) returns the value of the modulus of the complex number x = (xr,xi)$x=\left({x}_{r},{x}_{i}\right)$.

## Syntax

[result] = a02ab(xr, xi)
[result] = nag_complex_abs(xr, xi)

## Description

The function evaluates sqrt(xr2 + xi2)$\sqrt{{x}_{r}^{2}+{x}_{i}^{2}}$ by using a×sqrt(1 + (b/a)2)$a\sqrt{1+{\left(\frac{b}{a}\right)}^{2}}$ where a$a$ is the larger of |xr|$|{x}_{r}|$ and |xi|$|{x}_{i}|$, and b$b$ is the smaller of |xr|$|{x}_{r}|$ and |xi|$|{x}_{i}|$. This ensures against unnecessary overflow and loss of accuracy when calculating (xr2 + xi2)$\left({x}_{r}^{2}+{x}_{i}^{2}\right)$.

## References

Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## Parameters

### Compulsory Input Parameters

1:     xr – double scalar
2:     xi – double scalar
xr${x}_{r}$ and xi${x}_{i}$, the real and imaginary parts of x$x$, respectively.

None.

None.

### Output Parameters

1:     result – double scalar
The result of the function.

None.

## Accuracy

The result should be correct to machine precision.

None.

## Example

```function nag_complex_abs_example
xr = -1.7;
xi = 2.6;
[result] = nag_complex_abs(xr, xi)
```
```

result =

3.1064

```
```function a02ab_example
xr = -1.7;
xi = 2.6;
[result] = a02ab(xr, xi)
```
```

result =

3.1064

```