Interval Arithmetic Programming Reference HomeContentsPreviousNextIndex


Chapter 2

f95 Interval Reference

This chapter is a reference for the syntax and semantics of the intrinsic INTERVAL types implemented in Sun WorkShop 6 Fortran 95. The sections can be read in any order.

Unless explicitly stated otherwise, the INTERVAL data type has the same properties as other intrinsic numeric types. This chapter highlights differences between the REAL and INTERVAL types.

Some code examples are not complete programs. The implicit assumption is that these examples are compiled with the -xia command line option.

2.1 Fortran Extensions

INTERVAL data types are a non-standard extension to Fortran. However, where possible, the implemented syntax and semantics conform to the style of Fortran.

2.1.1 Character Set Notation

Left and right square brackets, "[...]", are added to the Fortran character set to delimit literal INTERVAL constants.

Throughout this document, unless explicitly stated otherwise, INTEGER, REAL, and INTERVAL constants mean literal constants. Constant expressions and named constants (PARAMETERS) are always explicitly identified as such.

TABLE 2-1 shows the character set notation used for code and mathematics.

TABLE 2-1   Font Conventions
Character Set Notation
Fortran code
INTERVAL :: X=[0.1,0.2]
Input to programs and commands
Enter X: ? [2.3,2.4]
Placeholders for constants in code
[a,b]
Scalar mathematics x(a + b) = xa + xb
Interval mathematics X(A + B) XA + XB



Note – Pay close attention to font usage. Different fonts represent an interval's exact, external mathematical value and an interval's machine-representable, internal approximation.

2.1.2 INTERVAL Constants

In f95, an INTERVAL constant is either a single integer or real decimal number enclosed in square brackets, [3.5], or a pair of integer or real decimal numbers separated by a comma and enclosed in square brackets, [3.5 E-10, 3.6 E-10]. If a degenerate interval is not machine representable, directed rounding is used to round the exact mathematical value to an internal machine representable interval known to satisfy the containment constraint.

An INTERVAL constant with both endpoints of type default INTEGER, default REAL or REAL(8), has the default type INTERVAL.

If an endpoint is of type default INTEGER, default REAL or REAL(8), it is internally converted to a value of the type REAL(8).

If an endpoint's type is INTEGER(8), it is internally converted to a value of type REAL(16).

If an endpoint's type is INTEGER(4), it is internally converted to a value of type REAL(8).

If an endpoint's type is INTEGER(1) or INTEGER(2), it is internally converted to a value of type REAL(4).

If both endpoints are of type REAL but have different KTPVs, they are both internally represented using the approximation method of the endpoint with greater decimal precision.

The KTPV of an INTERVAL constant is the KTPV of the part with the greatest decimal precision.

CODE EXAMPLE 2-1 shows the KTPV of various INTERVAL constants.

CODE EXAMPLE 2-1   KTPV of INTERVAL Constants

math% cat ce2-1.f95
IF(KIND([9_8, 9.0])      == 16 .AND. &
   KIND([9_8, 9_8])      == 16 .AND. & 
   KIND([9_4, 9_4])      == 8  .AND. & 
   KIND([9_2, 9_2])      == 4  .AND. &
   KIND([9, 9.0_16])     == 16 .AND. & 
   KIND([9, 9.0])        == 8  .AND. & 
   KIND([9, 9])          == 8  .AND. & 
   KIND([9.0_4, 9.0_4])  == 4  .AND. & 
   KIND([1.0Q0, 1.0_16]) == 16 .AND. & 
   KIND([1.0_8, 1.0_4])  == 8  .AND. & 
   KIND([1.0E0, 1.0Q0])  == 16 .AND. & 
   KIND([1.0E0, 1])      == 8  .AND. & 
   KIND([1.0Q0, 1])      == 16 ) PRINT *, 'Check'
END
math% f95 -xia ce2-1.f95

A Fortran constant, such as 0.1 or [0.1,0.2], is associated with the two values: the external value it represents and its internal approximation. In Fortran, the value of a constant is its internal approximation. There is no need to distinguish between a constant's external value and its internal approximation. Intervals require this distinction to be made. To represent a Fortran constant's external value, the following notation is used:

ev(0.1) = 0.1 or ev([0.1,0.2])= [0.1, 0.2].

The notation ev stands for external value.

Following the Fortran Standard, the numerical value of an INTERVAL constant is its internal approximation. The external value of an INTERVAL constant is always explicitly labelled as such.

For example, the INTERVAL constant [1, 2] and its external value ev([1, 2]) are equal to the mathematical value [1, 2]. However, while ev([0.1, 0.2]) = [0.1, 0.2], [0.1, 0.2] is only an internal machine approximation, because the numbers 0.1 and 0.2 are not machine representable. The value of the INTERVAL constant, [0.1, 0.2] is its internal machine approximation. The external value is denoted ev([0.1, 0.2]).

Under strict expression processing, an INTERVAL constant's internal approximation is fixed, as it is for other Fortran numeric typed constants. The value of a REAL constant is its internal approximation. Similarly, the value of an INTERVAL constant's internal approximation is referred to as the constant's value. A constant's external value, which is not a defined concept in standard Fortran, can be different from its internal approximation. Under widest-need expression processing, an INTERVAL constant's internal value is context-dependent. Nevertheless, an INTERVAL constant's internal approximation must contain its external value in both strict and widest-need expression processing.

Like any mathematical constant, the external value of an INTERVAL constant is invariant. The external value of a named INTERVAL constant (PARAMETER) cannot change within a program unit. However, as with any named constant, in different program units, different values can be associated with the same named constant.

Because intervals are opaque, there is no language requirement to store the information needed to internally represent an interval. Intrinsic functions are provided to access the infimum and supremum of an interval. Nevertheless, an INTERVAL constant is defined by an ordered pair of REAL or INTEGER constants. The constants are separated by a comma, and the pair is enclosed in square brackets. The first constant is the infimum or lower bound, and the second, is the supremum or upper bound.

If only one constant appears inside the square brackets, the represented interval is degenerate, having equal infimum and supremum. In this case, an internal interval approximation is constructed that is guaranteed to contain the single decimal literal constant's external value.

A valid interval must have an infimum that is less than or equal to its supremum. Similarly, an INTERVAL constant must also have an infimum that is less than or equal to its supremum. For example, the following code fragment must evaluate to true:

INF([0.1]) .LE. SUP([0.1]).

CODE EXAMPLE 2-2 contains examples of valid and invalid INTERVAL constants.

For additional information regarding INTERVAL constants, see the supplementary paper [4] cited in Section 2.10 References.

CODE EXAMPLE 2-2   Valid and Invalid INTERVAL Constants

X=[2,3]
X=[0.1] 	 ! Line 2: Interval containing the decimal number 1/10
X=[2, ] 	 ! Line 3: Invalid - missing supremum
X=[3_2,2_2] 	 ! Line 4: Invalid - infimum > supremum
X=[2_8,3_8]
X=[2,3_8]
X=[0.1E0_8]
X=[2_16,3_16]
X=[2,3_16]
X=[0.1E0_16]

2.1.3 Internal Approximation

The internal approximation of a REAL constant does not necessarily equal the constant's external value. For example, because the decimal number 0.1 is not a member of the set of binary floating-point numbers, this value can only be approximated by a binary floating-point number that is close to 0.1. For REAL data items, the approximation accuracy is unspecified in the Fortran standard. For INTERVAL data items, a pair of floating-point values is used that is known to contain the set of mathematical values defined by the decimal numbers used to symbolically represent an INTERVAL constant. For example, the mathematical interval [0.1, 0.2] is the external value of the INTERVAL constant [0.1,0.2].

Just as there is no Fortran language requirement to accurately approximate REAL constants, there is also no language requirement to approximate an interval's external value with a narrow width INTERVAL constant. There is a requirement for an INTERVAL constant to contain its external value.

ev(INF([0.1,0.2])) inf(ev([0.1,0.2])) = inf([0.1, 0.2])

and

sup([0.1, 0.2]) = sup(ev([0.1,0.2])) ev(SUP([0.1,0.2]))

f95 INTERVAL constants are sharp. This is a quality of implementation feature.

2.1.4 INTERVAL Statement

The INTERVAL declaration statement is the only INTERVAL-specific statement added to the Fortran language in f95. For a detailed description of the INTERVAL declaration statement and standard Fortran statements that interact with INTERVAL data items, see INTERVAL Statements.

2.2 Data Type and Data Items

If the -xia or -xinterval options are entered in the f95 command line, or if they are set either to widestneed or to strict, the INTERVAL data type is recognized as an intrinsic numeric data type in f95. If neither option is entered in the f95 command line, or if they are set to no, the INTERVAL data type is not recognized as intrinsic. See Section 2.3.3 Interval Command-Line Options for details on the INTERVAL command-line options.

2.2.1 Name: INTERVAL

The intrinsic type INTERVAL is added to the six intrinsic Fortran data types. The INTERVAL type is opaque, meaning that an INTERVAL data item's internal format is not specified. Nevertheless, an INTERVAL data item's external format is a pair of REAL data items having the same kind type parameter value (KTPV) as the INTERVAL data item.

2.2.2 Kind Type Parameter Value (KTPV)

An INTERVAL data item is an approximation of a mathematical interval consisting of a lower bound or infimum and an upper bound or supremum. INTERVAL data items have all the properties of other numeric data items.

The KTPV of a default INTERVAL data item is 8. The size of a default INTERVAL data item with no specified KTPV is 16 bytes. The size of a default INTERVAL data item in f95 cannot be changed using the -xtypemap or -r8const command line options. For more information, see Section 2.3.3.1 -xtypemap and -r8const Command-Line Options. Thus

KIND([0])= 2*KIND(0) = KIND(0.0_8) = 8

provided the size of the default REAL and INTEGER data items is not changed using -xtypemap.

2.2.2.1 Size and Alignment Summary

The size and alignment of INTERVAL types is unaffected by f95 compiler options. TABLE 2-2 contains INTERVAL sizes and alignments.

TABLE 2-2   INTERVAL Sizes and Alignments
Data Type Byte Size Alignment
INTERVAL
INTERVAL(4)
INTERVAL(8)
INTERVAL(16)
16
8
16
32
8
4
8
16



Note – INTERVAL arrays align the same as their elements.

2.2.3 INTERVAL Arrays

INTERVAL arrays have all the properties of arrays with different numeric types. See CODE EXAMPLE 2-25 for the declaration of INTERVAL arrays.

Interval versions of the following intrinsic array functions are supported:

ALLOCATED(), ASSOCIATED(), CSHIFT(), DOT_PRODUCT(), EOSHIFT(), KIND(), LBOUND(), MATMUL(), MAXVAL(), MERGE(), MINVAL(), NULL(), PACK(), PRODUCT(), RESHAPE(), SHAPE(), SIZE(), SPREAD(), SUM(), TRANSPOSE(), UBOUND(), UNPACK().

The MINLOC(), and MAXLOC() intrinsic functions are not defined for INTERVAL arrays because the MINVAL and MAXVAL intrinsic applied to an INTERVAL array may return an interval value not possessed by any element of the array. See the following sections for descriptions of the MAX and MIN intrinsic functions

For example MINVAL((/[1,2],[3,4]/)) = [1,3] and

MAXVAL(/[1,2],[3,4]/) = [2,4].

Array versions of the following intrinsic INTERVAL-specific functions are supported: ABS(), INF(), INT(), MAG(), MAX(), MID(), MIG(), MIN(), NDIGITS(), SUP(), WID().

Array versions of the following intrinsic INTERVAL-mathematical functions are supported: ACOS(), AINT(), ANINT(), ASIN(), ATAN(), ATAN2(), CEILING(), COS(), COSH(), EXP(), FLOOR(), LOG(), LOG10(), MOD(), SIGN(), SIN(), SINH(), SQRT(), TAN(), TANH().

Array versions of the following INTERVAL constructors are supported: INTERVAL(), DINTERVAL(), SINTERVAL(), QINTERVAL().

2.3 INTERVAL Arithmetic Expressions

INTERVAL arithmetic expressions are constructed from the same arithmetic operators as other numerical data types. The fundamental difference between INTERVAL and non-INTERVAL (point) expressions is that the result of any possible INTERVAL expression is a valid INTERVAL that satisfies the containment constraint of interval arithmetic. In contrast, point expression results can be any approximate value.

2.3.1 Mixed-Mode INTERVAL Expressions

Mixed-mode (INTERVAL-point) expressions require widest-need expression processing to guarantee containment. Expression processing is widest-need by default when support for intervals is invoked using either the -xia command-line macro or the -xinterval command line option. If widest-need expression processing is not wanted, use the options -xia=strict or -xinterval=strict to invoke strict expression processing. Mixed-mode INTERVAL expressions are compile-time errors under strict expression processing. Mixed-mode operations between INTERVAL and COMPLEX operands are not supported.

With widest-need expression processing, the KTPV of all operands in an interval expression is promoted to KTPVmax, the highest INTERVAL KTPV found anywhere in the expression.


Note – KTPV promotion is performed before expression evaluation.

Widest-need expression processing guarantees:

Each of the following examples is designed to illustrate the behavior and utility of widest-need expression processing. There are three blocks of code in each example:

The examples are designed to communicate three messages:

2.3.2 Value Assignment

The INTERVAL assignment statement assigns a value of an INTERVAL scalar, array element, or array expression to an INTERVAL variable, array element or array. The syntax is:

V = expr

where expr is a placeholder for an interval arithmetic or array expression, and V is an INTERVAL variable, array element, or array.

Executing an INTERVAL assignment causes the expression to be evaluated using either widest-need or strict expression processing. The resulting value is then assigned to V. The following steps occur when evaluating an expression using widest-need expression processing:

  1. The interval KTPV of every point (non-INTERVAL) data item is computed.

    If the point item is an integer, the resulting interval KTPV is twice the integer's KTPV. Otherwise an interval's KTPV is the same as the point item's KTPV.

  2. The expression, including the left-hand side of an assignment statement, is scanned for the maximum interval KTPV, denoted KTPVmax.

  3. All point and INTERVAL data items in the INTERVAL expression are promoted to KTPVmax, prior to evaluating the expression.

  4. If KIND(V) < KTPVmax, the expression result is converted to a containing interval with KTPV = KIND(V) and the resulting value is assigned to V.

