3.5 Environmental Inquiry

Next: 4 Data Parallelism Up: 3 Numerical Robustness Previous: 3.4 The Numeric Approximation

## 3.5 Environmental Inquiry

There are nine important model-related values that are fixed for and characteristic of a given real kind; these values constitute a sort of ``fingerprint" for the kind and are useful in various computational contexts. The environmental inquiry intrinsic functions allow the programmer to access these values at any time, in (a) numerical expressions in declaration of data objects and(b) any computation. Each of these environmental intrinsics takes a single argument, which may be a constant, scalar variable, or array variable. If it is a variable, its value need not be defined because only the type kind of the argument is used by these functions, not the value of the argument. These nine characteristic values and related environmental intrinsic functions shown in Table 2:

Table 2 Environmental Intrinsic Functions. View Table

Of these nine values, HUGE, TINY, and EPSILON are especially useful in writing robust portable numerical software, though in specialized contexts the others are tantamount to indispensable.

The seven numeric manipulation functions allow the programmer to access important model values related to a given specific value of that kind. The given value is the value of the (first) argument, which may be any expression that has a (defined) value of that kind. (Three of these seven functions also have a second argument.) These seven useful values and the related numeric manipulation intrinsic functions are shown in Table 3:

Table 3 Numerical Manipulation Functions. View Table

An (idealized) example will illustrate the use of these functions for writing robust portable code. In this example Newton's method is used to find the root to maximum accuracy (for the real kind being used) of a function F, in the minimum number of iterations. This example assumes the function F and its derivative function DF are available, and that the value X is already established in a region in which Newton's method will converge to the root.

```...
do
DX = F(X)/DF(X)                 ! Compute the next delta-X.
X = X-DX
if (DX<2*spacing(X)) exit       ! Stop if near the spacing
end do                           !  limits of that kind
...                              !      in this region.```

Next: 4 Data Parallelism Up: 3 Numerical Robustness Previous: 3.4 The Numeric Approximation

verena@csep1.phy.ornl.gov