X03 Chapter Contents
X03 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentX03AAF

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

X03AAF calculates the value of a scalar product using basic precision or additional precision and adds it to a basic precision or additional precision initial value.

## 2  Specification

 SUBROUTINE X03AAF ( A, ISIZEA, B, ISIZEB, N, ISTEPA, ISTEPB, C1, C2, D1, D2, SW, IFAIL)
 INTEGER ISIZEA, ISIZEB, N, ISTEPA, ISTEPB, IFAIL REAL (KIND=nag_wp) A(ISIZEA), B(ISIZEB), C1, C2, D1, D2 LOGICAL SW

## 3  Description

X03AAF calculates the scalar product of two real vectors and adds it to an initial value $c$ to give a correctly rounded result $d$:
 $d=c+∑i=1naibi.$
If $n<1$, $d=c$.
The vector elements ${a}_{i}$ and ${b}_{i}$ are stored in selected elements of the one-dimensional array parameters A and B, which in the subroutine from which X03AAF is called may be identified with parts of possibly multidimensional arrays according to the standard Fortran rules. For example, the vectors may be parts of a row or column of a matrix. See Section 5 for details, and Section 9 for an example.
Both the initial value $c$ and the result $d$ are defined by a pair of real variables, so that they may take either basic precision or additional precision values.
 (a) If ${\mathbf{SW}}=\mathrm{.TRUE.}$, the products are accumulated in additional precision, and on exit the result is available either in basic precision, correctly rounded, or in additional precision. (b) If ${\mathbf{SW}}=\mathrm{.FALSE.}$, the products are accumulated in basic precision, and the result is returned in basic precision.
This routine is designed primarily for use as an auxiliary routine by other routines in the NAG Library, especially those in the chapters on Linear Algebra.
None.

## 5  Parameters

1:     A(ISIZEA) – REAL (KIND=nag_wp) arrayInput
On entry: the elements of the first vector.
The $i$th vector element is stored in the array element ${\mathbf{A}}\left(\left(i-1\right)×{\mathbf{ISTEPA}}+1\right)$. In your subroutine from which X03AAF is called, A can be part of a multidimensional array and the actual argument must be the array element containing the first vector element.
2:     ISIZEA – INTEGERInput
On entry: the dimension of the array A as declared in the (sub)program from which X03AAF is called.
The upper bound for ISIZEA is found by multiplying together the dimensions of A as declared in your subroutine from which X03AAF is called, subtracting the starting position and adding $1$.
Constraint: ${\mathbf{ISIZEA}}\ge \left({\mathbf{N}}-1\right)×{\mathbf{ISTEPA}}+1$.
3:     B(ISIZEB) – REAL (KIND=nag_wp) arrayInput
On entry: the elements of the second vector.
The $i$th vector element is stored in the array element ${\mathbf{B}}\left(\left(i-1\right)×{\mathbf{ISTEPB}}+1\right)$. In your subroutine from which X03AAF is called, B can be part of a multidimensional array and the actual argument must be the array element containing the first vector element.
4:     ISIZEB – INTEGERInput
On entry: the dimension of the array B as declared in the (sub)program from which X03AAF is called.
The upper bound for ISIZEB is found by multiplying together the dimensions of B as declared in your subroutine from which X03AAF is called, subtracting the starting position and adding $1$.
Constraint: ${\mathbf{ISIZEB}}\ge \left({\mathbf{N}}-1\right)×{\mathbf{ISTEPB}}+1$.
5:     N – INTEGERInput
On entry: $n$, the number of elements in the scalar product.
6:     ISTEPA – INTEGERInput
On entry: the step length between elements of the first vector in array A.
Constraint: ${\mathbf{ISTEPA}}>0$.
7:     ISTEPB – INTEGERInput
On entry: the step length between elements of the second vector in array B.
Constraint: ${\mathbf{ISTEPB}}>0$.
8:     C1 – REAL (KIND=nag_wp)Input
9:     C2 – REAL (KIND=nag_wp)Input
On entry: C1 and C2 must specify the initial value $c$: $c={\mathbf{C1}}+{\mathbf{C2}}$. Normally, if $c$ is in additional precision, C1 specifies the most significant part and C2 the least significant part; if $c$ is in basic precision, then C1 specifies $c$ and C2 must have the value $0.0$. Both C1 and C2 must be defined on entry.
10:   D1 – REAL (KIND=nag_wp)Output
11:   D2 – REAL (KIND=nag_wp)Output
On exit: the result $d$.
If the calculation is in additional precision (${\mathbf{SW}}=\mathrm{.TRUE.}$),
• ${\mathbf{D1}}=d$ rounded to basic precision;
• ${\mathbf{D2}}=d-{\mathbf{D1}}$,
thus D1 holds the correctly rounded basic precision result and the sum ${\mathbf{D1}}+{\mathbf{D2}}$ gives the result in additional precision. D2 may have the opposite sign to D1.
If the calculation is in basic precision (${\mathbf{SW}}=\mathrm{.FALSE.}$),
• ${\mathbf{D1}}=d$;
• ${\mathbf{D2}}=0.0$.
12:   SW – LOGICALInput
On entry: the precision to be used in the calculation.
${\mathbf{SW}}=\mathrm{.TRUE.}$
${\mathbf{SW}}=\mathrm{.FALSE.}$
basic precision.
13:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{ISTEPA}}\le 0$, or ${\mathbf{ISTEPB}}\le 0$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{ISIZEA}}>\left({\mathbf{N}}-1\right)×{\mathbf{ISTEPA}}+1$, or ${\mathbf{ISIZEB}}>\left({\mathbf{N}}-1\right)×{\mathbf{ISTEPB}}+1$.

## 7  Accuracy

If the calculation is an additional precision, the rounded basic precision result D1 is correct to full implementation accuracy, provided that exceptionally severe cancellation does not occur in the summation. If the calculation is in basic precision, such accuracy cannot be guaranteed.

The time taken by X03AAF is approximately proportional to $n$ and also depends on whether basic precision or additional precision is used.
On exit the variables D1 and D2 may be used directly to supply a basic precision or additional precision initial value for a subsequent call of X03AAF.

## 9  Example

This example calculates the scalar product of the second column of the matrix $A$ and the vector ${\mathbf{B}}$, and add it to an initial value $1.0$ where
 $A= -2 -3 7 2 -5 3 -9 1 0 , B= 8 -4 -2 .$

### 9.1  Program Text

Program Text (x03aafe.f90)

### 9.2  Program Data

Program Data (x03aafe.d)

### 9.3  Program Results

Program Results (x03aafe.r)