A02 Chapter Contents
A02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentA02AAF

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

A02AAF evaluates the square root of the complex number $x=\left({x}_{r},{x}_{i}\right)$.

## 2  Specification

 SUBROUTINE A02AAF ( XR, XI, YR, YI)
 REAL (KIND=nag_wp) XR, XI, YR, YI

## 3  Description

The method of evaluating $y=\sqrt{x}$ depends on the value of ${x}_{r}$.
For ${x}_{r}\ge 0$,
 $yr=xr+xr2+xi2 2, yi=xi2yr .$
For ${x}_{r}<0$,
 $yi=signxi×xr+xr2+xi2 2 , yr=xi2yi .$
Overflow is avoided when squaring ${x}_{i}$ and ${x}_{r}$ by calling A02ABF to evaluate $\sqrt{{x}_{r}^{2}+{x}_{i}^{2}}$.

## 4  References

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

## 5  Parameters

1:     XR – REAL (KIND=nag_wp)Input
2:     XI – REAL (KIND=nag_wp)Input
On entry: ${x}_{r}$ and ${x}_{i}$, the real and imaginary parts of $x$, respectively.
3:     YR – REAL (KIND=nag_wp)Output
4:     YI – REAL (KIND=nag_wp)Output
On exit: ${y}_{r}$ and ${y}_{i}$, the real and imaginary parts of $y$, respectively.

None.

## 7  Accuracy

The result should be correct to machine precision.

The time taken by A02AAF is negligible.

## 9  Example

This example finds the square root of $-1.7+2.6i$.

### 9.1  Program Text

Program Text (a02aafe.f90)

### 9.2  Program Data

Program Data (a02aafe.d)

### 9.3  Program Results

Program Results (a02aafe.r)