A02 Chapter Contents
A02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentA02ABF

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

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

## 2  Specification

 FUNCTION A02ABF ( XR, XI)
 REAL (KIND=nag_wp) A02ABF
 REAL (KIND=nag_wp) XR, XI

## 3  Description

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

## 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.

None.

## 7  Accuracy

The result should be correct to machine precision.

None.

## 9  Example

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

### 9.1  Program Text

Program Text (a02abfe.f90)

### 9.2  Program Data

Program Data (a02abfe.d)

### 9.3  Program Results

Program Results (a02abfe.r)