# NAG FL Interfacea02aaf (sqrt)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine a02aaf ( xr, xi, yr, yi)
 Real (Kind=nag_wp), Intent (In) :: xr, xi Real (Kind=nag_wp), Intent (Out) :: yr, yi
#include <nag.h>
 void a02aaf_ (const double *xr, const double *xi, double *yr, double *yi)
The routine may be called by the names a02aaf or nagf_complex_sqrt.

## 3Description

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=sign(xi)×|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}}$.
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## 5Arguments

1: $\mathbf{xr}$Real (Kind=nag_wp) Input
2: $\mathbf{xi}$Real (Kind=nag_wp) Input
On entry: ${x}_{r}$ and ${x}_{i}$, the real and imaginary parts of $x$, respectively.
3: $\mathbf{yr}$Real (Kind=nag_wp) Output
4: $\mathbf{yi}$Real (Kind=nag_wp) Output
On exit: ${y}_{r}$ and ${y}_{i}$, the real and imaginary parts of $y$, respectively.

None.

## 7Accuracy

The result should be correct to machine precision.

## 8Parallelism and Performance

a02aaf is not threaded in any implementation.

The time taken by a02aaf is negligible.

## 10Example

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

### 10.1Program Text

Program Text (a02aafe.f90)

### 10.2Program Data

Program Data (a02aafe.d)

### 10.3Program Results

Program Results (a02aafe.r)