CODE EXAMPLE 2-3   KTPVmax Depends on KIND (Left-Hand Side)

math% cat ce2-3.f95
INTERVAL(4)  :: X1, Y1
INTERVAL     :: X2, Y2          ! Same as: INTERVAL(8) :: X2, Y2 
INTERVAL(16) :: X3, Y3
 
! Widest-need code
 X1 = 0.1                                            
 X2 = 0.1                                
 X3 = 0.1
 
! Equivalent strict code
Y1 = [0.1_4]
Y2 = [0.1_8]
Y3 = [0.1_16]
 
IF(X1 .SEQ. Y1)  PRINT *, "Check1."
IF(X2 .SEQ. Y2)  PRINT *, "Check2."
IF(X3 .SEQ. Y3)  PRINT *, "Check3."
END 
 
math% f95 -xia ce2-3.f95
math% a.out
 Check1.
 Check2.
 Check3.

.


Note – Under widest-need, the KTPV of the variable to which assignment is made (the left-hand side) is included in determining the value of KTPVmax to which all items in an INTERVAL statement are promoted.

CODE EXAMPLE 2-4   Mixed-Mode Assignment Statement

math% cat ce2-4.f95
INTERVAL(4) :: X1, Y1
INTERVAL(8) :: X2, Y2
REAL(8)     :: R = 0.1
 
! Widest-need code
 X1 = R*R 	 ! Line 4
 X2 = X1*R 	 ! Line 5
 
! Equivalent strict  code
 Y1 = INTERVAL((INTERVAL(R, KIND=8)*INTERVAL(R, KIND=8)), KIND=4	 )! Line 6
 Y2 = INTERVAL(X1, KIND=8)*INTERVAL(R, KIND=8) 	 ! Line 7
 
IF((X1 == Y1)) PRINT *, "Check1." 	 ! Line 8
IF((X2 == Y2)) PRINT *, "Check2." 	 ! Line 9
END
 
math% f95 -xia ce2-4.f95
math% a.out
 Check1.
 Check2.

CODE EXAMPLE 2-4 notes:

2.3.3 Interval Command-Line Options

Interval features in the f95 compiler are activated by means of the following command-line options:

It is a fatal error if at the end of command line processing xinterval=(widestneed|strict) is set, and either -fsimple or -fns is set to any value other than
-fsimple=0
-fns=no

When using command-line options:

When recognition of INTERVAL types is activated:

2.3.3.1 -xtypemap and -r8const Command-Line Options

The size of a default INTERVAL variable declared only with the INTERVAL keyword cannot be changed using the -xtypemap and -r8const command line options.

While these command line options have no influence on the size of default INTERVAL types, the options can change the result of mixed-mode INTERVAL expressions, as shown in CODE EXAMPLE 2-5.

CODE EXAMPLE 2-5   Mixed-Mode Expression
math% cat ce2-5.f95
REAL     :: R 
INTERVAL :: X
R = 1.0E0 - 1.0E-15
PRINT *, 'R = ', R
X = 1.0E0 - R
PRINT *, 'X = ', X
IF (  0.0 .IN. X  ) THEN 
    PRINT *, 'X contains zero'
ELSE 
    PRINT *, 'X does not contain zero'
ENDIF    
PRINT *, 'WID(X) = ', WID(X)
END
math% f95 -xia ce2-5.f95
math% a.out
 R =  1.0
 X =  [0.0E+0,0.0E+0]
 X contains zero
 WID(X) =  0.0E+0
math% f95 -xia -xtypemap=real:64,double:64,integer:64 ce2-5.f95 
math% a.out
 R =  0.999999999999999
 X =  [9.9920072216264088E-16,9.9920072216264089E-16]
 X does not contain zero
 WID(X) =  0.0E+0


Note – Although -xtypemap has no influence on the KTPV of X, it can influence the value of X.

2.3.4 Constant Expressions

INTERVAL constant expressions may contain INTERVAL literal and named constants, as well as any point constant expression components. Therefore, each operand or argument is itself, another constant expression, a constant, a named constant, or an intrinsic function called with constant arguments.

CODE EXAMPLE 2-6   Constant Expressions

math% cat ce2-6.f95
INTERVAL :: P, Q
! Widest-need code
P = SIN([1.23])+[3.45]/[9, 11.12]
 
! Equivalent strict code
Q = SIN([1.23_8])+[3.45_8]/[9.0_8, 11.12_8]
IF(P .SEQ. Q) PRINT *, 'Check'
END
math% f95 -xia ce2-6.f95
math% a.out
 Check


Note – Under widest-need expression processing, interval context is used to determine the KTPV of INTERVAL constants. See Section 1.3.7 Default Kind Type Parameter Value (KTPV) for more information.

INTERVAL constant expressions are permitted wherever an INTERVAL constant is allowed.

2.4 Intrinsic Operators

TABLE 2-3 lists the intrinsic operators that can be used with intervals. In TABLE 2-3, X and Y are intervals.

TABLE 2-3   INTRINSIC Operators
Operator Operation Expression Meaning
** Exponentiation X**Y Raise X to the INTERVAL power Y


X**N Raise X to the INTEGER power N (See Note 1)
* Multiplication X*Y Multiply X and Y
/ Division X/Y Divide X by Y
+ Addition X+Y Add X and Y
+ Identity +X Same as X (without a sign)
- Subtraction X-Y Subtract Y from X
- Numeric Negation -X Negate X
.IH. INTERVAL hull X.IH.Y Interval hull of X and Y
.IX. Intersection X.IX.Y Intersect X and Y
1. If N is an integer expression, overflow can cause a containment failure. Users must be responsible for preventing integer overflow in this release. See Section 1.5.1.1 Integer Overflow for more information.


Precedence of operators:

With the exception of the interval ** operator and an integer exponent, interval operators can only be applied to two interval operands with the same kind type parameter value. Thus the type and KTPV of an interval operator's result are the same as the type and KTPV of its operands.

If the second operand of the interval ** operator is an integer, the first operand can be of any interval KTPV. In this case, the result has the type and KTPV of the first operand.

Some INTERVAL-specific operators have no point analogs. These can be grouped into three categories: set, certainly, and possibly, as shown in TABLE 2-4. A number of unique set-operators have no certainly or possibly analogs.

TABLE 2-4   Intrinsic INTERVAL Relational Operators
Set Relational Operators
.SP.
.PSP
.SB.
.PSB.
.IN.
.DJ.

.EQ.
(same as ==)
.NEQ.
(same as /=)

.SEQ.
.SNE.
.SLT.
.SLE.
.SGT.
.SGE.
Certainly Relational Operators
.CEQ.
.CNE.
.CLT.
.CLE.
.CGT.
.CGE.
Possibly Relational Operators
.PEQ.
.PNE.
.PLT.
.PLE.
.PGT.
.PGE.


The precedence of intrinsic INTERVAL relational operators is the same as the precedence of REAL relational operators.

Except for the .IN. operator, intrinsic INTERVAL relational operators can only be applied to two INTERVAL operands with the same KTPV.

The first operand of the .IN. operator is of any INTEGER or REAL type. The second operand can have any interval KTPV.

The result of the INTERVAL relational expression has the default LOGICAL kind type parameter.

2.4.1 Arithmetic Operators +, -, *, /

Formulas for computing the endpoints of interval arithmetic operations on finite REAL intervals are motivated by the requirement to produce the narrowest interval that is guaranteed to contain the set of all possible point results. Ramon Moore independently developed these formulas and more importantly, was the first to develop the analysis needed to apply interval arithmetic. For more information, see R. Moore, Interval Analysis, Prentice-Hall, 1966.

The set of all possible values was originally defined by performing the operation in question on any element of the operand intervals. Therefore, given finite intervals, [a, b] and [c, d], with ,

,

with division by zero being excluded. The formulas, or their logical equivalent, are:

Directed rounding is used when computing with finite precision arithmetic to guarantee the set of all possible values is contained in the resulting interval.

The set of values that any interval result must contain is called the containment set of the operation or expression that produces the result.

To include extended intervals (with infinite endpoints) and division by zero, containment sets cannot directly depend on the value of arithmetic operations on real values. For extended intervals, containment sets are required for operations on points that are normally undefined. Undefined operations include the indeterminate forms .

The containment-set closure identity solves the problem of identifying the value of containment sets of expressions at singular or indeterminate points. The identity states that containment sets are closures. The closure of a function at a point on the boundary of its domain includes all limit or accumulation points. For details, see the Glossary and the supplementary papers [1], [3], [10], and [11] cited in Section 2.10 References.

Symbolically, cset(x op y, {(x0, y0)}) = , where denotes the closure of the operation, op, and {x0} denotes the singleton set with only one element, x0. The subscript 0 is used to symbolically distinguish a particular value, x0, of the variable, x, from the variable itself. For example, with x0 = 1, op = ÷, and y0 = 0, x0³ ÷ y0 is undefined, but the closure, .

This result is obtained using the sequences

or ,

both of whose limits are

Using the two sequences, {yj}, above, the closure of the division operator at x0 = 1 and y0 = 0 is:

The following tables, TABLE 2-5 through TABLE 2-9, display containment sets for the four basic arithmetic operations.

TABLE 2-5   Containment Set for Addition: cset(x +y, {(x0, y0)})
cset(x + y, {(x0, y0)}) {-} {real: y0} {+}
{-} {-} {-}
{real: x0} {-} {x0 + y0} {+}
{+} {+} {+}


TABLE 2-6   Containment Set for Subtraction: cset(x - y, {(x0, y0)})
cset(x - y, {(x0, y0)}) {-} {real: y0} {+}
{-} {-} {-}
{real: x0} {+} {x0 - y0} {-}
{+} {+} {+}


TABLE 2-7   Containment Set for Multiplication: cset(x × y, {(x0, y0)})
cset(x × y, {(x0, y0)}) {-} {real: y0 < 0} {0} {real: y0 > 0} {+}
{-} {+} {+} {-} {-}
{real: x0 < 0} {+} {x × y} {0} {x × y} {-}
{0} {0} {0} {0}
{real: x0 > 0} {-} x × y {0} x × y {+}
{+} {-} {-} {+} {+}


TABLE 2-8   Containment Set for Division: cset(x ÷ y, {(x0, y0)})
cset(x ÷ y, {(x0, y0)}) {-} {real: y0 < 0} {0} {real: y0 > 0} {+}
{-} [0, +] {+} {-, +} {-} [-, 0]
{real: x0 0} {0} {x ÷ y} {-, +} {x ÷ y} {0}
{0} {0} {0} {0} {0}
{+} [-, 0] {-} {-, +} {+} [0, +]


All inputs in the tables are shown as singletons. Results are shown as singletons, sets, or intervals. To avoid ambiguity, customary notation, such as , , and , is not used. These tables show the results for singleton-set inputs to each operation. Results for general set (or interval) inputs are the union of the results of the single-point results as they range over the input sets (or intervals).

In one case, division by zero, the result is not an interval, but the set, . In this case, the narrowest interval in the current system that does not violate the containment constraint of interval arithmetic is the interval .

Sign changes produce the expected results.

To incorporate these results into the formulas for computing interval endpoints, it is only necessary to identify the desired endpoint, which is also encoded in the rounding direction. Using to denote rounding down (towards -) and to denote rounding up (towards +),

and .
and .

Similarly, because ,

and .

Finally, the empty interval is represented in Fortran by the character string [empty] and has the same properties as the empty set, denoted in the algebra of sets. Any arithmetic operation on an empty interval produces an empty interval result. For additional information regarding the use of empty intervals, see the supplementary papers [6] and [7] cited in Section 2.10 References.

Using these results, f95 implements the closed interval system. The system is closed because all arithmetic operations and functions always produce valid interval results. See the supplementary papers [2] and [8] cited in Section 2.10 References.

2.5 Power Operators X**N and X**Y

The power operator can be used with integer exponents (X**N) and continuous exponents (X**Y). With a continuous exponent, the power operator has indeterminate forms, similar to the four arithmetic operators.

In the integer exponents case, the set of all values that an enclosure of must contain is .

Monotonicity can be used to construct a sharp interval enclosure of the integer power function. When n = 0, cset(xn, {x0})= 1 for all , and [empty]**N = [empty] for all N.

In the continuous exponents case, the set of all values that an interval enclosure of must contain is

where is the containment set of the expression . The function exp(y ln (x)) makes explicit that only values of need be considered, and is consistent with the definition of X**Y with REAL arguments in Fortran.

The result is empty if either INTERVAL argument is empty, or if x < 0. This is also consistent with the point version of X**Y in Fortran.

TABLE 2-9 displays the containment sets for all the singularities and indeterminate forms of cset(exp(yln(x)), {(y0, x0)}).

TABLE 2-9   cset(exp(yln(x)), {(y0, x0)})
x0 y0 cset(exp(yln(x)), {(y0, x0))}
0 y0 < 0 +
1 - [0,+]
1 + [0,+]
+ 0 [0,+]
0 0 [0,+]


The results in TABLE 2-9 can be obtained in two ways:

For most compositions, the second option is much easier. If sufficient conditions are satisfied, the closure of a composition can be computed from the composition of its closures. That is, the closure of each sub-expression can be used to compute the closure of the entire expression. In the present case,

cset(exp(yln(x)), {x0, y0}) = .

It is always the case that

cset(exp(yln(x)), {x0, y0}) .

Note that this is exactly how interval arithmetic works on intervals. The needed closures of the ln and exp functions are:

A necessary condition for closure-composition equality is that the expression must be a single-use expression (or SUE), which means that each independent variable can appear only once in the expression.

In the present case, the expression is clearly a SUE.

The entries in TABLE 2-9 follow directly from using the containment set of the basic multiply operation in TABLE 2-7 on the closures of the ln and exp functions. For example, with x= 1 and y0 = -, ln(x0) = 0. For the closure of multiplication on the values - and 0 in TABLE 2-7, the result is [-, +]. Finally, exp([-, +]) = [0, +], the second entry in TABLE 2-9. Remaining entries are obtained using the same steps. These same results are obtained from the direct derivation of the containment set of exp(yln(x)). At this time, sufficient conditions for closure-composition equality of any expression have not been identified. Nevertheless,

