Chapter Contents |
Previous |
Next |
SAS/C Compiler Changes in Release 7.50 |
The SAS/C compiler and library's floating-point support has been extensively changed and improved for Release 7.50. The changes are concentrated in three distinct, but overlapping areas:
IEEE Floating-Point Support |
The ISO standards document IEC 60559 defines a portable standard for floating-point computation known informally as IEEE floating-point. This standard is implemented by almost all computer systems presently in use. Until recently, the major exception to this statement was the IBM mainframe, which offered a different floating-point implementation defined by IBM in the 1960's. In the last decade, IBM has remedied this situation by offering an implementation of IEEE floating-point parallel to traditional IBM floating-point. Depending on their requirements, mainframe programs can choose to use traditional IBM floating-point, the more portable IEEE floating-point, or, for very advanced applications, both floating-point implementations.
There are advantages and limitations to the use of IEEE floating-point
by applications, and the choice between traditional mainframe floating-point
and IEEE floating-point is not always obvious.
The following list contains a few of the reasons that you might prefer to use IEEE floating-point:
The following list contains a few of the reasons that you might prefer to use traditional mainframe floating-point:
IBM's traditional floating-point format uses a base-16 representation, that is, the exponent represents a power of sixteen. IEEE floating-point uses a binary representation, with the exponent representing a power of two. For this reason, IBM calls its traditional floating-point format HFP (hexadecimal floating-point), and its IEEE format BFP (binary floating point). HFP and BFP are used as synonyms for traditional mainframe floating-point and IEEE floating-point in the rest of this document.
SAS/C IEEE Support |
When you compile a SAS/C program, you can specify the BFP
or NOBFP
option to specify
whether the default floating-point format is BFP or HFP. HFP is the default.
SAS/C enables programs to use both floating-point formats. This is
a useful option for programs such as debuggers, and for subroutine libraries
whose users want a choice of format. To support the use of both formats,
SAS/C provides the _ _binfmt
and _ _hexfmt
type modifiers, which can be used to specify
the floating-point format independently of whether the BFP
option is used. Similarly, H and B suffixes can be used
with floating-point constants to indicate the format.
Using Both IBM and IEEE Floating-Point Formats contains detailed rules on mixing the two formats, but the
basic premise you
should keep in mind is: You can use casts to convert between the two formats,
but mixed-mode expressions are, in general, not supported. In other words,
if you try to add a _ _binfmt double
to a _ _hexfmt double
, the compiler
cannot determine which kind of addition operation it should perform. You
therefore have to code a cast of one operand to the format of the other.
The SAS/C library of mathematical functions is completely supported
for both traditional and IEEE floating-point. However, some functions (such
as isinf
, which tests to see if its argument
is an infinite number) are not meaningful for hexadecimal floating point,
and return dummy results of little utility.
SAS/C has added format modifiers to the printf
and scanf
series of functions to enable either
format of floating-point number to be read or written. If a format specifier
does not have a floating-point type, the corresponding argument is assumed
to have the default floating-point format. Use of the extensions is not required
for programs which use only one kind of floating-point.
SAS/C and Mainframe Floating-Point Extensions |
The most recent generations of IBM mainframes have included extensions
to the floating-point hardware which enable improved performance for traditional
floating-point as well as for IEEE support. The SAS/C compiler option ARCHLEVEL(C)
can be specified to cause the compiler to generate
code that targets the newer floating-point hardware. If you specify the BFP
option, ARCHLEVEL(C)
is
the default ARCHLEVEL setting.
The two main advantages of ARCHLEVEL(C)
for traditional floating-point code are:
ARCHLEVEL(C)
will assign up to eight double or float register
variables. Without ARCHLEVEL(C)
, only two
register variables are supported.
SAS/C C99 Support |
SAS/C Release 7.50 supports many elements of the ISO C99 standard relating to floating-point. Some of these elements are oriented specifically to IEEE floating-point, but most apply to both formats.
The most significant SAS/C enhancements in support of C99 are:
float.h
,
with further information about the floating-point implementation.
printf
and scanf
functions for a
new %a
format for hexadecimal input and output of floating-point data.
fenv.h
,
that defines functions which enable you to test IEEE status flags, specify
the rounding mode, raise IEEE exceptions, and so forth. There are dummy implementations
of these functions for traditional mainframe floating point. Also, the header
file fenvtrap.h
(which is a SAS/C extension)
defines functions which let you control IEEE exception trapping.
isinf
(to test whether a number is infinite) and nextafter
(which returns the next floating-point number in a particular direction from
its argument). Others are more traditional mathematical operations like remainder
and log2
(logarithm
base 2). All of these functions are supported for BFP and HFP inputs. Functions
specific to IEEE such as isinf
will return
degenerate results when called for _ _hexfmt
arguments. See
SAS/C Library Reference, Volume 1 for a full list of the supported math functions.
exp
function to have a float version named expf
. While most
functions, such as exp
,
have a differently named variant function for use with float, a few functions
(for instance, the signbit
function) are defined
as macros that can be passed as an argument of any floating-point type.
tgmath.h
,
that is defined by the C99 standard to provide generic versions of math functions.
For instance, tgmath.h
defines an exp
macro which can accept any numeric argument, and returns
a result of the correct type.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.