C H A P T E R  2
 f95 Interval Reference

This chapter is a reference for the syntax and semantics of the intrinsic INTERVAL types implemented in Sun Studio 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 INTERVALConstants

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.

 ``` ``` ```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 ``` ```math% a.out ``` ```CHECK ``` ```  ```

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.11, References.

 ``` ``` ```math% cat ce2-2.f95 ``` ``` INTERVAL :: X ``` ``` X=[2,3] ``` ``` X=[0.1] !Case 1: Interval containing the decimal number 1/10 ``` ``` X=[2, ] !Case 2: Invalid - missing supremum ``` ``` X=[3_2,2_2] !Case 3: Invalid - infimum > supremum ``` ``` X=[2_8,3_8] ``` ``` X=[2,3_8] ``` ``` X=[0.1E0_8] ``` ``` X=[2_16,3_16] !Case 4: Invalid - KTPV 16 is not valid for type INTEGER ``` ``` X=[2,3.0_16] ``` ``` X=[0.1E0_16] ``` ``` END ``` ```math% f95 -xia ce2-2.f95 ``` ```  ``` ``` X=[2, ] !Case 2: Invalid - missing supremum ``` ``` ^ ``` ```"ce2-2.f95", Line = 4, Column = 10: ERROR: Unexpected syntax: "operand" was expected but found "]". ``` ```  ``` ``` X=[3_2,2_2] !Case 3: Invalid - infimum > supremum ``` ``` ^ ``` ```"ce2-2.f95", Line = 5, Column = 14: ERROR: The left endpoint of the interval constant must be less than or equal to the right endpoint. ``` ```  ``` ``` X=[2_16,3_16] !Case 4: Invalid - KTPV 16 is not valid for type INTEGER ``` ``` ^ ``` ```"ce2-2.f95", Line = 9, Column = 7: ERROR: The kind type parameter value 16 is not valid for type INTEGER. ``` ``` ^ ``` ```"ce2-2.f95", Line = 9, Column = 12: ERROR: The kind type parameter value 16 is not valid for type INTEGER. ``` ```  ``` ```f95comp: 12 SOURCE LINES ``` ```f95comp: 4 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI ``` ```  ```

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 Section 2.10, 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 might 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(), 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:

• Interval containment
• No type or precision conversions add width to the converted intervals

 Note - Unless there is a specific requirement to use strict expression processing, it is strongly recommended that users employ widest-need expression processing. In any expression or subexpression, explicit INTERVAL type and KTPV conversions can always be made.

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:

• Generic code that is independent of the expression processing mode (widest-need, or strict)
• Widest-need code
• Equivalent strict code

The examples are designed to communicate three messages:

• Except in special circumstances, use the widest-need expression processing.
• Whenever widest-need expression processing is enabled, but is not wanted, it can be overridden using the INTERVAL constructor to coerce type and KTPV conversions.
• With strict expression processing, INTERVAL type and precision conversions must be explicitly specified using INTERVAL constants and the INTERVAL constructor.

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, array, array section, or structure component.

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 after the expression is evaluated, the expression result is converted to a containing interval with KTPV = KIND(V) and the resulting value is assigned to V.

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

 ``` ``` ```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:

• The equivalent strict code shows the steps required to reproduce the results obtained using widest-need expression processing.
• In line 4, KIND(R)= 8, but KIND(X1) = 4. To guarantee containment and produce a sharp result, R is converted to a KTPVmax = 8 containing interval before evaluating the expression. Then the result is converted to a KTPV-4 containing interval and assigned to X1. These steps are made explicit in the equivalent strict code in line 6.
• In line 5, KIND(R) = KIND(X2) = 8. Therefore, X1 is promoted to a KTPV-8 INTERVAL before the expression is evaluated and the result assigned to X2. Line 7 shows the equivalent strict code.
• The checks in lines 8 and 9 verify that the widest-need and strict results are identical. For more detailed information on widest-need and strict expression processing, see Section 2.3, INTERVAL Arithmetic Expressions.

2.3.3 Interval Command-Line Options

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

• -xinterval=(no|widestneed|strict) is a command-line option to enable processing of intervals and to control permitted expression evaluation syntax.
• -xia=(widestneed|strict) is a macro that enables the processing of INTERVAL data types and sets a suitable floating-point environment. If -xia is not mentioned (the first default), there is no expansion.

-xia expands into the following.

-xinterval=widestneed
-ftrap=%none
-fns=no
-fsimple=0

-xia=(widestneed|strict) expands into the following.

-xinterval=(widestneed|strict)
-ftrap=%none
-fns=no
-fsimple=0

Previously set values of -ftrap, -fns, -fsimple are superseded.

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

-fsimple=0
-fns=no
-ftrap=no
-ftrap=%none

When using command-line options:

• At the end of the command-line processing, if -ansi is set and -xinterval is set to either widestneed or strict, the following warning is issued: "Interval data types are a non-standard feature".
• -fround = <r>: (Set the IEEE rounding mode in effect at startup) does not interact with -xia because INTERVAL operations and routines save and restore the rounding mode upon entry and exit.

When recognition of INTERVAL types is activated:

• INTERVAL operators and functions become intrinsic.
• The same restrictions are imposed on the extension of intrinsic INTERVAL operators and functions as are imposed on the extension of standard intrinsic operators and functions.
• Intrinsic INTERVAL-specific function names are recognized. See Section 2.2.3, INTERVAL Arrays and Section 2.10.4, Mathematical Functions.

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.

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

 ``` ``` ```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