2.6 Set Theoretic Operators

f95 supports the following set theoretic operators for determining the interval hull and intersection of two intervals.

2.6.1 Hull: X U Y or (X.IH.Y)

Description: Interval hull of two intervals. The interval hull is the smallest interval that contains all the elements of the operand intervals.

Mathematical definitions:

Arguments: X and Y must be intervals with the same KTPV.

Result type: Same as X.

2.6.2 Intersection: XY or (X.IX.Y)

Description: Intersection of two intervals.

Mathematical and operational definitions:


Arguments: X and Y must be intervals with the same KTPV.

Result type: Same as X.

2.7 Set Relations

f95 provides the following set relations that have been extended to support intervals.

2.7.1 Disjoint: X Y = or (X .DJ. Y)

Description: Test if two intervals are disjoint.

Mathematical and operational definitions:


Arguments: X and Y must be intervals with the same KTPV.

Result type: Default logical scalar.

2.7.2 Element: r Y or (R.IN. Y)

Description: Test if the number, R, is an element of the interval, Y.

Mathematical and operational definitions:

Arguments: The type of R is INTEGER or REAL, and the type of Y is INTERVAL.

Result type: Default logical scalar.

The following comments refer to the set relation:

2.7.3 Interior: (X .INT. Y)

Description: Test if X is in interior of Y.

The interior of a set in topological space is the union of all open subsets of the set.

For intervals, the relation X .INT. Y (X in interior of Y) means that X is a subset of Y, and both of the following relations are false:

Note also that, , but [empty] .INT. [empty] = true

The empty set is open and therefore is a subset of the interior of itself.

Mathematical and operational definitions:

Arguments: X and Y must be intervals with the same KTPV.

Result type: Default logical scalar.

2.7.4 Proper Subset: X Y or (X .PSB. Y)

Description: Test if X is a proper subset of Y

Mathematical and operational definitions:

Arguments: X and Y must be intervals with the same KTPV.

Result type: Default logical scalar.

2.7.5 Proper Superset: X Y or (X .PSP. Y)

Description: See proper subset with .

2.7.6 Subset: X Y or (X .SB. Y)

Description: Test if X is a subset of Y

Mathematical and operational definitions:



Arguments: X and Y must be intervals with the same KTPV.

Result type: Default logical scalar.

2.7.7 Superset: X Y or (X .SP. Y)

Description: See subset with .

2.7.8 Relational Operators

An intrinsic INTERVAL relational operator, denoted .qop., is composed by concatenating:

In place of .SEQ. and .SNE., .EQ. (or ==) and .NE. (or /=) defaults are accepted. To eliminate code ambiguity, all other INTERVAL relational operators must be made explicit by specifying a prefix.

All INTERVAL relational operators have equal precedence. Arithmetic operators have higher precedence than relational operators.

INTERVAL relational expressions are evaluated by first evaluating the two operands, after which the two expression values are compared. If the specified relationship holds, the result value is true; otherwise, it is false.

When widest-need expression processing is invoked, it applies to both INTERVAL operand expressions of INTERVAL relational operators.

Letting "nop" stand for the complement of the operator op, the certainly and possibly operators are related as follows:

.Cop. .NOT.(.Pnop.)
.Pop. .NOT.(.Cnop.)


Caution – This identity between certainly and possibly operators holds unconditionally if op  {EQNE}, and otherwise, only if neither operand is empty. Conversely, the identity does not hold if op  {LTLEGT, GE} and either operand is empty.

Assuming neither operand is empty, TABLE 2-10 contains the Fortran operational definitions of all INTERVAL relational operators of the form:

[x,x].qop.[y,y].

The first column contains the value of the prefix, and the first row contains the value of the operator suffix. If the tabled condition holds, the result is true.

TABLE 2-10   Operational Definitions of Interval Order Relations

LT. LE. EQ. GE. GT. NE.

.S
x < y and x < y x y and x y x = y and x = y x y and x y x > y and x > y x y or x y

.C

x < y

x y
y x and x y
x y

x > y
x > y or y > x

.P

x < y

x y
x y and y x
x y

x > y
y > x or x > y


CODE EXAMPLE 2-7   Relational Operators

math% cat ce2-7.f95
INTERVAL :: X = [1.0, 3.0], Y = [2.0, 4.0], Z 
INTEGER  :: V = 4, W = 5
LOGICAL  :: L1, L2, L3, L4
REAL :: R
 
L1 = (X == X) .AND. (Y .SEQ. Y)
L2 = X .SLT. Y
 
! Widest-need code
Z  = W
L3 = W .CEQ. Z
L4 = X-Y .PLT. V-W
IF( L1 .AND. L2 .AND. L3 .AND. L4) PRINT *, 'Check1'
 
! Equivalent (for the assignment to L3 and L4) strict code
L3 = INTERVAL(W, KIND=8) .CEQ. Z
L4 = X-Y  .PLT. INTERVAL(V, KIND=8)-INTERVAL(W, KIND=8)
IF(L3 .AND. L4) PRINT *, 'Check2'
END
math% f95 -xia ce2-7.f95
math% a.out
 Check1
 Check2

CODE EXAMPLE 2-7 notes:

2.7.8.1 Set Relational Operators

For an affirmative order relation with

op {LT, LE, EQ, GE, GT} and
,

between two points , the mathematical definition of the corresponding set-relation, .Sop., between two non-empty intervals is:

For the relation between two points , the corresponding set relation, .SNE., between two non-empty intervals X and Y is:

Empty intervals are explicitly considered in each of the following relations. In each case:

Arguments: X and Y must be intervals with the same KTPV.

Result type: default logical scalar.

2.7.8.2 Certainly Relational Operators

The certainly relational operators are true if the underlying relation is true for every element of the operand intervals. For example, [a,b] .CLT. [c,d] is true if x < y for all and . This is equivalent to b < c.

For an affirmative order relation with

op {LT, LE, EQ, GE, GT} and
,

between two points x and y, the corresponding certainly-true relation .Cop. between two intervals, X and Y, is

.

With the exception of the anti-affirmative certainly-not-equal relation, if either operand of a certainly relation is empty, the result is false. The one exception is the certainly-not-equal relation, .CNE., which is true in this case.

For each of the certainly relational operators:

Arguments: X and Y must be intervals with the same KTPV.

Result type: default logical scalar.

2.7.8.3 Possibly Relational Operators

The possibly relational operators are true if any element of the operand intervals satisfy the underlying relation. For example, [a,b] .PLT. [c,d] is true if there exists an and a such that x < y. This is equivalent to a < d.

For an affirmative order relation with

op {LT, LE, EQ, GE, GT} and
,

between two points x and y, the corresponding possibly-true relation .Pop. between two intervals X and Y is defined as follows:

.

If the empty interval is an operand of a possibly relation then the result is false. The one exception is the anti-affirmative possibly-not-equal relation, .PNE., which is true in this case.

For each of the possibly relational operators:

Arguments: X and Y must be INTERVALS with the same KTPV.

Result type: default logical scalar.

2.8 Extending Intrinsic INTERVAL Operators

If the operator specified in the INTERFACE statement of a user provided operator interface block is an intrinsic INTERVAL operator (for example .IH.), an extension to the intrinsic INTERVAL operator is created.

A user-provided operator function that extends an intrinsic INTERVAL operator may not extend the operator for those data types of its operands for which this operator is predefined.

For the combinations of arguments listed below, intrinsic interval operators +, -, *, /, .IH., .IX., and ** are predefined and cannot be extended by users.

(any INTERVAL type, any INTERVAL type)
(any INTERVAL type, any REAL or INTEGER type)
(any REAL or INTEGER type, any INTERVAL type)

The interval operator ** with the integer exponent is predefined and cannot be extended by users for the following combination of arguments:

(any INTERVAL type, any INTEGER type)

Except for the operator .IN. interval relational operators are predefined for the combinations of arguments listed below and cannot be extended by users.

(any INTERVAL type, any INTERVAL type)
(any INTERVAL type, any REAL or INTEGER type)
(any REAL or INTEGER type, any INTERVAL type)

The interval relational operator .IN. is predefined and cannot be extended by users for the following combination of arguments:

(any REAL or INTEGER type, any INTERVAL type)

In CODE EXAMPLE 2-8, both S1 and S2 interfaces are correct, because .IH. is not predefined for (LOGICAL, INTERVAL(16)) operands.

CODE EXAMPLE 2-8   Interval .IH. Operator Extension  
math% cat ce2-8.f95
MODULE M
INTERFACE OPERATOR (.IH.)
    MODULE PROCEDURE S1
    MODULE PROCEDURE S2
END INTERFACE
CONTAINS
REAL FUNCTION S1(L, Y)
LOGICAL, INTENT(IN)      ::  L 
INTERVAL(16), INTENT(IN) ::  Y
    S1 = 1.0
END FUNCTION S1
INTERVAL FUNCTION S2(R1, R2)
REAL, INTENT(IN) ::  R1 
REAL, INTENT(IN) ::  R2
    S2 = [2.0]
END FUNCTION S2
END MODULE M
PROGRAM TEST
USE M
INTERVAL(16) :: X = [1, 2]
LOGICAL      :: L = .TRUE.
REAL         :: R = 0.1
PRINT *, 'L  .IH. X  = ', L  .IH. X
PRINT *, 'R1 .IH. R2 =', R1 .IH. R2
END PROGRAM TEST
 
math% f95 -xia ce2-8.f95
math% a.out
 L  .IH. X  =  1.0
 R1 .IH. R2 = [2.0,2.0]

The extension of the + operator in CODE EXAMPLE 2-9 is incorrect because the attempt is made to change the definition of the intrinsic INTERVAL (+) operator, which is predefined for (INTERVAL, INTERVAL) type operands.

CODE EXAMPLE 2-9   User-defined interface that conflicts with the use of the intrinsic INTERVAL (+) operator.  
math% cat ce2-9.f95
MODULE M1
INTERFACE OPERATOR (+)
    MODULE PROCEDURE S4
END INTERFACE
CONTAINS
REAL FUNCTION S4(X, Y)
INTERVAL, INTENT(IN) ::  X
INTERVAL, INTENT(IN) ::  Y  
    S4 = 4.0
END FUNCTION S4
END MODULE M1
PROGRAM TEST
USE M1
INTERVAL :: X = [1.0], Y = [2.0]
PRINT *, 'X + Y = ', X + Y
END PROGRAM TEST
 
math% f95 -xia ce2-9.f95
MODULE M1
       ^  
"ce2-9.f95", Line = 1, Column = 8: ERROR: The compiler has detected 
errors in module "M1".  No module information file will be created 
for this module.
    MODULE PROCEDURE S4
                     ^  
"ce2-9.f95", Line = 3, Column = 22: ERROR: This specific interface 
"S4" conflicts with the intrinsic use of "+".
USE M1
    ^  
"ce2-9.f95", Line = 14, Column = 5: ERROR: Module "M1" has compile 
errors, therefore declarations obtained from the module via the 
USE statement may be incomplete.
f90: COMPILE TIME 0.820000 SECONDS
f90: MAXIMUM FIELD LENGTH 5518744 DECIMAL WORDS
f90: 17 SOURCE LINES

In CODE EXAMPLE 2-10, the following S1 interface is incorrect, because .IH. is predefined for (INTERVAL(4), INTERVAL(8)) operands.

CODE EXAMPLE 2-10   User-defined interface conflicts with the intrinsic use of .IH..

math% cat ce2-10.f95
MODULE M
INTERFACE OPERATOR (.IH.)
    MODULE PROCEDURE S1
END INTERFACE
CONTAINS
INTERVAL FUNCTION S1(X, Y)
INTERVAL(4), INTENT(IN) ::  X
INTERVAL(8), INTENT(IN) ::  Y 
    S1 = [1.0]
END FUNCTION S1
END MODULE M
 
PROGRAM TEST
USE M
INTERVAL(4) :: X = [1.0]
INTERVAL(8) :: Y = [2.0]
PRINT *, 'X .IH. Y = ', X .IH. Y
END PROGRAM TEST
math% f95 -xia ce2-10.f95
 
MODULE M
       ^ 
"ce2-10.f95", Line = 1, Column = 8: ERROR: The compiler has 
detected errors in module "M".  No module information file will be 
created for this module.
 
    MODULE PROCEDURE S1
                     ^  
"ce2-10.f95", Line = 3, Column = 22: ERROR: This specific interface 
"S1" conflicts with the intrinsic use of "ih".
 
USE M
    ^ 
"ce2-10.f95", Line = 14, Column = 5: ERROR: Module "M" has compile 
errors, therefore declarations obtained from the module via the 
USE statement may be incomplete.
 
f90: COMPILE TIME 0.190000 SECONDS
f90: MAXIMUM FIELD LENGTH 4135778 DECIMAL WORDS
f90: 18 SOURCE LINES
f90: 3 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI

The number of arguments of an operator function that extends an intrinsic INTERVAL operator must agree with the number of operands needed for the intrinsic operator, as shown in CODE EXAMPLE 2-11.

CODE EXAMPLE 2-11   Incorrect change in the number of arguments in a predefined INTERVAL operator.  
math% cat ce2-11.f95
MODULE M
INTERFACE OPERATOR (.IH.)
    MODULE PROCEDURE S1
END INTERFACE
CONTAINS
REAL FUNCTION S1(R)
REAL, INTENT(IN) :: R 
    S1 = 1.0
END FUNCTION S1
END MODULE M
PROGRAM TEST
USE M
REAL :: R = 0.1
PRINT *, ' .IH. R = ', .IH. R
END PROGRAM TEST
math% f95 -xia ce2-11.f95
MODULE M
       ^ 
"ce2-11.f95", Line = 1, Column = 8: ERROR: The compiler has 
detected errors in module "M".  No module information file will be 
created for this module.
    MODULE PROCEDURE S1
                     ^  
"ce2-11.f95", Line = 3, Column = 22: ERROR: The specific interface 
"S1" must have exactly two dummy arguments when inside a defined 
binary operator interface block.
USE M
    ^ 
