Chapter Contents |
Previous |
Next |
RBw.d |
Language element: | informat |
Category: | numeric |
Width range: | 2 to 8 |
Default width: | 4 |
Decimal range: | 0 to 10 |
OpenVMS specifics: | native floating-point representation |
Syntax | |
Details | |
Examples | |
Example 1: Single- vs. Double-Precision Representation | |
Example 2: Reading External Data | |
See Also |
Syntax |
RBw.d |
Details |
The RBw.d informat reads numeric data that are stored in native real-binary (floating-point) notation. Numeric data for scientific calculations are often stored in floating-point notation. (The SAS System stores all numeric values in floating-point notation.) A floating-point value consists of two parts: a mantissa that gives the value and an exponent that gives the value's magnitude.
It is usually impossible to key in floating-point binary data directly from a terminal, but many programs write floating-point binary data. Use caution if you are using the RBw.d informat to read floating-point data created by programs other than the SAS System because the RBw.d informat is designed to read only double-precision data.
Since the RBw.d informat is designed to read only double-precision data, it supports widths of less than 8 bytes only for those applications that truncate numeric data for space-saving purposes. RB4. does not expect a single-precision number that is truncated to 4 bytes.
External programs such as those written in C and FORTRAN can produce only single- or double-precision floating-point numbers. No length other than 4 or 8 bytes is allowed. The RBw.d informat allows a length of 3 through 8 bytes, depending on the storage you need to save.
The FLOAT4. informat has been created to read a single-precision,
floating-point number. If you read the hexadecimal notation
3F800000
with
FLOAT4., the result is a value of 1.
To read data created by a C or FORTRAN program, you need to decide on the proper informat to use. If the floating-point numbers require an 8-byte width, you should use the RB8. informat. If the floating-point numbers require a 4-byte width, you should use FLOAT4.
For more information about OpenVMS floating-point representation, see Architecture Reference Manual for Alpha and Architecture Reference Manual for VAX.
Examples |
Consider how the value of 1 is represented in single-precision
and double-precision notation. For single-precision, the hexadecimal representation
of the 4 bytes of data is
3F800000
.
For double-precision, the hexadecimal representation is
3FF0000000000000
.
The digits at the beginning of the data are different, indicating a different
method of storing the data.
Consider this C example:
#include <stdio.h> main() { FILE *fp; float x[3]; fp = fopen("test.dat","wb"); x[0] = 1; x[1] = 2; x[2] = 3; fwrite((char *)x,sizeof(float),3,fp); fclose(fp); }The file TEST.DAT will contain, in hexadecimal notation,
3f8000004000000040400000
.
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.