Adding Interval Support to the GNU Fortran Compiler
Michael J. Schulte, Vitaly Zelov, and Ahmet Akkas
Department of Electrical Engineering and Computer Science
Lehigh University, Bethlehem, PA 18015, USA
James Craig Burley
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111, USA
Draft revised May 30, 1998
Abstract
Compiler support for intervals as an intrinsic data type is essential for promoting wide-spread use of interval arithmetic. This document gives an overview
of modications being made to the GNU Fortran Compiler to provide support
for interval arithmetic. It also describes the design of interval runtime libraries
that will be used by the modied compiler, and discusses the methodology used
to test the compiler and runtime libraries. The modications being made to the
compiler are based on the Interval Arithmetic Specication being prepared by
Chiriaev and Walster [1]. Their specication builds upon the work of Kearfott
[2] and Priest [3] to provide a standard for supporting interval arithmetic in
Fortran.
1
Contents
1 Introduction
1.1
1.2
1.3
1.4
Interval arithmetic . . . . . . . . . . . .
Interval applications . . . . . . . . . . .
Interval software and standardization . .
Compiler support for interval arithmetic
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
3
4
5
2 The GNU Fortran Compiler
6
3 Interval Runtime Libraries
9
2.1 An overview of the GNU Fortran Compiler . . . . . . . . . . . . . . .
2.2 Modifying the GNU Fortran Compiler . . . . . . . . . . . . . . . . .
3.1 The non-I/O interval routines . . . . . . . . . . . . . . . . . . . . . .
3.2 The interval I/O routines . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Interval header les and support routines . . . . . . . . . . . . . . . .
6
8
10
14
15
4 Testing the Runtime Libraries and Compiler
17
5 Obtaining the Compiler and Runtime Libraries
18
6 Conclusions and Future Work
20
5.1 Obtaining and using the compiler . . . . . . . . . . . . . . . . . . . .
5.2 Obtaining and using the runtime libraries . . . . . . . . . . . . . . . .
2
18
20
1 Introduction
1.1 Interval arithmetic
Interval arithmetic was originally introduced in the 1960s by Raymond Moore as a
method for performing operations on intervals of real numbers [4]. With interval
arithmetic, each interval is represented by its lower and upper endpoints. More
formally, an interval [ ] is dened as
x; x
X
X
[
x; x
] f 2 j g
x
IR x
x
x
For example, the interval = [1 23 1 24] is a closed interval that includes all values
greater than or equal to 1.23 and less than or equal to 1.24.
Interval arithmetic allows computations to be performed on intervals, such that the
result of the computation provides a guaranteed enclosure for the correct mathematical result over the domain dened by the the interval operands. The basic arithmetic
operations = f+ ? g, are dened for the the intervals and as
X
;
;
:
;
:
;
X
X
Y
f j 2
x
y x
X; y
2 g
Y
unless = and 0 2 . For example, the interval addition
= [4 22 4 23] results in
=
Y
:
;
Y
Y
X
= [3 14 3 15] plus
:
;
:
:
[3 14 3 15] + [4 22 4 23] [7 36 7 38]
:
;
:
:
;
:
:
;
:
1.2 Interval applications
Although the concept of interval arithmetic is relatively straight-forward, it provides
a extremely powerful mechanism for bounding the results of oating point computations. As demonstrated in [4] and [5] interval arithmetic provides a practical method
for bounding errors in numerical computations including roundo errors, approximation errors, and errors due to inexact inputs. In addition, interval arithmetic has been
used to develop ecient algorithms for solving problems in several areas including:
Global optimization
Determining roots of functions
Solving systems of linear and nonlinear equations
Performing numerical dierentiation and integration
3
Interval arithmetic has also been successfully applied to several important applications. These include modeling control systems, detecting defects in VLSI manufacturing, performing ray intersection, estimating the performance of nancial trading
systems, locating oil and mineral deposits, estimating errors in laser systems, controlling mobile robots, and geometric modeling. These and other applications for interval
arithmetic are presented in [5], [6], [7], [8], [9], [10].
1.3 Interval software and standardization
Because of its ability to provide validated solutions, several software tools have been
developed to support interval arithmetic. These include interval arithmetic libraries,
[11], [12], [13], [14], language extensions with support for interval arithmetic [15], [16],
[17], [18] and interval application software [7], [19], [20]. Although these tools give
programmers access to interval arithmetic, they do not conform to specied standard.
As noted in [2], the lack of a specied standard for interval arithmetic has the following
disadvantages:
Resources are unnecessarily expended to redevelop tools for interval arithmetic
Diverse semantics in programming interval computations inhibit multi-person
development of application software
Interval arithmetic packages written in high-level languages, seldom take advantage of machine hardware and consequently may have poor runtime performance
Interval arithmetic packages designed on one platform may not be portable to
other platforms.
Furthermore, current interval arithmetic software packages do not always guarantee
containment. As noted in [3], several packages for interval arithmetic produce incorrect results due to mishandling arithmetic exceptions. Some of these packages
also depend on the underlying platforms built-in libraries when performing interval
functions and interval input and output. Consequently, the correctness and tightness
of the interval routines are dependent on the accuracy of the built-in libraries. This
accuracy is often dicult to determine and can vary on dierent platforms [21]. Also,
previous software packages for interval arithmetic may cause unexpected behavior.
For example, the machine oating point rounding mode is sometimes changed as a
side eect of performing an interval arithmetic operation.
To overcome these diculties a standard for interval arithmetic in Fortran was recently proposed [2]. This proposal species correct handling for an INTERVAL data
type, interval arithmetic operations, interval intrinsics, and interval I/O. In [1], this
4
specication is expanded to provide algorithms for correct nonstop handling of IEEE
754 exceptions [22] for all the interval intrinsic and operations dened in [2]. It also
includes a number of new operators and intrinsic, which are dened in [23].
1.4 Compiler support for interval arithmetic
To ease the burden of writing interval code and to help provide a standard for interval
arithmetic, the authors are modifying the GNU Fortran Compiler to support intervals
as an intrinsic data type. The new version of the GNU Fortran Compiler will provide
support for:
An intrinsic interval data type
Interval arithmetic operations
Interval set operations
Interval relationals
Interval special functions
Interval versions of mathematical functions
Interval conversion functions
Interval input and output
Interval exception handling
The interval support being added to the GNU Fortran Compiler is based on the
Interval Arithmetic Specication of Chiriaev and Walster [1]. This compiler will be
designed to provide correct results even in the presence of arithmetic exceptions. In
addition, interval runtime libraries will be developed which guarantee containment
and produce tight interval results across a variety of platforms. The GNU Fortran
Compiler with support for interval arithmetic will provide the following benets.
Programmers will be able to develop interval programs for Fortran in an ecient
manner.
Programs developed using the GNU Fortran Compiler will be portable to several
dierent platforms, which will encourage sharing of code and code reuse.
More people will be exposed to the benets of interval arithmetic, since the
interval-enhanced compiler will be publically available.
5
Runtime libraries developed for the GNU Fortran Compiler can be used by other
compilers or software packages to allow them to support interval arithmetic.
The implementation of the GNU Fortran Compiler will provide a good testing
ground for the feasibility of the Interval Arithmetic Specication.
Routines that are designed to test the runtime libraries and the compiler can
be used by others to assist them in testing interval compilers and other interval
software.
The contents of the remainder of this document is as follows: Section 2 gives an
overview of the GNU Fortran Compiler and describes changes that are being made
to its internal implementation to provide support for interval arithmetic. Section 3
describes the interval runtime libraries that are used by the GNU Fortran compiler
to support interval arithmetic. Section 4 discusses the method used for testing the
compiler and the routines in the runtime library. Section 5 explains how to obtain
and use the
the Interval-Enhanced GNU Fortran Compiler and the interval runtime libraries.
Section 6 gives our conclusions and discusses opportunities for future work.
2 The GNU Fortran Compiler
This section gives an overview of the GNU Fortran Compiler and describes changes
that are being made to it to provide support for interval arithmetic. General information about the GNU Fortran Compiler can be obtained from:
http://www.eecs.lehigh.edu/~mschulte/compiler/doc/g77_toc.html
2.1 An overview of the GNU Fortran Compiler
The GNU Fortran Compiler, also known as g77, is a publically available Fortran
compiler which is designed to run on a variety platforms. To promote software reuse,
it interfaces with other GNU compilers and tools, such as the GNU C compiler (gcc)
and the GNU debugger (gdb). Similar to other Fortran compilers, the GNU Fortran
Compiler reads a program written in Fortran and translates it to machine code. It
also has support for debugging, program linking, and error and warning diagnostics.
Command line arguments can be used to specify various options including output
control, Fortran dialect, warning messages, debugging support, optimization levels,
preprocessing, directory locations, code generation, and environment variables.
The GNU Fortran Compiler utilizes four main components:
6
A modied version of the gcc compiler
The g77 interface
The libf2c runtime libraries
The Fortran Compiler (internally named f771)
The gcc compiler is more than just a compiler for C. Based on command-line options
and the names given for les on the command line, gcc determines which actions
to perform, including preprocessing, compiling (in a variety of possible languages),
assembling, and linking. In a GNU Fortran installation, gcc recognizes Fortran source
les by names ending in .f or .F For these les, it uses the Fortran compiler, f771, to
perform compilation. More information on the gcc compiler can be obtained from:
http://www.gnu.ai.mit.edu/software/gcc/gcc.html
The g77 interface is essentially just a front-end for the gcc compiler. Because of this,
g77 can compile and link programs and source les written in other languages, such
as C and C++. Fortran programmers will normally use g77 instead of gcc, because
g77 knows how to specify the libraries needed to link with Fortran programs. Two
libraries that are automatically linked are the Fortran library, libf2c, and the math
library, lm.
The libf2c runtime library contains the machine code needed to support capabilities
of the Fortran language that are not directly provided by the machine code generated
by the g77 compilation phase. This library includes procedures needed by Fortran
programs while they are running. For example, while code generated by g77 is likely
to perform additions, subtractions, and multiplications in the compiled code, it does
not perform I/O or compute the trigonometric functions this way. Instead, statements
that perform these operations are converted by the f771 compiler into function calls in
the machine code. When run, the function calls in the machine code invoke functions
in libf2c. Consequently, libf2c must be linked with almost every useful program having
any component compiled by GNU Fortran. As mentioned above, the g77 interface
automatically takes care of all this.
The f771 compiler is a combination of two rather large pieces of code. One piece is the
so-called GNU Back End, or GBE, which knows how to generate fast code for a wide
variety of processors. The same GBE is used by the C, C++, and Fortran compiler
programs. Typically, a distribution of g77 will contain patch les for the GBE that
allow it to process Fortran code correctly and eciently. The other piece of f771 is
the majority of what is unique about GNU Fortran. This is the code that knows
how to interpret Fortran programs to determine what they are intending to do, and
7
then communicate that knowledge to the GBE for the actual compilation of those
programs. This piece is called the Fortran Front End (FFE). The FFE is responsible
for diagnosing incorrect usage of the language in the programs it processes, and is
also responsible for most of the warnings about questionable constructs. The GBE
handles producing some warnings, such as those concerning possible references to
undened variables.
2.2 Modifying the GNU Fortran Compiler
To support interval arithmetic, several modications were made to the GNU Fortran
Compiler. These modications provide support for the new interval data type, interval
constants, interval I/O and format statements, non-I/O interval operations. and
interval intrinsics.
For the new interval data type, diagnostic messages were added, an internal FFE
representations of the type was created, routines for the internal GBE translations
of the type were developed, and initializations of internal FFE and GBE interval
type information was provided. Also, code to recognize the interval keyword as a
statement or modier and code to assign internal interval type information based on
parsed keywords was added.
To support interval constants, diagnostics messages for interval constants, the ability
to recognize `[' and `]' as lexemes, and code to parse the constant were added. Also, the
internal representations and a new expression-parsing context for interval constants
were developed. In addition, routines to build IR entries and to translate FFE interval
constants to their GBE form were designed. To correctly handle unary minus by the
compiler, it was also necessary to add code to \fold" the unary-minus of an interval
constant and to not fold (i.e., leave as a runtime expression) other operations on
interval constants.
There were also several features added to support interval constant arrays. This
include the ability to extract an element of a constant array and the ability to creating
a new constant array. Also code to prepare for copying between constant arrays,
copying between a constant array and a constant scalar, and putting a value in an
element of a constant array was developed.
For the interval format speciers new diagnostic messages were added, and code to
parse the format speciers and to convert the format speciers to their runtime form
was developed. It was also necessary to provide data type information to the runtime
(I/O) library. This is not currently provided in the libf2c interface for formatted I/O,
since for existing data types it can be inferred from the format specier, assuming
the Fortran program is written correctly. However, with the addition of intervals, the
E, F and G format speciers can refer to either reals or intervals. Therefore, a new
8
runtime routine do o wt was dened and code to call the old routine was modied
to call the new one in the appropriate fashion.
To support non-I/O interval operations, new runtime routines were dened, and the
code that determines whether the operands are to unary or binary math operators
was modied to support intervals. Also, code that translates the FFE representations
of such operations to their GBE counterparts was added, and the ability to dene
runtime routines as operating on, or returning, interval-typed values was provided.
For interval intrinsics, the specications of several of the intrinsics' interfaces were
modied to allow intervals. Code to compile intrinsic operations to appropriate GBE
representations was also added. Additionally, the ability to dene an intrinsic as operating on, or returning, interval-typed values was provided, and code to automatically
produce documentation on intrinsics was modied to correctly handle the interval
data type.
Several changes still need to be made to the GNU Fortran Compiler as part of this
project. Compiler support for single precision intervals needs to be completed, and
code for generating runtime library calls for the rest of the interval intrinsics needs
to written and tested. In addition, some of the functionality currently implemented
by routines in the runtime library (e.g. interval relations and set operations) may be
supported directly by the compiler once it has been fully tested.
3 Interval Runtime Libraries
Routines to support interval arithmetic are being added to the existing GNU Fortran
runtime libraries. The GNU Fortran runtime directory, is composed of three subdirectories: libF77, libI77, and libU77. The libF77 directory contains the non-I/0
support routines needed by the GNU Fortran Compiler. Most of the routines in
libF77 provide support for Fortran intrinsic functions. The libI77 directory contains
support routines for Fortran I/O, as well as additional routines for le management.
The libU77 directory contains support routines for UNIX system function calls. The
libU77 directory was developed by Dave Love as part of the GNU Fortran Project.
The libF77 and libI77 directories are from the f2c package, which was developed at
Bell Labs, and is described in [24]. Source code for and further information on the
f2c package can be obtained from:
http://netlib.bell-labs.com/netlib/f2c/index.html
To incorporate the routines for interval arithmetic into the existing GNU Fortran
runtime libraries the non-I/O routines are being added to the libF77 directory and the
I/O routines are being added to the libI77 directory. Support routines for exception
9
handling, changing rounding modes, using oating point numbers, and initializing
intervals are accessible from both of these directories via symbolic links. Names for
the interval routines in the runtime libraries are derived from the names given in
the Interval Arithmetic Specication [1], and function denitions are designed to be
similar to those currently used in the runtime libraries.
The routines in the runtime library are design to support IEEE single and double
precision intervals in either big endian or little endian format. They are also designed
to run on a several dierent platforms including: Sun Sparc, DEC Alpha, SGI MIPS,
IBM RS/6000, and Intel x86 and Motorola 68k under Linux. So far, they have
been tested primarily on Sun Ultras. Later, they will be ported to a wider range
of platforms. To provide tight intervals, the routines use the underlying hardware's
built in IEEE rounding modes to produce minimum width intervals. Changing the
rounding modes is performed through platform specic function calls.
3.1 The non-I/O interval routines
The non-interval I/O routines include those which support interval arithmetic operations, set operations, relationals, and special and mathematical functions. There are
two versions of each routine: one for single precision intervals and a second for double
precision intervals. In the function denitions, single precision routines are prexed
with a u and double precision routines are prexed with a v. In C, the single and
double precision intervals are represented using the following structures.
typedef struct { double inf, sup; }
interval;
typedef struct { float inf, sup; } s_interval;
Table 1 shows the names, function denitions, and status for the interval arithmetic
routines. The three letters under the Status column indicate the current status of
the routine: written (W) or not written (NW), not tested (NT), partially tested
(PT) or rigorously tested (RT), and interfaced (I) or not interfaced (NI) with the
Fortran GNU Compiler. For each arithmetic operation, there are two routines listed:
one for single precision (SP) and one for double precision (DP). As the status column
indicates, all of the interval arithmetic routines have been written and partially tested.
The double precision routines have also been successfully interfaced with the GNU
Fortran Compiler.
As an example of the interval arithmetic routines, code for the v add subroutine
is shown below. The le for this routine contains two header le: round.h, which
denes machine specic macros for handling IEEE rounding modes, and interval.h,
which contains denitions for the interval data structures. The routine takes as input
arguments pointers to the intervals, a and b, and outputs the interval resx. Initially,
10
Table 1: Interval Arithmetic Routines
Routine Name
DP interval addition
DP interval subtraction
DP interval multiplication
DP interval division
SP interval addition
SP interval subtraction
SP interval multiplication
SP interval division
Function Denition
interval v add(interval *a, interval *b)
interval v sub(interval *a, interval *b)
interval v mul(interval *a, interval *b)
interval v div(interval *a, interval *b)
s interval u add(s interval *a, s interval * b)
s interval u sub(s interval *a, s interval *b)
s interval u mul(s interval *a, s interval *b)
s interval u div(s interval *a, s interval *b)
Status
W, PT, I
W, PT, I
W, PT, I
W, PT, I
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
the current IEEE rounding modes is saved. Then the rounding mode is set to round
towards minus innity and the lower interval endpoint of the sum is computed. After
this, the rounding mode is set to round towards positive innity and the upper interval
endpoint of the sum is computed. At the end of the routine, the rounding mode is
restored to its original value and interval result is returned. Implementation of the
other interval routines will be described in [25].
#include "round.h"
#include "interval.h"
interval v_add(interval *a, interval *b)
interval resx;
/* Interval sum */
RND_MODE_TYPE round_mode;
/* Variable for IEEE rounding mode */
round_mode = GET_ROUND();
/* Save the current rounding mode */
RND_DOWN();
/* Set rounding mode to minus infinity */
resx.inf = a->inf + b->inf; /* Compute lower endpoint of interval */
RND_UP();
/* Set rounding mode to plus infinity */
resx.sup = a->sup + b->sup; /* Compute upper endpoint of interval */
SET_ROUND(round_mode);
/* Restore the IEEE rounding mode */
return resx;
/* Return the result */
}
Table 2 and Table 3 show the names, function denitions, and status of the interval set
intrinsic routines and special interval function routines, respectively. These routines
have been written and partially tested, but have not yet been interfaced to the GNU
Fortran Compiler. Currently, these functions are implemented as part of the runtime
library. Because of the relative simplicity of many of these routines, they may later be
implemented directly by the GNU Fortran Compiler to improve runtime performance.
Interval set and relation operation routines are shown in Table 4. To limit the size
of this table, only the double precision versions of these routines are shown. The
function denitions for the single precision routines are identical, except interval is
replaced by s interval and double is replaced by oat. In a future release, these
routines are also likely to be implemented directly by the GNU Fortran Compiler.
11
Table 2: Interval Set Intrinsic Routines
Routine Name
DP inmum of an interval
DP supremum of an interval
DP interval intersection
DP interval hull
SP inmum of an interval
SP supremum of an interval
SP interval intersection
SP interval hull
Function Denition
double v inf(interval *a)
double v sup(interval *a)
interval v ix(interval *a, interval *b)
interval v ih(interval *a, interval *b)
oat u inf(s interval *a)
oat u sup(s interval *a)
s interval u ix(s interval *a, s interval *b)
s interval u ih(s interval *a, s interval *b)
Table 3: Special Interval Function Routines
Routine Name
DP interval width
DP interval midpoint
DP interval mignitude
DP interval magnitude
DP range of absolute Value
DP range of maximum
DP range of minimum
SP interval width
SP interval midpoint
SP interval mignitude
SP interval magnitude
SP range of absolute Value
SP range of maximum
SP range of minimum
Function Denition
double v wid(interval *a)
double v mid(interval *a)
double v mig(interval *a)
double v mag(interval *a)
interval v abs(interval *a)
interval v max(interval *a, interval *b)
interval v min(interval *a, interval *b)
oat u wid(s interval *a)
oat u mid(s interval *a)
oat u mig(s interval *a)
oat u mag(s interval *a)
s interval u abs(s interval *a)
s interval u max(s interval *a, s interval *b)
s interval u min(s interval *a, s interval *b)
12
Status
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
Status
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
Table 4: Interval Set and Relational Operation Routines
Routine Name
DP interval superset
DP interval proper superset
DP interval subset
DP interval proper subset
DP point in interval
DP disjoint intervals
DP interval set equal
DP interval set not-equal
DP interval less as set
DP interval less-or-equal as set
DP interval greater as set
DP interval greater-or-equal as set
DP interval certainly less
DP interval certainly less-or-equal
DP interval certainly greater
DP interval certainly greater-or-equal
DP interval certainly equal
DP interval certainly not-equal
DP interval possibly less
DP interval possibly less-or-equal
DP interval possibly greater
DP interval possibly greater-or-equal
DP interval possibly equal
DP interval possibly not-equal
Function Denition
logical v sp(interval *a, interval *b)
logical v psp(interval *a, interval *b)
logical v sb(interval *a, interval *b)
logical v psb(interval *a, interval *b)
logical v in(double *r, interval *b)
logical v dj(interval *a, interval *b)
logical v seq(interval *a, interval *b)
logical v sne(interval *a, interval *b)
logical v slt(interval *a, interval *b)
logical v sle(interval *a, interval *b)
logical v sgt(interval *a, interval *b)
logical v sge(interval *a, interval *b)
logical v clt(interval *a, interval *b)
logical v cle(interval *a, interval *b)
logical v cgt(interval *a, interval *b)
logical v cge(interval *a, interval *b)
logical v ceq(interval *a, interval *b)
logical v cne(interval *a, interval *b)
logical v plt(interval *a, interval *b)
logical v ple(interval *a, interval *b)
logical v pgt(interval *a, interval *b)
logical v pge(interval *a, interval *b)
logical v peq(interval *a, interval *b)
logical v pne(interval *a, interval *b)
Status
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
The value returned by each of these routines is type logical. Since a logical data type
is not directly supported in C, logical is implemented as a type-dened integer with
FALSE represented by 0 and TRUE represented by 1.
Table 5 and Table 6 show the names, function denitions, and status of the double
precision interval versions of the real-valued and integer-valued function routines and
mathematical function routines, respectively. Corresponding routines will also be
developed for single precision intervals. The real-valued and integer-valued functions
have been written and partially tested, but still need to be interfaced to the GNU
Fortran Compiler and tested more rigorously. The interval mathematical function
routines have not yet been written. For these routines, we have been in contact with
Dr. Walther Kramer of Karlsruhe University who is currently developing interval
elementary function routines. He expects these routines to become publically available
in late September or early October. If these routines do not become available in time,
we plan to modify existing point elementary function routines. Possible candidates for
this include routines from the fdlibm library, developed by Ng, or routines from the
cephes cmath library, developed by Moshier. Infomation on both of these packages is
13
Table 5: Real-Valued and Integer-Valued Function Routines
Routine Name
DP interval truncation
DP interval round to nearest
DP interval round to nearest integer
DP interval oor of inmum
DP interval ceiling of supremum
Function Denition
double v aint(interval *a)
double v anint(interval *a)
int v int(interval *a)
int v oor(interval *a)
int v ceiling(interval *a)
Status
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
Table 6: Interval Mathematical Function Routines
Routine Name
DP interval power of interval
DP interval power of integer
DP interval square root
DP interval exponential
DP interval natural logarithm
DP interval common logarithm
DP interval mod function
DP interval sign function
DP interval sin
DP interval cos
DP interval tan
DP interval asin
DP interval acos
DP interval atan
DP interval atan2
DP interval tanh
Function Denition
interval v pow v(interval *a, interval *b)
interval v pow i(interval *a, integer *n)
interval v sqrt(interval *a)
interval v exp(interval *a)
interval v log(interval *a)
interval v log10(interval *a)
interval v mod(interval *a, interval *b)
interval v mod(interval *a, interval *b)
interval v sin(interval *a)
interval v cos(interval *a)
interval v tan(interval *a)
interval v asin(interval *a)
interval v acos(interval *a)
interval v atan(interval *a)
interval v atan2(interval *a)
interval v tanh(interval *a)
Status
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
NW, NT, NI
available from:
http://netlib.bell-labs.com/netlib/
3.2 The interval I/O routines
The interval I/O routines are designed to interface directly with existing routines
in the libI77 runtime directory. This allows them to reuse much of the code that
is already available for I/O of real and complex numbers in Fortran. The routines
developed for interval I/O include several interval Fortran specic routines that are
designed for providing I/O in the VF, VE, VG, SF, SE, and SG formats specied in
the Interval Arithmetic Specic. In addition, there are a number of support routines
for performing conversion between character string and intervals or character strings
and oating point numbers. The support routines were developed base on routines
designed by Gay for oating point input [27] and by Burger and Dybvig [26] for
14
Routine Name
DP read interval V formats
SP read interval V formats
DP read interval S formats
SP read interval S formats
Read interval V formats
Read interval S formats
Write interval VF format
Write interval VE format
Write interval VG format
Write interval SF format
Write interval SE format
Write interval SG format
Table 7: Interval I/O Routines
Function Denition
interval v read fmtv(char *buer)
s interval u read fmtv(char *buer)
interval v read fmts(char *buer)
s interval u read fmts(char *buer)
int rd VF(uinterval *f, int w, int d, ftnlen len)
int rd SF(uinterval *f, int w, int d, ftnlen len)
int wrt VF(uinterval *f, int w, int d, ftnlen len)
int wrt VE(uinterval *f, int w, int d, int e, ftnlen len)
int wrt VG(uinterval *f, int w, int d, int e, ftnlen len)
int wrt SF(uinterval *f, int w, int d, ftnlen len)
int wrt SE(uinterval *f, int w, int d, int e, ftnlen len)
int wrt SG(uinterval *f, int w, int d, int e, ftnlen len)
Status
W, PT, I
W, PT, NI
NW, NT, NI
NW, NT, NI
W, PT, I
NW, NT, NI
W, PT, I
W, PT, I
W, PT, I
W, PT, NI
W, PT, NI
NW, NT, NI
oating point output. These routines were rst modied to provide correctly rounded
input and output, and then used to provide proper input and output of intervals.
Table 7 shows the names, function denitions, and status of the interval I/O routines.
The rst two routines are support routines that convert a character string, which
corresponds to an interval into a double precision or single precision interval. The
input interval can take any of the input formats specied in the Interval Arithmetic
Specication. The next two routines are similar, however, they allow the intervals
to be input using the single-valued formats. The rest of the routines are used to
read or write intervals using either list-direct or formatted input or output. For these
routines, uinterval corresponds to the union of a single and double precision oating
point intervals. This allows the same routine to be used for single and double precision
intervals.
3.3 Interval header les and support routines
Header les and support routines were developed to assist in adding interval arithmetic to the GNU Fortran Compiler. These les include denitions for the interval
data types (interval.h), denitions for various oating point values and parameters
(fp.h), denitions and routines for exception handling (except.h and except.c) and
support for directed rounding (round.h). Denintions and routines dened in these
les are used internally by the other routines in the interval runtime libraries.
Table 8 shows the names, function denitions, and status of the routines used for
interval exception handling. The rst two routines are used for getting and setting
the status ags for interval exceptions. The last two routines are used for getting
and setting the status ags that specify whether the program should halt when the
15
Routine Name
Get exception status
Set exception status
Get halting status
Set halting status
Table 8: Exception Function Routines
Function Denition
void int get except(int ex exception, logical *status)
void int set except(int ex exception, logical status)
void int get halt(int ex exception, logical status)
void int set halt(int ex exception, logical *status)
Status
W, PT, NI
W, PT, NI
W, PT, NI
W, PT, NI
Table 9: Rounding Mode Macros
Macro Name
Macro Denition
Set rounding mode to round up
RND UP()
Set rounding mode to round down
RND DOWN()
Set rounding mode to round to nearest RND NEAR()
Set rounding mode to specied value SET ROUND(mode)
Get rounding mode
mode GET ROUND()
Status
W, PT, I
W, PT, I
W, PT, I
W, PT, I
W, PT, I
corresponding interval exception occurs. The data type int ex is an enumerated type,
which can take values of
INTERVAL INVALID
INTERVAL DIVIDE BY ZERO
INTERVAL OUT OF DOMAIN
INTERVAL EMPTY
INTERVAL PARTIALLY OUT OF DOMAIN
as specied in the Interval Arithmetic Specication.
Table 8 shows the macro denitions used for setting and reading the underlying
hardware's IEEE rounding modes. These macros are dened to execute platformspecic systems calls. The GET ROUND() macro is used to obtain the current
rounding mode, and the SET ROUND() macro is used to set the rounding mode to
a user-specied value. The other routines allow the rounding mode to be set without
providing a rounding mode. The denitions for the rounding modes for the Sun Sparc,
DEC Alpha, SGI MIPS, and IBM RS/6000 platforms are complete. Minor additions
need to be made for Intel x86 and Motorola 68k machines running Linux.
16
4 Testing the Runtime Libraries and Compiler
One of benets of interval arithmetic algorithms is that they supply validated solutions. Therefore, it is extremely important that the underlying software used to
perform the interval algorithms is reliable. To help ensure this, extensive testing of
the interval compiler and runtime libraries must be being performed.
The rst set of interval tests, focuses on testing the routines in the runtime library,
independent of their interaction with the GNU Fortran Compiler. For each routine
in the runtime libraries, the following types of tests are conducted:
Interactive tests
Special case tests
Identity tests
Random tests
Interactive tests are typically run on the routine just after it is developed. Interactive
tests routines allow the user to specify the input values to the interval routine. The
test routine reads in the values, performs the specied function and outputs the result.
Interactive test routines are designed to catch more obvious bugs and to give the user
the ability to fairly quickly test a number of special cases.
After performing interactive tests, a number of special cases are tested, to ensure
that they produce correct results. This is typically done by reading the inputs from a
le, writing the results to a second le, and then performing manual checks to ensure
that correct results were produced. Examples of tests cases include testing division
by zero, multiplying very large or very small numbers together, taking the midpoint
of an innite interval, and taking the intersection of disjoint intervals. Naturally, the
types of random tests performed depend on the function being tested.
After ensuring that special cases work correctly, a large number identity tests are
run. Example of identity tests include + = + , + = 2 , and
+ = + ?( ). Several identity tests were supplied by Michael Parks of Sun
Microsystems. For many of the identities, outward rounding prevents identical results
from being produced. In these cases, it is often required to allow the results to dier
by a unit in the last place and handle cases which lead to overow or underow
separately. For example, ( + ) + = + ( + ) does not always produce
identical results for the the left and right hand side of the equations. Identity tests
are run for both random inputs and values input from a user-specied le.
After running identity tests, a large number of random tests are performed. The
random tests routines are designed to test the algorithm for a very large number of
X
X
Y
X
Y
Y
X
Y
X
Y
Z
X
17
Y
Z
X
X
X
pseudo-random inputs. One of the biggest diculties in performing random tests is
determining the correct value for the result. For the interval I/O routines, we were
able to test our results against results produced by Sun's oating point I/O routines.
The Sun routines produce the correctly rounded result if the rounding mode is set
prior to calling the routine. For the interval operations and functions, we have not
yet run large numbers of random cases, because we still need to develop a standard
against which to test the results. We are investigating using the extended precision
routines from Maple or cephes to provide an accurate estimate of the correct result,
however, further work remains to be done in this area.
Once the runtime routines are interfaced to the GNU Fortran Compiler additional
tests are run to ensure that correct results are still produced. Due to time constraints,
so far these tests have consisted mostly of interactive tests and testing special cases
from an input le. Large numbers of identity tests and random input still need to
be performed. After this the compiler will be tested more extensively by using it to
compile and run interval programs. As part of this project, we plan to develop a
validation test suite for the Interval Arithmetic Specication which can be used to
test the GNU Fortran Compiler, as well as future interval compilers.
5 Obtaining the Compiler and Runtime Libraries
Preliminary versions of the interval-enhanced compiler and the runtime libraries are
available from
http://www.eecs.lehigh.edu/~mschulte/compiler/code
5.1 Obtaining and using the compiler
Due to the interaction of the the g77 interface with the libgcc compiler, the f771
compiler, and the gcc and libf2c libraries the amount of code needed to compile and
install g77 is rather large. The gcc and g77 distributions occupy 8.6MB packed and
35MB unpacked, An additional 70 to 100 MB are required to perform the installation.
Therefore, for this preliminary release of the interval-enhanced compiler we are simply
providing Sun-Sparc excutables of the compiler.
To obtain the executable for the compiler, access the above Internet URL. A directory
containing a README le, some object les and libraries, sample interval programs,
and the compiler executables has been tarred and compressed into a le called compiler.tar.Z. Download this le into the directory from which you would like to run
the compiler. For the purposes of this discussion, we will refer to this directory as
18
path-name where path-name is the absolute path name to the directory (e.g.,
/usr/local/). After this, complete the following steps to allow the compiler to be run
from any directory.
<
>
<
>
1. Uncompress and extract the compiler directory. On most systems this can be
done by typing
uncompress < compiler.tar.Z | tar xf or
gunzip < compiler.tar.Z | tar xf -
This will extract the les into the path-name /compiler directory. This directory contains a bin dirctory that contains the compiler executables, a README
le, and source and executable for a sample interval Fortran program.
2. Specify the directory for g77 related les by typing
<
>
export G77_HOME=<path-name>/compiler/bin
or
setenv G77_HOME <path-name>/compiler/bin
Your may also want to add this command to the .cshrc, .prol, or .login le in
your home directory, so that you will not have to retype this command each
time you log in.
3. Test to ensure that G77 HOME was set correctly by typing
echo $G77_HOME
This should return path-name /compiler/bin.
4. Add path-name /compiler/bin to the path that is searched for commands by
typing
<
<
>
>
export PATH=$PATH:<path-name>/compiler/bin
or
setenv PATH $PATH:<path-name>/compiler/bin
Your may also want to add this command to the .cshrc le, .prol, or .login le
in your home directory.
19
After completing the above steps, you should be ready to run the compiler. To ensure
that the compiler works correctly, you can type make in the path-name directory.
If things are working correctly this will compile a Fortran program, sample.f, into an
executable le, sample. The sample.f is a fairly simple interval program that performs
several features provided by the rst release of the interval-enhanced compiler. This
program can be easily modied to test other cases. Since this is a preliminary release
of compiler, there are still some bugs and limitation in the functions provided. These
are described in more detail in the README le in the compiler directory.
<
<
5.2 Obtaining and using the runtime libraries
In addition to executables for the interval-enhanced compiler, source code and executables for the runtime library routines are also being provided. The routines
provided at this time are only a portion of the routines that have been developed
so far. This is because many of the routines in the runtime library (especially those
for interval I/O) are designed to interface with code developed for the libf2c library,
and consequently are not suitable for general use. Also, some of the routines that
have been developed (i.e., the ones for interval relations, set operations, and routines
for real-valued and integer-valued intrinsics) are not yet been documented and tested
thoroughly enough to be released.
The runtime libraries can be downloaded from the same location as the compiler. To
obtain the entire runtime library, download the le runtime.tar.Z, and extract by it
typing
uncompress < compiler.tar.Z | tar xf or
gunzip < compiler.tar.Z | tar xf -
The README le in this directory describes the directories contents. The example
directoy contains a program called ex-run.c that shows how to use many of the routines
in the runtime library.
6 Conclusions and Future Work
This document describes modications made to the GNU Fortran Compiler to provide
support for interval arithmetic. Although this work is still in the preliminary stages,
several important tasks have been accomplishments. We have modied the compiler
to recognize the interval data type, parse interval constants, and perform interval
arithmetic operations, and interval input and output. We have also developed runtime
20
libraries to assist with these and other interval functions and operations. We have
performed preliminary testing on the compiler and runtime libraries, however, more
extensive testing needs to be done. Preliminary versions of the compiler and routines
in the runtime are now available via the world wide web from the Internet location:
http://www.eecs.lehigh.edu/~mschulte/compiler
Further work remains to be done to modify the GNU Fortran Compiler to support
interval arithmetic. Some of the major tasks which need to be accomplished are
Modify the GNU Fortran Compiler to handle single precision intervals and the
remaining interval functions
Finish developing routines for the runtime libraries
Interface these routines to the GNU Fortran Compiler
Develop a validation test suite for the Interval Arithmetic Specication
Perform rigorous testing of the runtime libraries and the GNU Fortran Compiler
Make routines in the runtime library available to the teams working on global
optimization problems
Thoroughly document the compiler, runtime libraries, and validation test suite
After the initial work of adding interval support to the GNU Fortran Compiler is
complete, there are several opportunities for developing further support for interval
arithmetic. These include
Adding quadruple precision oating point and interval data types to the GNU
Fortran Compiler
Enhancing the GNU Fortran Compiler to perform better optimization on interval arithmetic code
Making modications to the GNU Back End to improve the runtime performance of interval arithmetic
Providing compiler support for intervals in other high level programming languages, such as Fortran 90, C, C++, and Java
Designing hardware support for interval arithmetic and for extended precision
arithmetic
21
Acknowledgments
The authors are very thankful to G. William Walster, Dimitry Chiriaev, Douglas
Priest, and Michael Parks for their valuable comments and advice. They are also
thankful to Sun Microsystems for providing the opportunity to work on this project.
References
[1] D. Chiriaev and G. W. Walster, Interval Arithmetic Specication 1997.
[2] R. B. Kearfott et al. A specic proposal for interval arithmetic in Fortran, 1996.
[3] Priest D., Handling IEEE 754 Invalid Operation Exceptions in Real Interval
Arithmetic, Manuscript, 1997.
[4] R. E. Moore, Interval Analysis. Prentice Hall, 1966.
[5] G. Alefeld and J. Herzberger, Introduction to Interval Computations. Academic
Press, 1983.
[6] Moore R.E. "Methods and applications of interval analysis" , SIAM Studies in
Applied Mathematics. SIAM, Philadelphia, Pennsylvania, 1979.
[7] R. Hammer, M. Hocks, U. Kulisch, and D. Ratz, C++ Toolbox for Veried
Computing. Springer-Verlag, 1995.
[8] V. Kreinovich, \Data Processing Beyond Traditional Statistics: Applications of
Interval Computations. A Brief Introduction," in Journal of Reliable Computing.
Supplement to the International Workshop on Applications of Interval Computations (V. Kreinovich, ed.), pp. 13{21, 1995.
[9] G. F. Corliss, \Industrial Applications of Interval Techniques," in Computer
Arithmetic and Self-Validating Numerical Methods (C. Ullrich, ed.), Academic
Press, pp. 91{113, 1990.
[10] E. Hansen, Global Optimization Using Interval Analysis. Marcel Dekker, 1992.
[11] R. B. Kearfott et al., \Algorithm 737: INTLIB: A Portable FORTRAN 77 Interval Standard Function Library," ACM Transactions on Mathematical Software,
vol. 20, pp. 447{459, 1994.
[12] O. Knuppel, \PROFIL/BIAS - A Fast Interval Library," Computing, vol. 53,
pp. 277{288, 1994.
22
[13] E. Hyvonen and S. D. Pascale, \InC++ Library Family for Interval Computations," in Journal of Reliable Computing. Supplement to the International Workshop on Applications of Interval Computations (V. Kreinovich, ed.), pp. 85{90,
1995.
[14] R. B. Kearfott, \A FORTRAN 90 Environment for Research and Prototyping of
Enclosure Algorithms for Nonlinear Equations and Global Optimization," ACM
Transactions on Mathematical Software, vol. 21, no. 1, pp.63{78, March, 1995.
[15] R. Klatte et al., PASCAL-XSC: Language Reference with Examples. SpringerVerlag, 1991.
[16] R. Klatte et al., C-XSC: A C++ Class Library for Extended Scientic Computing. Springer-Verlag, 1993.
[17] W. V. Walter, \ACRITH-XSC: A Fortran-like Language for Veried Scientic Computing," in Scientic Computing with Automatic Result Verication
(E. Adams and U. Kulisch, eds.), Academic Press, pp. 45{70, 1993.
[18] J. S. Ely, \The VPI Software Package for Variable Precision Interval Arithmetic,"
Interval Computations, vol. 2, pp. 135{153, 1993.
[19] R. B. Kearfott and M. Novoa, \INTBIS, A Portable Interval Newton Bisection
Package," ACM Transactions on Mathematical Software, vol. 16, pp. 152{157,
1990.
[20] R. B. Kearfott, Rigerous Global Search: Continuous Problems Kluwer Academic
Publishers, Dordchet, 1997.
[21] D. Priest, \Fast Table-Driven Algorithms for Interval Elementary Functions,"
Proceedings of the 13th Symposium on Computer Arithmetic, Pacic Grove, California, pp. 168-174, July, 1997.
[22] ANSI/IEEE 754-1985 Standard for Binary Floating-Point Arithmetic, Institute
of Electrical and Electronics Engineers, New York, 1985.
[23] G. W. Walster and E. R. Hansen, Composite Functions in Interval Mathematics,
Manuscript, 1997. Available as J3/97-198 document.
[24] S. L. Feldman, D. M. Guy, M. W. Maimone, and N. L. Schyer, \A Fortran-to-C
Converter," Computer Science Technical Report No. 149, AT&T Bell Laboratories, Murray Hill, NJ, 1995.
[25] M. J. Schulte, J. C. Burley, V. Zelov, and A. Akkas, \Working Note 20: Internal
Report on the Implementation of Interval Operations and I/O in GNU Fortran,"
to be prepared by January 15, 1998.
23
[26] R. G. Burger and R. K. Dybvig, \Printing Floating Point Numbers Quickly and
Accurately," Sigplan Notices, vol. 31, no. 5, pp. 108-116, May, 1996.
[27] D. M. Gay, \Correctly Rounded Binary-Decimal and Decimal-Binary Conversions," Numerical Analysis Manuscript 90-10, AT&T Bell Laboratories, November, 1990.
24
© Copyright 2026 Paperzz