"ce2-11.f95", Line = 13, Column = 5: ERROR: Module "M" has compile 
errors, therefore declarations obtained from the module via the 
USE statement may be incomplete.
PRINT *, ' .IH. R = ', .IH. R
                       ^      
"ce2-11.f95", Line = 15, Column = 24: ERROR: Unexpected syntax: 
"operand" was expected but found ".".
f90: COMPILE TIME 0.200000 SECONDS
f90: MAXIMUM FIELD LENGTH 4135778 DECIMAL WORDS
f90: 16 SOURCE LINES
f90: 4 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI

A binary intrinsic INTERVAL operator cannot be extended with unary operator function having an INTERVAL argument.

In CODE EXAMPLE 2-12, the S1 interface is incorrect, because "+" is predefined for the INTERVAL operand.

CODE EXAMPLE 2-12   User-defined interface that conflicts with the intrinsic use of unary "+".  
math% cat ce2-12.f95
MODULE M
INTERFACE OPERATOR (+)
    MODULE PROCEDURE S1
END INTERFACE
CONTAINS
REAL FUNCTION S1(X)
    INTERVAL, INTENT(IN) :: X 
    S1 = 1.0
END FUNCTION S1
END MODULE M
PROGRAM TEST
USE M
INTERVAL :: X = 0.1
PRINT *, ' + X = ', + X
END PROGRAM TEST
math% f95 -xia ce2-12.f95
MODULE M
       ^ 
"ce2-12.f95", Line = 1, Column = 8: ERROR: The compiler has 
detected errors in module "M".  No module information file will be 
created for this module.
    MODULE PROCEDURE S1
                     ^  
"ce2-12.f95", Line = 3, Column = 22: ERROR: This specific interface 
"S1" conflicts with the intrinsic use of "+".
USE M
    ^ 
"ce2-12.f95", Line = 13, Column = 5: ERROR: Module "M" has compile 
errors, therefore declarations obtained from the module via the 
USE statement may be incomplete.
f90: COMPILE TIME 0.290000 SECONDS
f90: MAXIMUM FIELD LENGTH 4146432 DECIMAL WORDS
f90: 16 SOURCE LINES
f90: 3 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI

In a generic interface block, if the generic name specified in the INTERFACE statement is the name of an intrinsic INTERVAL subprogram, the specific user-defined subprograms extend the predefined meaning of the intrinsic subprogram.

All references to subprograms having the same generic name must be unambiguous.

The intrinsic subprogram is treated as a collection of specific intrinsic subprograms, the interface definitions of which are also specified in the generic interface block.

CODE EXAMPLE 2-13   Correct extension of intrinsic INTERVAL function WID
math% cat ce2-13.f95
MODULE M
INTERFACE WID
    MODULE PROCEDURE S1
    MODULE PROCEDURE S2
END INTERFACE
CONTAINS
REAL FUNCTION S1(X)
REAL, INTENT(IN) :: X 
    S1 = 1.0
END FUNCTION S1
INTERVAL FUNCTION S2(X, Y)
INTERVAL, INTENT(IN) :: X 
INTERVAL, INTENT(IN) :: Y 
    S2 = [2.0]
END FUNCTION S2
END MODULE M
PROGRAM TEST
USE M
INTERVAL :: X = [1, 2], Y = [3, 4]
REAL     :: R = 0.1
PRINT *, WID(R)
PRINT *, WID(X, Y)
  
END PROGRAM TEST
math% f95 -xia ce2-13.f95
math% a.out
 1.0
 [2.0,2.0]

CODE EXAMPLE 2-14 is correct.

CODE EXAMPLE 2-14   Correct extension of the intrinsic INTERVAL function ABS.

math% cat ce2-14.f95
MODULE M
INTERFACE ABS
    MODULE PROCEDURE S1
END INTERFACE
CONTAINS
INTERVAL FUNCTION S1(X)
INTERVAL, INTENT(IN) :: X 
    S1 = [-1.0]
END FUNCTION S1
END MODULE M
PROGRAM TEST
USE M
INTERVAL :: X = [1, 2]
PRINT *, ABS(X)
  
END PROGRAM TEST
math% f95 -xia ce2-14.f95
math% a.out
 [-1.0,-1.0]

CODE EXAMPLE 2-15 is correct.

CODE EXAMPLE 2-15   

math% cat ce2-15.f95
MODULE M
INTERFACE MIN
    MODULE PROCEDURE S1
END INTERFACE
CONTAINS
INTERVAL FUNCTION S1(X, Y)
    INTERVAL(4), INTENT(IN) :: X
    INTERVAL(8), INTENT(IN) :: Y 
    S1 = [-1.0]
END FUNCTION S1
END MODULE M
 
PROGRAM TEST
USE M
INTERVAL(4) :: X = [1, 2]
INTERVAL(8) :: Y = [3, 4]
REAL        :: R = 0.1
PRINT *, MIN(X, Y)
END PROGRAM TEST
math% f95 -xia ce2-15.f95
math% a.out
 [-1.0,-1.0]

Correct extension of the intrinsic INTERVAL function MIN.

2.8.1 Extended Operators with Widest-Need Evaluation

CODE EXAMPLE 2-16 illustrates how widest-need expression processing occurs when calling predefined versus extended versions of an intrinsic INTERVAL operator.

CODE EXAMPLE 2-16   Widest-need expression processing when calling a predefined version of an intrinsic INTERVAL operator.

math% cat ce2-16.f95
MODULE M
INTERFACE OPERATOR (.IH.)
    MODULE PROCEDURE S4 
END INTERFACE
CONTAINS 
INTERVAL FUNCTION S4(X, Y) 
    COMPLEX, INTENT(IN) :: X 
    COMPLEX, INTENT(IN) :: Y
    S4 = [0]
END FUNCTION S4
END MODULE M
USE M
INTERVAL :: X = [1.0]
REAL     :: R = 1.0
COMPLEX  :: C = (1.0, 0.0)
X = (R-0.1).IH.(R-0.2)   ! intrinsic interval .IH. is invoked, 
                         ! widest-need on both arguments
                         
X = X .IH. (R+R)         ! intrinsic interval .IH. is invoked, 
                         ! widest-need on both arguments
                         
X = X .IH. (R+R+X)       ! intrinsic interval .IH. is invoked, 
                         ! widest-need on the second argument 
                         
X = (R+R) .IH. (R+R+X)    ! intrinsic interval .IH. is invoked, 
                         ! widest-need on both arguments
                         
X = C .IH. (C+R)         ! s4 is invoked, no widest-need
END
 
math% f95 -xia ce2-16.f95
math% a.out

CODE EXAMPLE 2-17 illustrates how widest-need expression processing occurs when calling a user-defined operator.

CODE EXAMPLE 2-17   Widest-need expression processing when invoking a user-defined operator. 
math% cat ce2-17.f95
MODULE M
INTERFACE OPERATOR (.AA.)
    MODULE PROCEDURE S1
    MODULE PROCEDURE S2
END INTERFACE
CONTAINS 
INTERVAL FUNCTION S1(X, Y)
INTERVAL, INTENT(IN) :: X 
REAL, INTENT(IN)     :: Y
    PRINT *, 'S1 is invoked.'
    S1 = [1.0]
END FUNCTION S1
INTERVAL FUNCTION S2(X, Y)
INTERVAL, INTENT(IN) :: X 
INTERVAL, INTENT(IN) :: Y
    PRINT *, 'S2 is invoked.'
    S2 = [2.0]
END FUNCTION S2
END MODULE M
USE M
INTERVAL :: X = [1.0]
REAL     :: R = 1.0
X = X .AA. R+R     ! S1 is invoked 
X = X .AA. X       ! S2 is invoked 
END
 
math% f95 -xia ce2-17.f95
    MODULE PROCEDURE S1
                     ^  
"ce2-17.f95", Line = 3, Column = 22: WARNING: Widest-need 
evaluation does not apply to arguments of user-defined operation.
USE M
    ^ 
"ce2-17.f95", Line = 20, Column = 5: WARNING: Widest-need 
evaluation does not apply to arguments of user-defined operation.
f90: COMPILE TIME 0.700000 SECONDS
f90: MAXIMUM FIELD LENGTH 5605590 DECIMAL WORDS
f90: 26 SOURCE LINES
f90: 0 ERRORS, 2 WARNINGS, 0 OTHER MESSAGES, 0 ANSI
math% a.out
 S1 is invoked.
 S2 is invoked.

2.8.2 INTERVAL (X [,Y, KIND])

Description: Convert to INTERVAL type.

Class: Elemental function.

Arguments:

X is of type INTEGER, REAL, or INTERVAL.

Y (optional) is of type INTEGER or REAL. If X is of type INTERVAL, Y must not be present.

KIND (optional) is a scalar INTEGER initialization expression.

Result characteristics: INTERVAL

If KIND is present, its value is used to determine the result's KTPV; otherwise, the result's KTPV is the same as a default interval.

Containment:

Containment is guaranteed if X is an interval. For example, given

INTERVAL(16):: X,

the result of INTERVAL(X, KIND=4) contains the INTERVAL X.

However, given REAL(8) X, Y, the result of INTERVAL(X,Y,KIND=4) does not necessarily contain the internal interval X .IH. Y. The reason is that X and Y can be REAL expressions, the values of which cannot be guaranteed.

The INTERVAL constructor does not necessarily contain the value of a literal INTERVAL constant with the same endpoints. For example, INTERVAL(1.1,1.3) does not necessarily contain the external value ev([1.11.3]) = [1.1, 1.3]. The reason is that the internal values of REAL constants are approximations with unknown accuracy.

To construct an interval that always contains two REAL values, use the interval hull operator .IH., as shown in CODE EXAMPLE 2-18.

Result value: The interval result value is a valid interval.

If Y is absent and X is an interval, then INTERVAL(X [,KIND]) is an interval containing X and INTERVAL(X [,KIND]) is an interval with left and right endpoints [XL,XU], where

XL = REAL(INF(X) [,KIND]) rounded down, so that XL .LE. INF(X)

and

XU = REAL(SUP(X)[,KIND]) rounded up, so that XU.GE.SUP(X).

If both X and Y are present (and are therefore not intervals), then INTERVAL(X,Y [,KIND]) is an interval with left and right endpoints equal to REAL(X [,KIND]) and REAL(Y [,KIND]) respectively.


Note – In this case, rounding direction is not specified. Therefore, containment is not provided.

[-inf,inf] is returned in two cases:

2.8.2.1 Limiting the Scope of Widest-Need

The intrinsic INTERVAL constructor function can be used in two ways:

Given the non-INTERVAL (REAL or INTEGER) expression, EXP, the code

INTERVAL Y
REAL R
R =
EXP
Y = R

is the same as

INTERVAL Y
Y = INTERVAL(
EXP)

This is not the same as

INTERVAL Y
Y =
EXP

The later will evaluate EXP as an interval expression. In the first two code fragments, the expression EXP is evaluated as a non-INTERVAL expression, and the result is used to construct a degenerate interval.

With two arguments, EXP1 and EXP2, INTERVAL(EXP1, EXP2) insulates both expressions from widest-need expression processing and constructs an interval with endpoints equal to the result of the non-INTERVAL evaluation of the expressions.

Including the KIND parameter makes it possible to control the KTPV of the result. This is most often needed under -strict expression processing where explicit KTPV conversions are necessary.

The intrinsic INTERVAL function with non-INTERVAL arguments should be used with care. Whenever interval containment is desired, use the interval hull operator .IH., as shown in CODE EXAMPLE 2-18.

The INTERVAL constructor acts as a boundary between INTERVAL and REAL or INTEGER expressions. On the non-INTERVAL side of this boundary, accuracy (and therefore containment) guarantees cannot be enforced.

CODE EXAMPLE 2-18   Containment Using the .IH. Operator 
math% cat ce2-18.f95
REAL(16) :: A, B
INTERVAL :: X1, X2
PRINT *, "Press Control/D to terminate!"
WRITE(*, 1, ADVANCE='NO')
READ(*, *, IOSTAT=IOS) A, B
DO WHILE (IOS >= 0)
    PRINT *, " FOR A =", A, ", AND B =", B
    
    ! Widest need code
     X1 = A .IH. B                                    
    
    ! Equivalent strict code          
    X2 = INTERVAL(INTERVAL(A, KIND=16) .IH. INTERVAL(B, KIND=16))
    IF (X1 .SEQ. X2)  PRINT *, 'Check.'
    PRINT *, 'X1 = ', X1
    WRITE(*, 1, ADVANCE='NO')
    READ(*, *, IOSTAT=IOS)  A, B
END DO
1  FORMAT(" A, B = ")
END
math% f95 -xia ce2-18.f95
math% a.out
 Press Control/D to terminate!
 A, B = 1.3 1.7
 FOR A = 1.3 , AND B = 1.7
 X1 =  [1.2999999999999998,1.7000000000000002]
 A, B = 0.0  0.2
 FOR A = 0.0E+0 , AND B = 0.2
 X1 =  [0.0E+0,0.20000000000000002]
 A, B = <Control-D>

See Section 2.8.2 INTERVAL (X [,Y, KIND]) for details on the use of the intrinsic INTERVAL constructor function.

2.8.2.2 KTPV-Specific Names of Intrinsic INTERVAL Constructor Functions

As shown in TABLE 2-11, the intrinsic INTERVAL constructor function can be called using a KTPV-specific form that does not use the optional KIND parameter.

TABLE 2-11   KTPV Specific Forms of the Intrinsic INTERVAL Constructor Function
KTPV -Specific Name Result
DINTERVAL(X[,Y])
INTERVAL(X[,Y], KIND = 8) or INTERVAL(X[,Y])
SINTERVAL(X[,Y])
INTERVAL(X[,Y], KIND = 4)
QINTERVAL(X[,Y])
INTERVAL(X[,Y], KIND = 16)


2.8.2.3 Intrinsic INTERVAL Constructor Function Conversion Examples

The three examples in this section illustrate how to use the intrinsic INTERVAL constructor to perform conversions from REAL to INTERVAL type data items. CODE EXAMPLE 2-19 shows that REAL expression arguments of the INTERVAL constructor are evaluated using REAL arithmetic and are, therefore, insulated from widest-need expression evaluations.