+

X+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 under -xia=strict expression processing. This is not a problem under widest-need expression processing. Users must be responsible for preventing integer overflow under strict expression processing. See Section 1.5.1.1, Integer Overflow for more information.

Precedence of operators:

• The operator ** takes precedence over the *, /, +, -, .IH., and .IX. operators.
• The operators * and / take precedence over the +, -, .IH., and .IX. operators.
• The operators + and - take precedence over the .IH. and .IX. operators.
• The operators .IH. and .IX. take precedence over the // operator.

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.

 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 (cset) of the operation or expression that produces the result.

To include extended intervals (with infinite endpoints) and division by zero, csets can only indirectly depend on the value of arithmetic operations on real operands. For extended intervals, csets 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 function 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.11, References.

The following is an intuitive way to justify the values included in an expression's cset. Consider the function

.

The question is: What is the cset of h(x0), for x0 = 0 ? To answer this question, consider the function

.

Clearly, f(x0) = 0, for x0 = 0. But, what about

or

?

The function g(x0) is undefined for x0 = 0, because h(x0) is undefined. The cset of h(x0) for x0 = 0 is the smallest set of values for which g(x0) = f(x0). Moreover, this must be true for all composite functions of h. For example if

g'(y) = ,

then g(x) = g'(h(x)). In this case, it can be proved that the cset of h(x0) = if x0= 0, where denotes the setconsisting of the two values, and .

TABLE 2-5 through TABLE 2-8, contain the csets for the basic arithmetic operations. It is convenient to adopt the notation that an expression denoted by f(x) simply means its cset. Similarly, if

,

the containment set of f over the interval X, then hull(f(x)) is the sharp interval that contains f(X).

TABLE 2-5 Containment Set for Addition: x + y

{-}

{real: y0}

{+}

{-}

{-}

{-}

{real: x0}

{-}

{x0 + y0}

{+}

{+}

{+}

{+}

TABLE 2-6 Containment Set for Subtraction: x - y

{-}

{real: y0}

{+}

{-}

{-}

{-}

{real: x0}

{+}

{x0 - y0}

{-}

{+}

{+}

{+}

TABLE 2-7 Containment Set for Multiplication: x × y

{-}

