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_divide (a02ac)

## Purpose

nag_complex_divide (a02ac) divides one complex number, $x=\left({x}_{r},{x}_{i}\right)$, by a second complex number, $y=\left({y}_{r},{y}_{i}\right)$, returning the result in $z=\left({z}_{r},{z}_{i}\right)$.

## Syntax

[zr, zi] = a02ac(xr, xi, yr, yi)
[zr, zi] = nag_complex_divide(xr, xi, yr, yi)

## Description

The result $z$ is calculated using Smith's algorithm with scaling, from Li et al. (2002), which ensures that no unnecessary overflow or underflow occurs at intermediate stages of the computation.

## References

Li X S, Demmel J W, Bailey D H, Henry G, Hida Y, Iskandar J, Kahan W, Kapur A, Martin M C, Tung T and Yoo D J (2002) Design, implementation and testing of extended and mixed precision BLAS ACM Trans. Math. Soft. 28(2) 152–205

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{xr}$ – double scalar
2:     $\mathrm{xi}$ – double scalar
${x}_{r}$ and ${x}_{i}$, the real and imaginary parts of $x$, respectively.
3:     $\mathrm{yr}$ – double scalar
4:     $\mathrm{yi}$ – double scalar
${y}_{r}$ and ${y}_{i}$, the real and imaginary parts of $y$, respectively.

None.

### Output Parameters

1:     $\mathrm{zr}$ – double scalar
2:     $\mathrm{zi}$ – double scalar
${z}_{r}$ and ${z}_{i}$, the real and imaginary parts of $z$, respectively.

None.

## Accuracy

The result should be correct to machine precision.

The time taken by nag_complex_divide (a02ac) is negligible.
This function must not be called with ${\mathbf{yr}}=0.0$ and ${\mathbf{yi}}=0.0$.

## Example

This example finds the value of $\left(-1.7+2.6i\right)/\left(-3.1-0.9i\right)$.
```function a02ac_example

fprintf('a02ac example results\n\n');

xr = -1.7;
xi = 2.6;
yr = -3.1;
yi = -0.9;
x = xr+i*xi;
y = yr+i*yi;

[zr, zi] = a02ac(xr, xi, yr, yi);

z = zr+i*zi;

fprintf('The value of x/y, where\n');
fprintf('    x = ');
disp(x);
fprintf('and y = ');
disp(y);
fprintf('     is ');
disp(z);

```
```a02ac example results

The value of x/y, where
x =   -1.7000 + 2.6000i

and y =   -3.1000 - 0.9000i

is    0.2812 - 0.9203i

```