CODE EXAMPLE 2-19   INTERVAL Conversion  
math% cat ce2-19.f95
REAL        :: R = 0.1, S = 0.2, T = 0.3
REAL(8)     :: R8 = 0.1D0, T1, T2
INTERVAL(4) :: X, Y
INTERVAL(8) :: DX, DY
R = 0.1
Y  = INTERVAL(R, R, KIND=4)
X  = INTERVAL(0.1, KIND=4) 	 ! Line 7 
IF ( X == Y ) PRINT *, 'Check1'
X  = INTERVAL(0.1, 0.1, KIND=4) 	 ! Line 10
IF ( X == Y ) PRINT *, 'Check2'
T1 = R+S
T2 = T+R8
DY = INTERVAL(T1, T2)         
DX = INTERVAL(R+S, T+R8) 	 ! Line 15
IF ( DX == DY ) PRINT *, 'Check3'
DX = INTERVAL(Y, KIND=8) 	 ! Line 17
IF (Y .CEQ. INTERVAL(0.1, 0.1, KIND=8)) PRINT *, 'Check4'
END
 
math% f95 -xia ce2-19.f95
math% a.out
 Check1
 Check2
 Check3
 Check4

CODE EXAMPLE 2-19 notes:

CODE EXAMPLE 2-20 shows how the INTERVAL constructor can be used to construct the smallest possible interval, Y, such that the endpoints of Y are not elements of a given interval, X.

CODE EXAMPLE 2-20   Create a narrow interval containing a given real number.

math% cat ce2-20.f95
INTERVAL :: X = [10.E-10,11.E+10]
INTERVAL :: Y
Y = INTERVAL(-TINY(INF(X)), TINY(INF(X))) + X
PRINT *, X .INT. Y
END
math% f95 -xia ce2-20
math% a.out
  T

Given an interval X, a sharp interval Y satisfying the condition X .INT. Y is constructed. For information on the interior set relation, Section 2.7.3 Interior: (X .INT. Y).

CODE EXAMPLE 2-21 illustrates when the INTERVAL constructor returns the interval [-INF, INF] and [MAX_FLOAT, INF].

CODE EXAMPLE 2-21   INTERVAL(NaN)

math% cat ce2-21.f95
REAL :: R = 0., S = 0.
T = R/S                        ! Line 2  
PRINT *, T
PRINT *, INTERVAL(T, S)        ! Line 4 
PRINT *, INTERVAL(T, T)        ! Line 5 
PRINT *, INTERVAL(2., 1.)      ! Line 6 
PRINT *, INTERVAL(1./R)        ! Line 7 
END
 
math% f95 -xia ce2-21.f95
math% a.out
 NaN
 [-Inf,Inf]
 [-Inf,Inf]
 [-Inf,Inf]
 [1.7976931348623157E+308,Inf]

CODE EXAMPLE 2-21 notes:

2.8.3 Specific Names for Intrinsic Generic INTERVAL Functions

The f95 specific names for intrinsic generic INTERVAL functions end with the generic name of the intrinsic and start with V, followed by S, D, or Q for arguments of type INTERVAL(4), INTERVAL(8), and INTERVAL(16), respectively.

In f95, only the following specific intrinsic functions are supported for the INTERVAL(16) data type: VQABS, VQAINT, VQANINT, VQINF, VQSUP, VQMID, VQMAG, VQMIG, and VQISEMPTY.

To avoid name space clashes in non-interval programs, the specific names are made available only by the command line options:

See Section 2.3.3 Interval Command-Line Options for more information.

All the supported intrinsic functions have specific names. For example, TABLE 2-12 lists the names for the INTERVAL version of the ABS intrinsic.

TABLE 2-12   Specific Names for the Intrinsic INTERVAL ABS Function
Specific Name Argument Result
VSABS INTERVAL(4) INTERVAL(4)
VDABS INTERVAL(8) INTERVAL(8)
VQABS INTERVAL(16) INTERVAL(16)


The remaining specific intrinsic functions are listed in Section 2.9.4.4 Intrinsic Functions.

2.9 INTERVAL Statements

This section describes the INTERVAL statements recognized by f95. The syntax and description of each statement is given, along with possible restrictions and examples.

2.9.1 Type Declaration

An INTERVAL statement is used to declare INTERVAL named constants, variables, and function results. INTERVAL is an intrinsic numeric type declaration statement with the same syntax and semantics as standard numeric type declaration statements. The same specifications are available for use with the INTERVAL statement as exist for use in other numeric type declarations.

Description: The declaration can be INTERVAL, INTERVAL(4), INTERVAL(8), or INTERVAL(16).

2.9.1.1 INTERVAL

For a declaration such as

INTERVAL :: W

the variable, W, has the default INTERVAL KTPV of 8 and occupies 16 bytes of contiguous memory. In Sun WorkShop 6 Fortran 95, the default INTERVAL KTPV is not altered by the command-line options -xtypemap or -r8const.

INTERVAL cannot be used as a derived type name. For example the code in CODE EXAMPLE 2-22 is illegal.

CODE EXAMPLE 2-22   Illegal Derived Type: INTERVAL

TYPE INTERVAL
	 REAL :: INF, SUP
END TYPE INTERVAL

2.9.1.2 INTERVAL(n), for n {4, 8, 16}

For a declaration such as

INTERVAL(n) :: W

the variable, W, has KTPV = n and occupies 2n bytes of contiguous memory.

CODE EXAMPLE 2-23 contains INTERVAL variable declarations with different KTPVs. Widest-need and strict value alignment is also shown.

CODE EXAMPLE 2-23   Declaring Intervals with Different KTPVs

math% cat ce2-23.f95
INTERVAL(4)  :: X1, X2 
INTERVAL(8)  :: Y1, Y2 
INTERVAL(16) :: Z1, Z2
REAL(8)      :: D = 1.2345 
 
! Widest-need code
 X1 = D
 Y1 = D
 Z1 = D
 
 
! Equivalent strict code
X2 = INTERVAL(INTERVAL(D, KIND=8), KIND=4) 
Y2 = INTERVAL(D, KIND=8)
Z2 = INTERVAL(D, KIND=16)
 
IF (X1 == X2) PRINT *, 'Check1'
IF (Y1 == Y2) PRINT *, 'Check2'
IF (Z1 == Z2) PRINT *, 'Check3'
END 
 
math% f95 -xia ce2-23.f95
math% a.out
 Check1
 Check2
 Check3

CODE EXAMPLE 2-24 illustrates how to declare and initialize INTERVAL variables. See Section 2.1.2 INTERVAL Constants regarding the different ways to represent INTERVAL constants.

CODE EXAMPLE 2-24   Declaring and Initializing INTERVAL Variables

math% cat ce2-24.f95
INTERVAL :: U = [1, 9.1_8], V = [4.1]
 
! Widest-need code
INTERVAL :: W1 = 0.1_16
 
! Equivalent strict code
INTERVAL :: W2 = [0.1_16]
 
PRINT *, U, V
IF (W1 .SEQ. W2) PRINT *, 'Check'
END 
 
math% f95 -xia ce2-24.f95
math% a.out
 [1.0,9.1000000000000015] [4.0999999999999996,4.1000000000000006]
 Check

In any initializing declaration statement, if the type of the data expression does not match the type of the symbolic name, type conversion is performed.

CODE EXAMPLE 2-25   Declaring INTERVAL Arrays

INTERVAL(4) :: R(5), S(5) 
INTERVAL :: U(5), V(5) 
INTERVAL(16) :: X(5), Y(5) 

2.9.1.3 DATA Statements

Syntax

The syntax for DATA statements containing INTERVAL variables is the same as for other numeric data types except that INTERVAL variables are initialized using INTERVAL constants.

CODE EXAMPLE 2-26   DATA Statement Containing INTERVAL Variables

INTERVAL X
DATA X/[1,2]/

2.9.1.4 EQUIVALENCE Statements

Any INTERVAL variables or arrays may appear in an EQUIVALENCE statement with the following restriction: If an equivalence set contains an INTERVAL variable or array, all of the objects in the equivalence set must have the same type, as shown in CODE EXAMPLE 1-18. This is a standard, not interval-specific, Fortran restriction.

2.9.1.5 FORMAT Statements

Syntax

The repeatable edit descriptors for intervals are:

Fw.d, VFw.d, Dw.d, VDw.d, Dw.dEe, VDw.dEe, Yw.d, and Yw.dEe

where

D {E, EN, ES, G}
w and e are nonzero, unsigned integer constants
d is an unsigned integer constant.

See Section 2.9.2 Input and Output for the specifications of how edit descriptors process INTERVAL data. For the behavior of standard edit descriptors with non-INTERVAL data, see the Fortran Reference Manual.

All standard Fortran edit descriptors accept intervals. The prefix V can be added to the standard E, F, and G edit descriptors for interval-only versions.

As shown in CODE EXAMPLE 2-27, no modifications to nonrepeatable edit descriptors are required when reading or writing INTERVAL data.

CODE EXAMPLE 2-27   Nonrepeatable Edit Descriptor Example

math% cat ce2-27.f95
INTERVAL :: X = [-1.3, 1.3]
WRITE(*, '(SP, VF20.5)') X
WRITE(*, '(SS, VF20.5)') X
END
math% f95 -xia ce2-27.f95
math% a.out
 [-1.30001,+1.30001]
 [-1.30001, 1.30001]

Description

Repeatable Edit Descriptors

The repeatable edit descriptors E, F, EN, ES, G, VE, VEN, VES, VF, VG, and Y specify how INTERVAL data are edited.

CODE EXAMPLE 2-28 contains examples of INTERVAL-specific edit descriptors.

CODE EXAMPLE 2-28   Format Statements with INTERVAL-specific Edit Descriptors

FORMAT(VE22.4E4) 
FORMAT(VEN22.4) 
FORMAT(VES25.5) 
FORMAT(VF25.5) 
FORMAT(VG25.5) 
FORMAT(VG22.4E4) 
FORMAT(Y25.5) 

See Section 2.9.2 Input and Output for additional examples.

2.9.1.6 FUNCTION (External)

As shown in CODE EXAMPLE 2-29, there is no difference between an interval and a non-interval external function, except for the use of INTERVAL types (INTERVAL, INTERVAL(4), INTERVAL(8), or INTERVAL(16)) in the function's and argument's definitions.

CODE EXAMPLE 2-29   Default Interval Function

INTERVAL FUNCTION SQR (A)                    ! Line 1
INTERVAL :: A 
SQR = A**2 
RETURN 
END 

The default INTERVAL in line 1 can be made explicit, as shown in CODE EXAMPLE 2-30.

CODE EXAMPLE 2-30   Explicit INTERVAL(16) Function Declaration

INTERVAL(16) FUNCTION SQR (A)                ! Line 1

2.9.1.7 IMPLICIT Attribute

Use the IMPLICIT attribute to specify the default type of interval names.

IMPLICIT INTERVAL (8) (V)

2.9.1.8 INTRINSIC Statement

Use the INTRINSIC statement to declare intrinsic functions, so they can be passed as actual arguments.

CODE EXAMPLE 2-31   Intrinsic Function Declaration

INTRINSIC VDSIN, VDCOS, VQSIN
X = CALC(VDSIN, VDCOS, VQSIN) 


Note – Specific names of generic functions must be used in the INTRINSIC statement and passed as actual arguments. See Section 2.8.3 Specific Names for Intrinsic Generic INTERVAL Functions and Section 2.9.4.4 Intrinsic Functions.

Because they are generic, the following intrinsic INTERVAL functions cannot be passed as actual arguments:

NDIGITS, INTERVAL

2.9.1.9 NAMELIST Statement

The NAMELIST statement supports intervals.

CODE EXAMPLE 2-32   INTERVALS in a NAMELIST

CHARACTER(8) :: NAME 
CHARACTER(4) :: COLOR 
INTEGER      :: AGE 
INTERVAL(4)  :: HEIGHT 
INTERVAL(4)  :: WEIGHT 
NAMELIST /DOG/ NAME, COLOR, AGE, WEIGHT, HEIGHT 

2.9.1.10 PARAMETER Attribute

The PARAMETER attribute is used to assign the result of an INTERVAL initialization to a named constant (PARAMETER).

Syntax

PARAMETER (p = e [, p = expr]...)

p INTERVAL symbolic name
expr INTERVAL constant expression
= assigns the value of e to the symbolic name, p
Description

Both the symbolic name, p, and the constant expression, expr, must have INTERVAL types.

Exponentiation to an integer power is allowed in constant expressions.

Mixed-mode INTERVAL expression evaluation is supported in the definition of interval named constants under widest-need expression processing. If the constant expression's type does not match the named constant's type, type conversion of the constant expression is performed under widest-need expression processing.


Caution – In f95, non-INTERVAL constant expressions are evaluated at compile time without regard to their possible subsequent use in mixed-mode INTERVAL expressions. They are outside the scope of widest-need expression processing. Therefore, no requirement exists to contain the value of the point expression used to set the value of non-INTERVAL named constants. To remind users whenever a non-INTERVAL named constant appears in a mixed-mode INTERVAL expression, a compile-time warning message is issued. Named constants, as defined by the Fortran standard, are more properly called read-only variables. There is no external value associated with a read-only variable.

In standard Fortran 95, named constants cannot be used to represent the infimum and supremum of an INTERVAL constant. This is a known error that this constraint is not enforced in this release.

CODE EXAMPLE 2-33   Constant Expression in Non-INTERVAL PARAMETER Attribute

math% cat ce2-33.f95
REAL(4), PARAMETER      :: R   = 0.1
INTERVAL(4), PARAMETER  :: I4  = 0.1
INTERVAL(16), PARAMETER :: I16 = 0.1
INTERVAL                :: XR, XI
XR = R4
XI = I4
IF ((.NOT.(XR.SP.I16)).AND. (XI.SP.I16)) PRINT *, 'Check.'
END
math% f95 -xia ce2-33.f95
math% a.out
 Check.


Note – XR does not contain 1/10, whereas XI does.

2.9.1.11 Fortran 95-Style POINTER

Intervals can be associated with pointers.

CODE EXAMPLE 2-34   INTERVAL Pointers

INTERVAL, POINTER :: PX
INTERVAL :: X
X => P

2.9.1.12 Statement Function