{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: x ÷ y

{-}

{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 sets. Results are shown as sets or intervals. Customary notation, such as , , and , is used, with the understanding that csets are implied when needed. 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.11, References.

Using these results, f95 implements the "simple" 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.11, 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, Xn, which represents the cset of Xn,is 1 for all , and for all n.

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

where and exp(y(ln(x))) are their respective containment sets. The function exp(y(ln(x))) makes explicit that only values of x 0 need be considered, and is consistent with the definition of X**Ywith REALarguments 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 exp(y(ln(x))).

TABLE 2-9 exp( y (ln (x )))

x0

y0

exp(y(ln(x)))

0

y0 < 0

+

1

-

[0,+]

1

+

[0,+]

+

0

[0,+]

0

0

[0,+]

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

• Directly computing the closure of the composite expression, exp(y(ln(x))) for the values of x0 and y0 for which the expression is undefined.
• Use the containment-set evaluation theorem to bound the set of values in a containment set.

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,

exp(y(ln(x))) = exp(y0 × ln(x0)).

That is, the cset of the expression on the left is equal to the composition of csets on the right.

It is always the case that

exp(y(ln(x))) exp(y0 × ln(x0)).

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

ln(0) = -inf, ln(+inf)=+inf, exp(-inf)=0, exp(+inf)=+inf

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 x0 = 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(y(ln(x))). At this time, sufficient conditions for closure-composition equality of any expression have not been identified. Nevertheless,

• The containment-set evaluation theorem guarantees that a containment failure can never result from computing a composition of closures instead of a closure.
• An expression must be a SUE for closure-composition equality to be true.

2.6 Dependent Subtraction Operator

The dependent subtraction operator .DSUB. can be used to recover either operand of a previous interval addition.

Two interval variables are dependent when one interval variable is a result of an interval arithmetic operation applied to the other interval variable. For example, if X = A + B, then X depends on both A and B. Dependent interval subtraction produces narrower interval results when recovering A or B from X.

Dependent operations cannot be applied to interval constants because interval constants are not the result of an interval operation, and therefore, cannot be dependent. Applying dependent operations to interval constants produces a compile-time error.

The result of X.DSUB.A returns an enclosure of B given that X = A + B, as shown in TABLE 2-10.

TABLE 2-10 Results of X .DSUB. A For Different Values of X and A

A = [EMPTY]

A = Finite Interval

A = [-inf, inf]

X = [EMPTY]

[-inf, inf]

[EMPTY]

[EMPTY]

X = Finite Interval

[-inf, inf]

Finite interval[1]

[-inf, inf]

X = [-inf, inf]

[-inf, inf]

[-inf, inf]

[-inf, inf]

2.7 Set Theoretic Operators

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

2.7.1 Hull: X 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 and operational definitions:

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

Result type: Same as X.

2.7.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.8 Set Relations

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

2.8.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.8.2 Element: rY 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:

• Under widest-need expression processing, R and Y having different KTPVs has no impact on how they are evaluated. Widest-need expression processing applies to Y, but does not apply to the evaluation of R. After evaluation, KTPV promotion of Y or R is done before the inclusion test is performed.
• Under strict expression evaluation, R and Y must have the same KTPV.
• If R is NaN (Not a Number), R .IN. Y is unconditionally false.
• If Y is empty, R .IN. Y is unconditionally false.

2.8.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:

• , or in Fortran: INF(Y).IN.X

• , or in Fortran: SUP(Y).IN.X

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.8.4 Proper Subset: XY or (X.PSB.Y)

Description: Test if X is a proper subset of Y

Mathematical and operational definitions:

proper subset definition

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

Result type: Default logical scalar.

2.8.5 Proper Superset: XY or (X.PSP.Y)

Description:Seeproper subset with .

2.8.6 Subset: XY 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.8.7 Superset: XY or (X.SP.Y)

Description:See subset with .

2.8.8 Relational Operators

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

• The required period delimiters
• An operator prefix, q {C,P,S}, where C, P, and S stand for certainly, possibly, and set, respectively
• A Fortran relational operator suffix, op {LT, LE, EQ, NE, GT, GE}

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

 Note - This identity between certainly and possibly operators holds unconditionally if op {EQ, NE}, and otherwise, only if neither operand is empty. Conversely, the identity does not hold if op {LT, LE, GT, GE} and either operand is empty.

Assuming neither operand is empty, TABLE 2-11 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-11 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

 ``` ``` ```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:

• L1 is true because an interval is set-equal to itself and the default .EQ. ( or == ) operator is the same as .SEQ. .
• L2 is true because (INF(X).LT.INF(Y)).AND.(SUP(X).LT.SUP(Y)) is true.
• L3 is true because widest need promotes W to the interval [5,5] and two intervals are certainly equal if and only if all four of their endpoints are equal.
• L4 is true because evaluating the interval expressions X-Y and V-W yields the intervals [-3,1] and [-1,-1] respectively. Therefore the expression (INF(X-Y) .LT. SUP(V-W)) is true.

2.8.8.1 Set Relational Operators

For an affirmative order relation with

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

,

between two points x and y, the mathematical definition of the corresponding set-relation, .Sop., between two non-empty intervals X and Y is:

For the relation between two points x and y, 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.8.8.2 Certainly Relational Operators

Thecertainly 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< yfor 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.8.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.9 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.

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

 ``` ``` ```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. ``` ```f95comp: 17 SOURCE LINES ``` ```f95comp: 3 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI ``` ```  ```

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

 ``` ``` ```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. ``` ```  ``` ```f95comp: 18 SOURCE LINES ``` ```f95comp: 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.

 ``` ``` ```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 ".". ``` ```  ``` ```f95comp: 16 SOURCE LINES ``` ```f95comp: 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.

 ``` ``` ```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. ``` ```  ``` ```f95comp: 16 SOURCE LINES ``` ```f95comp: 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.

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

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

 ``` ``` ```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] ``` ```  ```

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

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

 ``` ``` ```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. ``` ```f95comp: 26 SOURCE LINES ``` ```f95comp: 0 ERRORS, 2 WARNINGS, 0 OTHER MESSAGES, 0 ANSI ``` ```math% a.out ``` ``` S1 is invoked. ``` ``` S2 is invoked. ``` ```  ```

2.9.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.1, 1.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:

• If both X and Y are present and Y is less than X.
• If either X or Y or both do not represent a mathematical integer or real number (for example, when one or both REAL arguments is a NaN).

2.9.2.1 Limiting the Scope of Widest-Need

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

• To perform KTPV conversions of INTERVAL variables or expressions
• To insulate a non-INTERVAL expression from mixed-mode INTERVAL expression evaluation.

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

 ```INTERVAL YREAL RR = EXPY = R ```

is the same as

 ```INTERVAL YY = INTERVAL(EXP) ```

This is not the same as

 ```INTERVAL YY = 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.

 ``` ``` ```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 ``` ```Check. ``` ```X1 = [1.2999999999999998,1.7000000000000002] ``` ```A, B = 0.0 0.2 ``` ```FOR A = 0.0E+0 , AND B = 0.2 ``` ```Check. ``` ```X1 = [0.0E+0,0.20000000000000002] ``` ```A, B = ^d ``` ```  ```

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

2.9.2.2 KTPV-Specific Names of Intrinsic INTERVAL Constructor Functions

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

TABLE 2-12 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.9.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.

 ``` ``` ```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:

• Lines 7 and 10: Interval X is assigned a degenerate interval with both endpoints equal to the internal representation of the real constant 0.1
• Line 15: Interval DX is assigned an interval with left and right endpoints equal to the result of REAL expressions R+S and T+R8 respectively
• Line 17: Interval Y is converted to a containing KTPV-8 interval.

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.

 ``` ``` ```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.8.3, Interior: (X .INT. Y).

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

 ``` ``` ```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:

• Line 2: Variable T is assigned a NaN value.
• Lines 4 and 5: One of the arguments of the INTERVAL constructor is a NaN and the result is the interval [-INF, INF].
• Line 6: The interval [-INF, INF] is constructed instead of an invalid interval [2,1].
• Line 7: The interval [MAX_FLOAT, INF] is constructed. This interval contains the interval [INF, INF]. See the supplementary paper [8] cited in Section 2.11, References, for a discussion of the chosen intervals to internally represent.

2.9.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:

• -xinterval
• -xinterval=strict or -xinterval=widestneed
• macro -xia, -xia=strict or -xia=widestneed

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

TABLE 2-13 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.10.4.5, Intrinsic Functions.

2.10 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.10.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.10.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 Studio 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.

 ``` ``` ```math% cat ce2-22.f95 ``` ```TYPE INTERVAL ``` ``` REAL :: INF, SUP ``` ```END TYPE INTERVAL ``` ```  ``` ```END ``` ```math% f95 -xia ce2-22.f95 ``` ```  ``` ```TYPE INTERVAL ``` ``` ^ ``` ```"ce2-22.f95", Line = 1, Column = 6: ERROR: A derived type type-name must not ``` ```be the same as the name of the intrinsic type INTERVAL. ``` ```  ``` ```f95comp: 5 SOURCE LINES ``` ```f95comp: 1 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI ``` ```  ```

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

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

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

 ``` ``` ```math% cat ce2-25.f95 ``` ```INTERVAL(4) :: R(5), S(5) ``` ```INTERVAL :: U(5), V(5) ``` ```INTERVAL(16) :: X(5), Y(5) ``` ```END ``` ```math% f95 -xia ce2-25.f95 ``` ```math% a.out ``` ```  ```

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

 ``` ``` ```math% cat ce2-26.f95 ``` ```INTERVAL X ``` ```DATA X/[1,2]/ ``` ```END ``` ```  ``` ```math% f95 -xia ce2-26.f95 ``` ```math% a.out ``` ```  ```

2.10.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.10.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.10.2, Input and Output for the specifications of how edit descriptors process INTERVAL data.

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.

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

 ``` ``` ```math% cat ce2-28.f95 ``` ```  ``` ``` 10 FORMAT(VE22.4E4) ``` ``` 20 FORMAT(VEN22.4) ``` ``` 30 FORMAT(VES25.5) ``` ``` 40 FORMAT(VF25.5) ``` ``` 50 FORMAT(VG25.5) ``` ``` 60 FORMAT(VG22.4E4) ``` ``` 70 FORMAT(Y25.5) ``` ```  ``` ``` END ``` ```  ``` ```math% f95 -xia ce2-28.f95 ``` ```math% a.out ``` ```  ```

See Section 2.10.2, Input and Output for additional examples.

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

 ``` ``` ```math% cat ce2-29.f95 ``` ```PROGRAM ce2_29 ``` ```INTERVAL :: X, Y ``` ```EXTERNAL SQR ``` ```INTERVAL :: SQR ``` ```  ``` ```Y = [4.0] ``` ```X = SQR(Y) ``` ```print *, "X = ", X ``` ```print *, "KIND(X) =", KIND(X) ``` ```END ``` ```  ``` ```INTERVAL FUNCTION SQR (A) !Line 1 ``` ```INTERVAL :: A ``` ```SQR = A**2 ``` ```RETURN ``` ```END ``` ```  ``` ```math% f95 -xia ce2-29.f95 ``` ```math% a.out ``` ``` X = [16.0,16.0] ``` ``` KIND(X) = 8 ``` ```  ```

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

 ``` ``` ```math% cat ce2-30.f95 ``` ```PROGRAM ce2_30 ``` ```INTERVAL(16) :: X, Y ``` ```EXTERNAL SQR ``` ```INTERVAL(16) :: SQR ``` ```  ``` ```Y = [4.0] ``` ```X = SQR(Y) ``` ```print *, "X = ", X ``` ```print *, "KIND(X) =", KIND(X) ``` ```END ``` ```  ``` ```INTERVAL(16) FUNCTION SQR (A) !Line 1 ``` ```INTERVAL(16) :: A ``` ```SQR = A**2 ``` ```RETURN ``` ```END ``` ```math% f95 -xia ce2-30.f95 ``` ```math% a.out ``` ``` X = [16.0,16.0] ``` ``` KIND(X) = 16 ``` ```  ```

2.10.1.7 IMPLICIT Attribute

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

 ```IMPLICIT INTERVAL (8) (V) ```

2.10.1.8 INTRINSIC Statement

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

 ```INTRINSIC VDSIN, VDCOS, VSSIN, VSCOS ``` ```X = CALC(VDSIN, VDCOS, VSSIN, VSCOS) ```

 Note - Specific names of generic functions must be used in the INTRINSIC statement and passed as actual arguments. See Section 2.9.3, Specific Names for Intrinsic Generic INTERVAL Functions and Section 2.10.4.5, Intrinsic Functions.

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

NDIGITS, INTERVAL

2.10.1.9 NAMELIST Statement

The NAMELIST statement supports intervals.

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

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

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

 ``` ``` ```math% cat ce2-33.f95 ``` ```REAL(4), PARAMETER :: R4 = 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.10.1.11 Fortran 95-Style POINTER

Intervals can be associated with pointers.

 ``` ``` ```math% cat ce2-34.f95 ``` ```INTERVAL, POINTER :: PX ``` ```INTERVAL, TARGET :: X ``` ```X = [0.1,0.3] ``` ```PX => X ``` ```PRINT*, X ``` ```PRINT*, PX ``` ```END ``` ```math% f95 -xia ce2-34.f95 ``` ```math% a.out ``` ``` [0.099999999999999991,0.30000000000000005] ``` ``` [0.099999999999999991,0.30000000000000005] ``` ```  ```

2.10.1.12 Statement Function

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

 ``` ``` ```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.10.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.

 ``` ``` ```math% cat ce2-36.f95 ``` ```  ``` ```INTERVAL :: I,J = [0.0] ``` ```INTERVAL(16) :: K = [0.1, 0.2_16] ``` ```INTERVAL(16) :: L = [0.1] ``` ```  ``` ```END ``` ```math% f95 -xia ce2-36.f95 ``` ```math% a.out ``` ```  ```

CODE EXAMPLE 2-36 notes:

• J is initialized to [0.0]
• K is initialized to an interval containing [0.1, 0.2]
• L is initialized to an interval containing [0.1]

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

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

2.10.2 Input and Output

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

2.10.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:

• [X_inf,X_sup]represents the mathematical interval
• [X] represents the degenerate mathematical interval [x, x], or [x]
• X represents the non-degenerate mathematical interval [x] + [-1,+1]uld (unit in the last digit). This form is the single-number representation, in which the last decimal digit is used to construct an interval (see the Y edit descriptor). In this form, trailing zeros are significant. Thus 0.10 represents interval [0.09, 0.11], 100E-1 represents interval [9.9, 10.1], and 0.10000000 represents the interval [0.099999999, 0.100000001].

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.10.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:

• [input-field1, input-field2], in which case w1 + w2 = w - 3 or w = w1 + w2 + 3
• [input-field], in which case w' = w-2 or w = w'+2
• input-field, in which case w' = w

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

 ``` ``` ```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.10.2.4 Formatted Input/Output

The INTERVAL edit descriptors are:

• Ew.dEe
• ENw.d
• ESw.d
• Fw.d
• Gw.dEe
• VEw.dEe
• VENw.dEe
• VESw.dEe
• VFw.d
• VGw.dE
• Yw.dEe

In the INTERVAL edit descriptors:

• w specifies the number of positions occupied by the field
• d specifies the number of digits to the right of the decimal point
• Ee specifies the width of exponent field

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:

• e > 0
• w 0 when using the F edit descriptor, or w > 0 when using all edit descriptors other than F.
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:

Xev(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) Xev(output_string)

2.10.2.5 Formatted Input

The behavior of formatted input is identical for all INTERVAL edit descriptors listed in Section 2.10.2.4, Formatted Input/Output. All inputs described in Section 2.10.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).

 ``` ``` ```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 ``` ```  ```

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

 ``` ``` ```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.10.2.6 Formatted Output

The F, E, EN, ES, 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 descriptors are used, the output field always has the form prescribed by the corresponding E, EN, or ES edit descriptor.

Formatted INTERVAL output has the following properties:

• A positive interval endpoint starts with an optional plus sign.
• A negative endpoint always starts with a leading minus sign.
• A zero interval endpoint never starts with a leading plus or minus.
• The VF, VE, VEN, VES, and VG edit descriptors provide [inf, sup]-style formatting of intervals.
• The Y edit descriptor produces single-number interval output.
• If an output list item matching the VF, VE, VEN, VES, or VG, or Y edit descriptor is any type other than INTERVAL, the entire output field is filled with asterisks.
• If the output field's width, w, in VF, VE, VEN, VES, VG edit descriptors is an even number, the field is filled with one leading blank character and w-1 is used for the output field's width.

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

TABLE 2-14 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

3

3

3

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

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

 ``` ``` ```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-22) returns the maximum number of significant digits necessary to write an INTERVAL variable or array using the single-number display format.

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

 ``` ``` ```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, E20.5)') X ``` ```WRITE(*, '(1X, E20.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.

 ``` ``` ```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.10.2.8 E, EN, and ES Edit Descriptors

The E, EN, and ES edit descriptors format INTERVAL data items using the single-number E, EN, and ES forms of the Y edit descriptor.

The general forms are:

• Ew.dEe
• ENw.dEe
• ESw.dEe

•  ``` ``` ```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.10.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.

 ``` ``` ```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.10.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

 ``` ``` ```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.10.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.

 ``` ``` ```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.10.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.

 ``` ``` ```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.10.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.

 ``` ``` ```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.10.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.

 ``` ``` ```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 endpoint according to the specified interval edit descriptor, asterisks are printed. For example, [0.9999, ******]

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

 ``` ``` ```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.10.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.10.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.10.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.10.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.10.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.10.4 Mathematical Functions

This section lists the type-conversion, trigonometric, and other functions that accept INTERVALarguments. 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 xand yare used to denote REALor INTEGERvalues.

When evaluating a function, f, of an interval argument, X, the interval result, f(X), must be an enclosure of its containment set, f(x). Therefore,

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 fis discussed in the supplementary paper [1] cited in Section 2.11, 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 INTERVALfunctions in f95.

2.10.4.1 Division With Intersection Function DIVIX

The function DIVIX returns the interval enclosure of the result of the interval division operation (A/B) intersected with the interval C.

In the case when A contains zero, the mathematical result of the interval division operation (A/B) is the union of two disjoint intervals. Each interval in the union can be represented in the currently implemented interval arithmetic system. The DIVIX function is a convenient way to compute one or both of these intervals.

2.10.4.2 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.11, References.

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

Mathematical definition:

Class: Elemental function.

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

TABLE 2-15 ATAN2 Indeterminate Forms

y0

x0

0

0

[-1, 1]

[-1, 1]

+

+

[0, 1]

[0, 1]

+

-

[0, 1]

[-1, 0]

-

-

[-1, 0]

[-1, 0]

-

+

[-1, 0]

[0, 1]

 ``` ``` ```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 Y =", Y, "For X =", X ``` ``` 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 Y = [0.0E+0,0.0E+0] For X = [0.0E+0,0.0E+0] ``` ``` ATAN2(Y,X) = [-3.1415926535897936,3.1415926535897936] ``` ```Y, X = ?inf inf ``` ```For Y = [1.7976931348623157E+308,Inf] For X = [1.7976931348623157E+308,Inf] ``` ``` ATAN2(Y,X) = [0.0E+0,1.5707963267948968] ``` ```Y, X = ?inf -inf ``` ```For Y = [1.7976931348623157E+308,Inf] For X = [-Inf,-1.7976931348623157E+308] ``` ``` ATAN2(Y,X) = [1.5707963267948965,3.1415926535897936] ``` ```Y, X = ?-inf +inf ``` ```For Y = [-Inf,-1.7976931348623157E+308] For X = [1.7976931348623157E+308,Inf] ``` ``` ATAN2(Y,X) = [-1.5707963267948968,0.0E+0] ``` ```Y, X = ?-inf -inf ``` ```For Y = [-Inf,-1.7976931348623157E+308] For X = ``` ```[-Inf,-1.7976931348623157E+308] ``` ``` ATAN2(Y,X) = [-3.1415926535897936,-1.5707963267948965] ``` ```Y, X = ? ^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-16 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-16 Tests and Arguments of the REAL ATAN2 Function

Y

X

m(Q)

-< y

x < 0

ATAN2(y, x)

ATAN2(, x) + 2

-= y

x < 0

ATAN2(y, x)

2 -

< -

x < 0

ATAN2(y, x) - 2

ATAN2(, x)

2.10.4.3 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.10.4.4 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.10.4.5 Intrinsic Functions

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

 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.10.4.2, Inverse Tangent Function ATAN2(Y,X), respectively. The remaining intrinsic functions do not require this treatment.

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

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

(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-20 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-21 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-22 Intrinsic INTERVAL -Specific Functions

Intrinsic
Function

Definition

No. of
Args.

Generic
Name

Specific
Names

Argument
Type

Function
Type

Infimum

inf([a, b]) = a

1

INF

VDINF

VSINF

VQINF

INTERVAL(8)

INTERVAL(4)

INTERVAL(16)

REAL(8)

REAL(4)

REAL(16)

Supremum

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

Division with intersection

3

DIVIX

VDDIVIX

VSDIVIX

VQDIVIX

INTERVAL(8)

INTERVAL(4)

INTERVAL(16)

INTERVAL(8)

INTERVAL(4)

INTERVAL(16)

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.5 Random Number Subroutine

RANDOM_NUMBER(HARVEST) returns through the interval variable HARVEST one pseudorandom interval [a, b], or an array of pseudorandom intervals from uniform distributions over the ranges 0 a 1, and a b 1.

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

1 (TableFootnote) The returned finite interval must always enclose B, given that X = A + B.