A statement function can be used to declare and evaluate parameterized INTERVAL expressions. Non-INTERVAL statement function restrictions apply.

CODE EXAMPLE 2-35   INTERVAL Statement Function

math% cat ce2-35.f95
INTERVAL :: X, F
F(X) = SIN(X)**2 + COS(X)**2
IF(1 .IN. F([0.5])) PRINT *, 'Check'
END 
math% f95 -xia ce2-35.f95
math% a.out
 Check

2.9.1.13 Type Statement

The type statement specifies the data type of variables in a variable list. Optionally the type statement specifies array dimensions, and initializes variables with values.

Syntax

The syntax is the same as for non-INTERVAL numeric data types, except that type can be one of the following INTERVAL type specifiers: INTERVAL, INTERVAL(4), INTERVAL(8), or INTERVAL(16).

Description

Properties of the type statement are the same for INTERVAL types as for other numeric data types.

Restrictions

Same as for non-INTERVAL numeric types.

CODE EXAMPLE 2-36   INTERVAL Type Statement

INTERVAL     :: I, J = [0.0] 
INTERVAL(16) :: K = [0.1, 0.2_16] 
INTERVAL(16) :: L = [0.1] 

CODE EXAMPLE 2-36 notes:

2.9.1.14 WRITE Statement

The WRITE statement accepts INTERVAL variables and processes an input/output list in the same way that non-INTERVAL type variables are processed. Formatted writing of INTERVAL data is performed using the defined INTERVAL edit descriptors. NAMELIST-directed WRITE statements support intervals.

2.9.1.15 READ Statement

The READ statement accepts INTERVAL variables and processes an input/output list in the same way that non-INTERVAL type variables are processed.

2.9.2 Input and Output

The process of performing INTERVAL input/output is the same as for other non-INTERVAL data types.

2.9.2.1 External Representations

Let x be an external (decimal) number that can be read or written using either list-directed or formatted input/output. See the subsections in Section 2.1 "Fortran Extensions" regarding the regarding the distinction between internal approximations and external values. Such a number can be used to represent either an external interval, or an endpoint. There are three displayable forms of an external interval:

A positive or negative infinite interval endpoint is input/output as a case-insensitive string INF or INFINITY prefixed with a minus or an optional plus sign.

The empty interval is input/output as the case-insensitive string EMPTY enclosed in square brackets, "[...]". The string, EMPTY, may be preceded or followed by blanks.

CODE EXAMPLE 1-6 can be used to experiment with extended intervals.

See Section 2.4.1 Arithmetic Operators +, -, *, /, for more details.

2.9.2.2 Input

On input, any external interval, X, or its components, X_inf and X_sup, can be formatted in any way that is accepted by the Dw.d edit descriptor. Therefore, let input-field, input-field1, and input-field2 be valid input fields for the Dw'.d, Dw1.d, and Dw2.d edit descriptors, respectively.

Let w be the width of an interval input field. On input, w must be greater than zero. All INTERVAL edit descriptors accept input INTERVAL data in each of the following three forms:

The first form (two numbers enclosed in brackets and separated by a comma) is the familiar [inf, sup] representation.

The second form (a single number enclosed in brackets) denotes a point or degenerate interval.

The third form (without brackets) is the single-number form of an interval in which the last displayed digit is used to determine the interval's width. See Section 2.9.2.7 Single-Number Editing with the Y Edit Descriptor. For more detailed information, see M. Schulte, V. Zelov, G.W. Walster, D. Chiriaev, "Single-Number Interval I/O," Developments in Reliable Computing, T. Csendes (ed.), (Kluwer 1999).

If an infimum is not internally representable, it is rounded down to an internal approximation known to be less than the exact value. If a supremum is not internally representable, it is rounded up to an internal approximations known to be greater than the exact input value. If the degenerate interval is not internally representable, it is rounded down and rounded up to form an internal INTERVAL approximation known to contain the exact input value.

2.9.2.3 List-Directed Input

If an input list item is an INTERVAL, the corresponding element in the input record must be an external interval or a null value.

An external interval value may have the same form as an INTERVAL, REAL, or INTEGER literal constant. If an interval value has the form of a REAL or INTEGER literal constant with no enclosing square brackets, "["... "]", the external interval is interpreted using the single-number interval representation: [x] + [-1,1]uld (unit in the last digit).

When using the [inf, sup] input style, an end of record may occur between the infimum and the comma or between the comma and the supremum.

A null value, specified by two consecutive commas, means that the corresponding INTERVAL list item is unchanged.


Note – Do not use a null value for the infimum or supremum of an interval.

CODE EXAMPLE 2-37   List Directed Input/Output Code

math% cat ce2-37.f95
INTERVAL, DIMENSION(6) :: X
INTEGER I
DO I = LBOUND(X, 1), UBOUND(X, 1)
    READ(*, *) X(I) 
    WRITE(*, *) X(I) 
END DO
END 
math% f95 -xia ce2-37.f95
math% a.out
1.234500
 [1.2344989999999997,1.2345010000000001]
[1.2345]
 [1.2344999999999999,1.2345000000000002]
[-inf,2]
 [-Inf,2.0]
[-inf]
 [-Inf,-1.7976931348623157E+308]
[EMPTY]
 [EMPTY]
[1.2345,1.23456]
 [1.2344999999999999,1.2345600000000002]

2.9.2.4 Formatted Input/Output

The INTERVAL edit descriptors are:

In the INTERVAL edit descriptors:

The parameters w and d must be used. Ee is optional

The w and d specifiers must be present and are subject to the following constraints:

Input Actions

Input actions for formatted interval input are the same as for other numeric data types, except that in all cases, the stored internal approximation contains the external value represented by the input character string. Containment can require outward rounding of interval endpoints. Given any input interval characters, input_string, the corresponding external value, ev(input_string), and the resulting internal approximation after input conversion, X, are related:

ev(input_string) X.

During input, all interval edit descriptors have the same semantics. The value of parameter w, is the field width containing the external interval. The value of e is ignored.

Output Actions

Output actions for formatted interval output are the same as for other data types, except that in all cases, the mathematical value of the output character string must contain the mathematical value of the internal data item in the output list. Containment can require outward rounding of interval endpoints. Given any internal interval, X, the corresponding output characters, output_string, and the external value, ev(output_string), are related:

X ev(output_string).

During output, edit descriptors cause the internal value of interval output list items to be displayed using different formats. However, the containment constraint requires that

ev(input_string) X ev(output_string)

2.9.2.5 Formatted Input

The behavior of formatted input is identical for all INTERVAL edit descriptors listed in Section 2.9.2.4 Formatted Input/Output. All inputs described in Section 2.9.2.2 Input are accepted.

If the input field contains a decimal point, the value of d is ignored. If a decimal point is omitted from the input field, d determines the position of the decimal point in the input value; that is, the input value is read as an integer and multiplied by 10(-d).

CODE EXAMPLE 2-38   The decimal point in an input value dominates format specifiers.

math% cat ce2-38.f95
INTERVAL :: X, Y
READ(*, '(F10.4)') X
READ(*, '(F10.4)') Y
WRITE(*, *)'1234567890123456789012345678901234567890-position'
WRITE(*, '(1X, E19.6)') X
WRITE(*, '(1X, E19.6)') Y
END
math% f95 -xia ce2-38.f95
math% a.out
[.1234]
[1234]
 1234567890123456789012345678901234567890-position
      0.123400E+000 
      0.123400E+000 

CODE EXAMPLE 2-39   All the INTERVAL edit descriptors accept single-number input

math% cat ce2-39.f95
INTERVAL, DIMENSION(9) :: X
INTEGER                :: I
READ(*, '(Y25.3)')   X(1)
READ(*, '(E25.3)')   X(2)
READ(*, '(F25.3)')   X(3) 
READ(*, '(G25.3) ')  X(4) 
READ(*, '(VE25.3)')  X(5) 
READ(*, '(VEN25.3)') X(6) 
READ(*, '(VES25.3)') X(7) 
READ(*, '(VF25.3)')  X(8) 
READ(*, '(VG25.3)')  X(9)
DO I = LBOUND(X, 1), UBOUND(X, 1) 
    PRINT *, X(I)
END DO
END 
math% f95 -xia ce2-39.f95
math% a.out
1.23    
1.23
1.23
1.23
1.23
1.23
1.23
1.23
1.23
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]
 [1.2199999999999999,1.2400000000000003]

.
Blank Editing (BZ)

Because trailing zeros are significant in single-number INTERVAL input, the BZ control edit descriptor is ignored when processing leading and trailing blanks for input to INTERVAL list items.

CODE EXAMPLE 2-40   BZ Descriptor

math% cat ce2-40.f95
INTERVAL :: X
REAL(4)  :: R
READ(*, '(BZ, F40.6 )') X
READ(*, '(BZ, F40.6 )') R
WRITE(*, '(VF40.3)')    X
WRITE(*, '(F40.3)')     R
END
math% f95 -xia ce2-40.f95
math% a.out
[.9998   ]
    .9998
 [             0.999,             1.000]
                                   1.000

Scale Factor (P)

The P edit descriptor changes the scale factor for Y, VE, VEN, VES, VF, and VG descriptors and for F, E, EN, ES, and G edit descriptors when applied to intervals. The P edit descriptor scales interval endpoints the same way it scales REAL values.

2.9.2.6 Formatted Output

The F, E, and G edit descriptors applied to intervals have the same meaning as the Y edit descriptor except that if the F or G edit descriptor is used, the output field may be formatted using the F edit descriptor. If the E edit descriptor is used, the output field always has the form prescribed by the E edit descriptor.

Formatted INTERVAL output has the following properties:

On output, the default values for the exponent field, e, are shown in TABLE 2-13.

TABLE 2-13   Default Values for Exponent Field in Output Edit Descriptors
Edit Descriptor INTERVAL(4) INTERVAL(8) INTERVAL(16)
Y, E, EN, ES, G 
3 3 3
VE, VEN, VES, VG 
2 2 3


2.9.2.7 Single-Number Editing with the Y Edit Descriptor

The Y edit descriptor formats extended interval values in the single-number form.

If the external INTERVAL value is not degenerate, the output format is the same as for a REAL or INTEGER literal constant (X without square brackets, "["..."]"). The external value is interpreted as a non-degenerate mathematical interval [x] + [-1,1]uld. The general form of the Y edit descriptor is:

Yw.dEe

The d specifier sets the number of places allocated for displaying significant digits. However, the actual number of displayed digits may be more or less than d, depending on the value of w and the width of the external interval.

The e specifier (if present) defines the number of places in the output subfield reserved for the exponent.

The presence of the e specifier forces the output field to have the form prescribed by the E (as opposed to F) edit descriptor.

The single-number interval representation is often less precise than the [inf, sup] representation. This is particularly true when an interval or its single-number representation contains zero or infinity.

For example, the external value of the single-number representation for [-15, +75] is ev([0E2]) = [-100, +100]. The external value of the single-number representation for [1, ] is ev([0E+inf]) =  .

In these cases, to produce a narrower external representation of the internal approximation, the VGw.d'Ee edit descriptor is used, with d' 1 to display the maximum possible number of significant digits within the w-character input field.

CODE EXAMPLE 2-41   Y [inf, sup]-style Output

math% cat ce2-41.f95
INTERVAL :: X = [-1, 10]
INTERVAL :: Y = [1, 6]
WRITE(*, '(Y20.5)') X 
WRITE(*, '(Y20.5)') Y 
END
math% f95 -xia ce2-41.f95
math% a.out
 [-1.     ,0.1E+002]
 [1.0     ,6.0     ]

If it is possible to represent a degenerate interval within the w-character output field, the output string for a single number is enclosed in obligatory square brackets, "[", ... "]" to signify that the result is a point.

If there is sufficient field width, the E or F edit descriptor is used, depending on which can display the greater number of significant digits. If the number of displayed digits using the E and F edit descriptor is the same, the F edit descriptor is used.

CODE EXAMPLE 2-42   Yw.d Output

cat math% cat ce2-42.f95
WRITE(*, *) '1234567890123456789012345678901234567890-position'   
WRITE(*, '(1x, F20.6)') [1.2345678, 1.23456789]
WRITE(*, '(1x, F20.6)') [1.234567, 1.2345678]
WRITE(*, '(1x, F20.6)') [1.23456, 1.234567]
WRITE(*, '(1x, F20.6)') [1.2345, 1.23456]
WRITE(*, '(1x, F20.6)') [1.5111, 1.5112]
WRITE(*, '(1x, F20.6)') [1.511, 1.512]
WRITE(*, '(1x, F20.6)') [1.51, 1.52]
WRITE(*, '(1x, F20.6)') [1.5, 1.5]
END
math% f95 -xia ce2-42.f95
math% a.out
 1234567890123456789012345678901234567890-position
       1.2345679     
       1.234567      
       1.23456       
       1.2345        
       1.511         
       1.51          
       1.5           
 [     1.50000000000]

Increasing interval width decreases the number of digits displayed in the single-number representation. When the interval is degenerate all remaining positions are filled with zeros and brackets are added if the degenerate interval value is represented exactly.

The intrinsic function NDIGITS (see TABLE 2-21) returns the maximum number of significant digits necessary to write an INTERVAL variable or array using the single-number display format.

CODE EXAMPLE 2-43   Yw.d Output Using the NDIGITS Intrinsic
math% cat ce2-43.f95
INTEGER :: I, ND, T, D, DIM
PARAMETER(D=5)      ! Some default number of digits
PARAMETER(DIM=8)
INTERVAL, DIMENSION(DIM) :: X
CHARACTER(20) :: FMT
X = (/ [1.2345678, 1.23456789], &
  [1.234567, 1.2345678], &
  [1.23456, 1.234567], &
  [1.2345, 1.23456], &
  [1.5111, 1.5112], &
  [1.511, 1.512], &
  [1.51, 1.52], &
  [1.5]/)
ND=0
DO I=1, DIM
    T = NDIGITS(X(I))
    IF(T == EPHUGE(T)) THEN ! The interval is degenerate
        ND = MAX(ND, D)
    ELSE   
        ND = MAX( ND, T )
    ENDIF   
END DO
 
WRITE(FMT, '(A2, I2, A1, I1, A1)') '(E', 10+ND, '.', ND, ')'
DO I=1, DIM
    WRITE(*, FMT) X(I) 
END DO
END
math% f95 -xia ce2-43.f95
math% a.out
  0.12345679E+001 
  0.1234567 E+001 
  0.123456  E+001 
  0.12345   E+001 
  0.1511    E+001 
  0.151     E+001 
  0.15      E+001 
[ 0.15000000E+001]

For readability, the decimal point is always located in position p = e + d + 4, counting from the right of the output field.

CODE EXAMPLE 2-44   {Y, F, E, G}w.d output, where d sets the minimum number of significant digits to be displayed.

math% cat ce2-44.f95
INTERVAL :: X = [1.2345678, 1.23456789] 
INTERVAL :: Y = [1.5] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'   
WRITE(*, '(1X, F20.5)') X  
WRITE(*, '(1X, F20.5)') Y 
WRITE(*, '(1X, 1E20.5)') X 
WRITE(*, '(1X, 1E20.5)') Y 
WRITE(*, '(1X, G20.5)') X 
WRITE(*, '(1X, G20.5)') Y 
WRITE(*, '(1X, Y20.5)') X 
WRITE(*, '(1X, Y20.5)') Y 
END 
math% f95 -xia ce2-44.f95
math% a.out
 1234567890123456789012345678901234567890-position
        1.2345679    
 [      1.5000000000]
        0.12345E+001 
 [      0.15000E+001]
        1.2345679    
 [      1.5000000000]
        1.2345679    
 [      1.5000000000]

The optional e specifier specifies the number of exponent digits. If the number of exponent digits is specified, w must be at least d + e + 7.

CODE EXAMPLE 2-45   Yw.dEe output (the usage of e specifier)

math% cat ce2-45.f95
INTERVAL :: X = [1.2345, 1.2346] 
INTERVAL :: Y = [3.4567, 3.4568] 
INTERVAL :: Z = [1.5] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'   
WRITE(*, '(1X, Y19.5E4)') X 
WRITE(*, '(1X, Y19.5E4)') Y 
WRITE(*, '(1X, Y19.5E4)') Z 
WRITE(*, '(1X, Y19.5E3)') X 
WRITE(*, '(1X, Y19.5E3)') Y 
WRITE(*, '(1X, Y19.5E3)') Z 
END 
math% f95 -xia ce2-45.f95
math% a.out
 1234567890123456789012345678901234567890-position
      0.1234 E+0001 
      0.3456 E+0001 
 [    0.15000E+0001]
       0.1234 E+001 
       0.3456 E+001 
 [     0.15000E+001]

.

2.9.2.8 E Edit Descriptor

The E edit descriptor formats INTERVAL data items using the single-number E form of the Y edit descriptor.

The general form is:

Ew.dEe

CODE EXAMPLE 2-46   Ew.dEe Edit Descriptor  
math% cat ce2-46.f95
INTERVAL :: X = [1.2345678, 1.23456789] 
INTERVAL :: Y = [1.5]
WRITE(*, *) '1234567890123456789012345678901234567890-position'   
WRITE(*, '(1X, E20.5)')   X 
WRITE(*, '(1X, E20.5E3)') X 
WRITE(*, '(1X, E20.5E3)') Y 
WRITE(*, '(1X, E20.5E4)') X 
WRITE(*, '(1X, E20.5E2)') X 
END 
math% f95 -xia ce2-46.f95
math% a.out
 1234567890123456789012345678901234567890-position
        0.12345E+001 
        0.12345E+001 
 [      0.15000E+001]
       0.12345E+0001 
         0.12345E+01 

2.9.2.9 F Edit Descriptor

The F edit descriptor formats INTERVAL data items using only the F form of the INTERVAL Y edit descriptor. The general form is:

Fw.d

Using the F descriptor, it is possible to display more significant digits than specified by d. Positions corresponding to the digits that are not displayed are filled with blanks.

CODE EXAMPLE 2-47   Fw.d Edit Descriptor

math% cat ce2-47.f95
INTERVAL :: X = [1.2345678, 1.23456789] 
INTERVAL :: Y = [2.0] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'   
WRITE(*, '(1X, F20.4)') X 
WRITE(*, '(1X, E20.4)') X 
WRITE(*, '(1X, F20.4)') Y 
WRITE(*, '(1X, E20.4)') Y 
END
math% f95 -xia ce2-47.f95
math% a.out
 1234567890123456789012345678901234567890-position
         1.2345679   
         0.1234E+001 
 [       2.000000000]
 [       0.2000E+001]

2.9.2.10 G Edit Descriptor

The G edit descriptor formats INTERVAL data items using the single-number E or F form of the Y edit descriptor. The general form is:

Gw.dEe
CODE EXAMPLE 2-48   Gw.dEe Edit Descriptor

math% cat ce2-48.f95
INTERVAL :: X = [1.2345678, 1.23456789] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'   
WRITE(*, '(1X, G20.4)')   X 
WRITE(*, '(1X, G20.4E3)') X 
END 
math% f95 -xia ce2-48.f95
math% a.out
 1234567890123456789012345678901234567890-position
         1.2345679   
         0.1234E+001


Note – If it is impossible to output interval endpoints according to the F descriptor, G edit descriptor uses the E descriptor

2.9.2.11 VE Edit Descriptor

The general form of the VE edit descriptor is:

VEw.dEe

Let Xd be a valid external value using the Ew'.d edit descriptor. The VE edit descriptor outputs INTERVAL data items in the following form:

[X_inf,X_sup], where w' = (w-3)/2 .

The external values, X_inf and X_sup, are lower and upper bounds, respectively, on the infimum and supremum of the INTERVAL output list item.

CODE EXAMPLE 2-49   VE Output

math% cat ce2-49.f95
INTERVAL :: X = [1.2345Q45, 1.2346Q45] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'
WRITE(*, '(1X, VE25.3)')   X
WRITE(*, '(1X, VE33.4E4)') X
END
math% f95 -xia ce2-49.f95
math% a.out
 1234567890123456789012345678901234567890-position
 [ 0.123E+046, 0.124E+046]
 [   0.1234E+0046,   0.1235E+0046]

2.9.2.12 VEN Edit Descriptor

The general form of the VEN edit descriptor is:

VENw.dEe

Let X_inf and X_sup be valid external values displayed using the ENw'.d edit descriptor. The VEN edit descriptor outputs an INTERVAL data item in the following form:

[X_inf,X_sup], where w' = (w-3)/2 .

The external values, X_inf and X_sup, are lower and upper bounds, respectively, on the infimum and supremum of the INTERVAL output list item.

CODE EXAMPLE 2-50   VEN Output

math% cat ce2-50.f95
INTERVAL :: X = [1024.82] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'
WRITE(*, '(1X, VEN25.3)') X
WRITE(*, '(1X, VEN33.4E4)') X
END
math% f95 -xia ce2-50.f95
math% a.out
 1234567890123456789012345678901234567890-position
 [ 1.024E+003, 1.025E+003]
 [   1.0248E+0003,   1.0249E+0003]

2.9.2.13 VES Edit Descriptor

The general form of the VES edit descriptor is:

VESw.dEe

Let X_inf and X_sup be a valid external values using the ESw'.d edit descriptor. The VES edit descriptor outputs an INTERVAL data item in the following form:

[X_inf,X_sup], where w' = (w-3)/2 .

The external values, X_inf and X_sup, are lower and upper bounds, respectively, on the infimum and supremum of the INTERVAL output list item.

CODE EXAMPLE 2-51   VES Output

math% cat ce2-51.f95
INTERVAL :: X = [21.234] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'
WRITE(*, '(1X, VES25.3)')   X
WRITE(*, '(1X, VES33.4E4)') X
END
math% f95 -xia ce2-51.f95
math% a.out
 1234567890123456789012345678901234567890-position
 [ 2.123E+001, 2.124E+001]
 [   2.1233E+0001,   2.1235E+0001]

2.9.2.14 VF Edit Descriptor

Let X_inf and X_sup be valid external values displayed using the Fw'.d edit descriptor. The VF edit descriptor outputs INTERVAL data items in the following form:

[X_inf,X_sup], where w' = (w-3)/2 .

The external values, X_inf and X_sup, are lower and upper bounds, respectively, on the infimum and supremum of the INTERVAL output list item.

CODE EXAMPLE 2-52   VF Output Editing

math% cat ce2-52.f95
INTERVAL :: X = [1.2345, 1.2346], Y = [1.2345E11, 1.2346E11] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'
WRITE(*, '(1X, VF25.3)') X
WRITE(*, '(1X, VF25.3)') Y
END
math% f95 -xia ce2-52.f95
math% a.out
 1234567890123456789012345678901234567890-position
 [      1.234,      1.235]
 [***********,***********]


Note – If it is impossible to output an interval according to the specified format statement, asterisks are printed.

2.9.2.15 VG Edit Descriptor

For INTERVAL output, VG editing is the same as VE or VF editing, except that the G edit descriptor is used to format the displayed interval endpoints.

CODE EXAMPLE 2-53   VG Output

math% cat ce2-53.f95
INTERVAL :: X = [1.2345, 1.2346], Y = [1.2345E11, 1.2346E11] 
WRITE(*, *) '1234567890123456789012345678901234567890-position'
WRITE(*, '(1X, VG25.3)') X
WRITE(*, '(1X, VG25.3)') Y
END 
math% f95 -xia ce2-53.f95
math% a.out
 1234567890123456789012345678901234567890-position
 [  1.23     ,  1.24     ]
 [ 0.123E+012, 0.124E+012]


Note – If it is impossible to output interval endpoints according to the F descriptor, the VG edit descriptor uses the E descriptor.

2.9.2.16 Unformatted Input/Output

Unformatted input/output is used to transfer data to and from memory locations without changing its internal representation. With intervals, unformatted input/output is particularly important, because outward rounding on input and output is avoided.


Note – Use only unformatted INTERVAL input and output to read and write unformatted INTERVAL data. Binary file compatibility with future releases is not guaranteed. Unformatted input/output relies on the fact that INTERVAL data items are opaque.

2.9.2.17 List-Directed Output

REAL constants for left and right endpoints are produced using either an F or an E edit descriptor. Let |x| be the absolute value of an output interval endpoint. Then if

,

the endpoint is produced using the 0PFw.d edit descriptor. Otherwise, the 1PEw.dEe descriptor is used. In f95, d1 = -2 and d2 = +8.

For the output of INTERVAL data items in f95, the values for d and e are the same as for the REAL types with the same KTPV. The value of w reflects the need to conveniently accommodate two REAL values and three additional characters for square brackets, "[", "]", and the comma, as shown in CODE EXAMPLE 2-37.

2.9.2.18 Single-Number Input/Output and Base Conversions

Single-number INTERVAL input, immediately followed by output, can appear to suggest that a decimal digit of accuracy has been lost, when in fact radix conversion has caused a 1 or 2 ulp increase in the width of the stored input interval. For example, an input of 1.37 followed by an immediate print will result in 1.3 being output. See Section 2.9.2.4 Formatted Input/Output.

As shown in CODE EXAMPLE 1-6, programs must use character input and output to exactly echo input values and internal reads to convert input character strings into valid internal approximations.

2.9.3 Intrinsic INTERVAL Functions

This section contains the defining properties of the f95 intrinsic INTERVAL functions.

Generic intrinsic INTERVAL functions that accept arguments with more than one KTPV have both generic and KTPV-specific names. When an intrinsic function is invoked using its KTPV-specific name, arguments must have the matching KTPV.


Note – In f95, some KTPV-16 specific intrinsic functions are not provided. This is an outstanding quality of implementation opportunity.

With functions that accept more than one INTERVAL data item (for example, SIGN(A,B)), all arguments must have the same KTPV. Under widest-need expression processing, compliance with this restriction is automatic. With strict expression processing, developers are responsible for enforcing type and KTPV restrictions on intrinsic function arguments. Compile-time errors result when different KTPVs are encountered.

2.9.4 Mathematical Functions

This section lists the type-conversion, trigonometric, and other functions that accept INTERVAL arguments. The symbols and in the interval are used to denote its ordered elements, the infimum, or lower bound and supremum, or upper bound, respectively. In point (non-interval) function definitions, lowercase letters x and y are used to denote REAL or INTEGER values.

When evaluating a function, f, of an interval argument, X, the interval result, f(X), must be an enclosure of its containment set, cset(f, {x}), where:

A similar result holds for functions of n-variables. Determining the containment set of values that must be included when the interval contains values outside the domain of f is discussed in the supplementary paper [1] cited in Section 2.10 References. The results therein are needed to determine the set of values that a function can produce when evaluated on the boundary of, or outside its domain of definition. This set of values, called the containment set is the key to defining interval systems that return valid results, no matter what the value of a function's arguments or an operator's operands. As a consequence, there are no argument restrictions on any intrinsic INTERVAL functions in f95.

2.9.4.1 Inverse Tangent Function ATAN2(Y,X)

This sections provides additional information about the inverse tangent function. For further details, see the supplementary paper [9] cited in Section 2.10 References.

Description: Interval enclosure of the inverse tangent function over a pair of intervals.

Mathematical definition:

Class: Elemental function.

Special values: TABLE 2-14 and CODE EXAMPLE 2-54 display the ATAN2 indeterminate forms.

TABLE 2-14   ATAN2 Indeterminate Forms
y0 x0 cset(sin, {y0, x0}) cset(cos, {y0, x0}) cset(, {y0, x0})
0 0 [-1, 1] [-1, 1]
+ + [0, 1] [0, 1]
+ - [0, 1] [-1, 0]
- - [-1, 0] [-1, 0]
- + [-1, 0] [0, 1]


CODE EXAMPLE 2-54   ATAN2 Indeterminate Forms 
math% cat ce2-54.f95
   INTERVAL :: X, Y
   INTEGER  :: IOS = 0
   PRINT *, "Press Control/D to terminate!"
   WRITE(*, 1, ADVANCE='NO')
   READ(*, *, IOSTAT=IOS) Y, X
   DO WHILE (ios >= 0)
      PRINT *, "For X =", X, "For Y =", Y
      PRINT *, 'ATAN2(Y,X)= ', ATAN2(Y,X)
      WRITE(*, 1, ADVANCE='NO')
      READ(*, *, IOSTAT=IOS) Y, X
   END DO
1  FORMAT("Y, X = ?")
   END
math% f95 -xia ce2-54.f95
math% a.out
 Press Control/D to terminate!
Y, X = ? [0] [0]
For X = [0.0E+0,0.0E+0] For Y = [0.0E+0,0.0E+0]
ATAN2(Y,X)=  [-3.1415926535897936,3.1415926535897936]
 Y, X = ? inf inf
For X = [1.7976931348623157E+308,Inf] For Y = 
[1.7976931348623157E+308,Inf]
 ATAN2(Y,X)=  [0.0E+0,1.5707963267948968]
 Y, X = ?inf -inf
For X = [-Inf,-1.7976931348623157E+308] For Y =
 [1.7976931348623157E+308,Inf]
 ATAN2(Y,X)=  [1.5707963267948965,3.1415926535897936]
 Y, X = ?-inf +inf
For X = [1.7976931348623157E+308,Inf] For Y = 
[-Inf,-1.7976931348623157E+308]
 ATAN2(Y,X)=  [-1.5707963267948968,0.0E+0]
 Y, X = ?-inf -inf
For X = [-Inf,-1.7976931348623157E+308] For Y = 
[-Inf,-1.7976931348623157E+308]
 ATAN2(Y,X)=  [-3.1415926535897936,-1.5707963267948965]
 Y, X = ? <Control-D>

Arguments: Y is of type INTERVAL. X is of the same type and KIND type parameter as Y.

Result characteristics: Same as the arguments.

Result value: The interval result value is an enclosure for the specified interval. An ideal enclosure is an interval of minimum width that contains the exact mathematical interval in the description.

The result is empty if one or both arguments are empty.

In the case where x < 0 and , to get a sharp interval enclosure (denoted by ), the following convention uniquely defines the set of all possible returned interval angles:

This convention, together with

results in a unique definition of the interval angles that ATAN2(Y, X) must include.

TABLE 2-15 contains the tests and arguments of the REAL ATAN2 function that are used to compute the endpoints of in the algorithm that satisfies the constraints required to produce sharp interval angles. The first two columns define the distinguishing cases. The third column contains the range of possible values of the midpoint, m(), of the interval . The last two columns show how the endpoints of are computed using the REAL ATAN2 intrinsic function. Directed rounding must be used to guarantee containment.

TABLE 2-15   Tests and Arguments of the REAL ATAN2 Function
Y X m()
- < y x < 0 ATAN2(y, x) ATAN2( , x) + 2
- = y x < 0 ATAN2(y, x) 2 - q
< - x < 0 ATAN2(y, x) - 2 ATAN2( , x)


2.9.4.2 Maximum: MAX(X1,X2,[X3,...])

Description: Range of maximum.

The containment set for max(X1, ..., Xn) is:

.

The implementation of the MAX intrinsic must satisfy:

MAX(X1,X2,[X3, ...]) {max(X1, ..., Xn)}.

Class: Elemental function.

Arguments: The arguments are of type INTERVAL and have the same type and KIND type parameter.

Result characteristics: The result is of type INTERVAL. The kind type parameter is that of the arguments.

2.9.4.3 Minimum: MIN(X1,X2,[X3, ...])

Description: Range of minimum.

The containment set for min(X1, ..., Xn) is:

.

The implementation of the MIN intrinsic must satisfy:

MIN(X1,X2,[X3, ...]) {min(X1, ..., Xn)}.

Class: Elemental function.

Arguments: The arguments are of type INTERVAL and have the same type and KIND type parameter.

Result characteristics: The result is of type INTERVAL. The kind type parameter is that of the arguments.

2.9.4.4 Intrinsic Functions

Tables TABLE 2-17 through TABLE 2-21 list the properties of intrinsic functions that accept interval arguments. TABLE 2-16 lists the tabulated properties of intrinsic INTERVAL functions in these tables.

TABLE 2-16   Tabulated Properties of Each Intrinsic INTERVAL Function
Tabulated Property Description
Intrinsic Function what the function does
Definition mathematical definition
No. of Args. number of arguments the function accepts
Generic Name the function's generic name
Type-Specific Names the function's specific names
Argument Type data type associated with each specific name
Function Type data type returned for specific argument data type


KTPV 4, 8 and 16 versions of intrinsic INTERVAL functions are defined. The corresponding specific intrinsic names begin with VS, VD or VQ, from interVal Single, Double and Quad.

For each specific REAL intrinsic function, a corresponding intrinsic INTERVAL function exists with a VS, VD, or VQ prefix, such as VSSIN() and VDSIN().

Because indeterminate forms are possible, special values of the X**Y and ATAN2 function are contained in Section 2.5 Power Operators X**N and X**Y and Section 2.9.4.1 Inverse Tangent Function ATAN2(Y,X), respectively. The remaining intrinsic functions do not require this treatment.

TABLE 2-17   Intrinsic INTERVAL Arithmetic Functions
Intrinsic Function Point Definition No. of Args. Generic Name Specific Names Argument Type Function Type
Absolute value |a| 1 ABS VDABS VSABS VQABS INTERVAL(8) INTERVAL(4) INTERVAL(16) INTERVAL(8) INTERVAL(4) INTERVAL(16)
Truncation See Note 1 int(a) 1 AINT VDINT VSINT VQINT INTERVAL(8) INTERVAL(4) INTERVAL(16) INTERVAL(8) INTERVAL(4) INTERVAL(16)
Nearest integer int(a + .5)
if a 0
int(a - .5)
if a < 0
1 ANINT VDNINT VSNINT VQNINT INTERVAL(8) INTERVAL(4) INTERVAL(16) INTERVAL(8) INTERVAL(4) INTERVAL(16)
Remainder a-b(int(a/b)) 2 MOD VDMOD VSMOD INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Transfer of sign See Note 2 |a| sgn(b) 2 SIGN VDSIGN VSSIGN INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Choose largest value See Note 3 max(a,b,...) 2 MAX MAX INTERVAL INTERVAL
Choose smallest value See Note 3 min(a,b,...) 2 MIN MIN INTERVAL INTERVAL
(1) int(a) = floor(a) if a > 0 and ceiling(a) if a < 0

(2) The signum function sgn(a) = -1 if a < 0, +1 if a > 0 and 0 if a = 0

(3) The MIN and MAX intrinsic functions ignore empty interval arguments unless all arguments are empty, in which case, the empty interval is returned.


TABLE 2-18   Intrinsic INTERVAL Type Conversion Functions
Conversion To No. of Args. Generic Name Argument Type Function Type
INTERVAL 1, 2, or 3 INTERVAL INTERVAL
INTERVAL(4)
INTERVAL(8)
INTEGER
REAL
REAL(8)
REAL(16)
INTERVAL
INTERVAL
INTERVAL
INTERVAL
INTERVAL
INTERVAL
INTERVAL
INTERVAL(4) 1 or 2 SINTERVAL INTERVAL
INTERVAL(4)
INTERVAL(8)
INTEGER
REAL
REAL(8)
REAL(16)
INTERVAL(4)
INTERVAL(4)
INTERVAL(4)
INTERVAL(4)
INTERVAL(4)
INTERVAL(4)
INTERVAL(4)
INTERVAL(8) 1 or 2 DINTERVAL INTERVAL
INTERVAL(4)
INTERVAL(8)
INTEGER
REAL
REAL(8)
REAL(16)
INTERVAL(8)
INTERVAL(8)
INTERVAL(8)
INTERVAL(8)
INTERVAL(8)
INTERVAL(8)
INTERVAL(8)
INTERVAL(16) 1 or 2 QINTERVAL INTERVAL
INTERVAL(4)
INTERVAL(8)
INTERVAL(16)
INTEGER
REAL
REAL(8)
INTERVAL(16)
INTERVAL(16)
INTERVAL(16)
INTERVAL(16)
INTERVAL(16)
INTERVAL(16)
INTERVAL(16)


TABLE 2-19   Intrinsic INTERVAL Trigonometric Functions
Intrinsic Function Point Definition No. of Args. Generic Name Specific Names Argument Type Function Type
Sine sin(a) 1 SIN VDSIN VSSIN INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Cosine cos(a) 1 COS VDCOS VSCOS INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Tangent tan(a) 1 TAN VDTAN VSTAN INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Arcsine arcsin(a) 1 ASIN VDASIN VSASIN INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Arccosine arccos(a) 1 ACOS VDACOS VSACOS INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Arctangent arctan(a) 1 ATAN VDATAN VSATAN INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Arctangent See Note 1 arctan(a/b) 2 ATAN2 VDATAN2 VSATAN2 INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Hyperbolic Sine sinh(a) 1 SINH VDSINH VSSINH INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Hyperbolic Cosine cosh(a) 1 COSH VDCOSH VSCOSH INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Hyperbolic Tangent tanh(a) 1 TANH VDTANH VSTANH INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
(1) arctan(a/b) = , given a = h sin, b = h cos, and h2 = a2 + b2.


TABLE 2-20   Other Intrinsic INTERVAL Mathematical Functions
Intrinsic Function Point Definition No. of Args. Generic Name Specific Names Argument Type Function Type
Square Root See Note 1 exp{ln(a)/2} 1 SQRT VDSQRT VSSQRT INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Exponential exp(a) 1 EXP VDEXP VSEXP INTERVAL INTERVAL(4) INTERVAL(8) INTERVAL(4)
Natural logarithm ln(a) 1 LOG VDLOG VSLOG INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
Common logarithm log(a) 1 LOG10 VDLOG10 VSLOG10 INTERVAL(8) INTERVAL(4) INTERVAL(8) INTERVAL(4)
(1) sqrt(a) is multi-valued. A proper interval enclosure must contain both the positive and negative square roots. Defining the SQRT intrinsic to be

eliminates this difficulty.


TABLE 2-21   Intrinsic INTERVAL-Specific Functions
Intrinsic Function Definition
No. of Args. Generic Name Specific Names Argument Type Function Type
INF inf([a, b]) = a 1 INF VDINF VSINF VQINF INTERVAL(8) INTERVAL(4) INTERVAL(16) REAL(8) REAL(4) REAL(16)
SUP sup([a, b]) = b 1 SUP VDSUP VSSUP VQSUP INTERVAL(8) INTERVAL(4) INTERVAL(16) REAL(8) REAL(4) REAL(16)
Width w([a, b]) = b - a 1 WID VDWID VSWID VQWID INTERVAL(8) INTERVAL(4) INTERVAL(16) REAL(8) REAL(4) REAL(16)
Midpoint mid([a, b]) = (a + b)/2
1 MID VDMID VSMID VQMID INTERVAL(8) INTERVAL(4) INTERVAL(16) REAL(8) REAL(4) REAL(16)
Magnitude See Note 1 max(|a|) A 1 MAG VDMAG VSMAG VQMAG INTERVAL(8) INTERVAL(4) INTERVAL(16) REAL(8) REAL(4) REAL(16)
Mignitude See Note 2 min(|a|) A 1 MIG VDMIG VSMIG VQMIG INTERVAL(8) INTERVAL(4) INTERVAL(16) REAL(8) REAL(4) REAL(16)
Test for empty interval true if A is empty 1 ISEMPTY VDISEMPTY VSISEMPTY VQISEMPTY INTERVAL(8) INTERVAL(4) INTERVAL(16) LOGICAL LOGICAL LOGICAL
Floor floor(A) 1 FLOOR
INTERVAL(8) INTERVAL(4) INTERVAL(16) INTEGER INTEGER INTEGER
Ceiling ceiling(A) 1 CEILING
INTERVAL(8) INTERVAL(4) INTERVAL(16) INTEGER INTEGER INTEGER
Precision precision(A) 1 PRECISION
INTERVAL(8) INTERVAL(4) INTERVAL(16) INTEGER INTEGER INTEGER
Range range(A) 1 RANGE
INTERVAL(8) INTERVAL(4) INTERVAL(16) INTEGER INTEGER INTEGER
Number of digits See Note 3 Maximum number of digits using Y edit descriptor 1 NDIGITS
INTERVAL INTERVAL(4) INTERVAL(16) INTEGER INTEGER INTEGER
(1) mag([a, b]) = max(|a|,|b|)

(2) mig([a, b]) = min(|a|,|b|), if a > 0 or b < 0, otherwise 0

(3) Special cases: NDIGITS([-inf, +inf]) = NDIGITS([EMPTY]) = 0


2.10 References

The following technical reports are available online. See the Interval Arithmetic README for the location of these files.

  1. G.W. Walster, E.R. Hansen, and J.D. Pryce, "Extended Real Intervals and the Topological Closure of Extended Real Relations," Technical Report, Sun Microsystems. February 2000.

  2. G. William Walster, "Empty Intervals," Technical Report, Sun Microsystems. April 1998.

  3. G. William Walster, "Closed Interval Systems," Technical Report, Sun Microsystems. August 1999.

  4. G. William Walster, "Literal Interval Constants," Technical Report, Sun Microsystems. August 1999.

  5. G. William Walster, "Widest-Need Interval Expression Evaluation," Technical Report, Sun Microsystems. August 1999.

  6. G. William Walster, "Compiler Support of Interval Arithmetic With Inline Code Generation and Nonstop Exception Handling," Technical Report, Sun Microsystems. February 2000.

  7. G. William Walster, "Finding Roots on the Edge of a Function's Domain," Technical Report, Sun Microsystems. February 2000.

  8. G. William Walster, "Implementing the `Simple' Closed Interval System," Technical Report, Sun Microsystems. February 2000.

  9. G. William Walster, "Interval Angles and the Fortran ATAN2 Intrinsic Function," Technical Report, Sun Microsystems. February 2000.

  10. G. William Walster, "The `Simple' Closed Interval System," Technical Report, Sun Microsystems. February 2000.

  11. G. William Walster, Margaret S. Bierman, "Interval Arithmetic in Forte Developer Fortran," Technical Report, Sun Microsystems. March 2000.


Sun Microsystems, Inc.
Copyright information. All rights reserved.
Feedback
Library   |   Contents   |   Previous   |   Next   |   Index