User's Manual

NUMERIC PROGRAMMING EXAMPLES
Exception Considerations
Care
is
taken inside the function to avoid generating exceptions. Any possible numeric value
will
be
accepted. The only exceptions possible would occur if insufficient space exists
on
the numeric register
stack.
The value passed in the numeric stack
is
checked for existence, type
(NaN
or infinity), and status
(unnormal, denormal, zero, sign). The string size
is
tested for a minimum and maximum value.
If
the
top of the register stack
is
empty, or the string size
is
too small, the function will return with an error
code.
Overflow and underflow
is
avoided inside the function for very large or very small numbers.
Special Instructions
The functions demonstrate the operation of several numeric instructions, different data types, and
precision control.
Shown are instructions for automatic conversion to BCD, calculating the value of
10
raised to an integer value, establishing and maintaining concurrency, data synchronization, and use of
directed rounding
on
the NPX.
Without the extended precision data type and built-in exponential function, the double precision accuracy
of this function could not be attained with the size and speed of the shown example.
The function relies
on
the numeric BCD data type for conversion from binary floating-point to decimal.
It
is
not difficult
to
unpack the BCD digits into separate ASCII decimal digits. The major
work
involves
scaling the floating-point value to the comparatively limited range of BCD values. To print a 9-digit
result requires accurately scaling the given value to an integer between
10
8
and
10
9
For example, the
number +0.123456789 requires a scaling factor of
10
9
to produce the value + 123456789.0, which
can be stored in 9 BCD digits. The scale factor must be an exact power of
10
to avoid
to
changing any
of the printed digit values.
These routines should exactly convert all values exactly representable in decimal in the field size given.
Integer values that fit in the given string size
will
not be scaled, but directly stored into the BCD form.
Noninteger values exactly representable in decimal within the string size limits
will
also be exactly
converted. For example,
0.125
is
exactly representable in binary or decimal. To convert this floating-
point value
to
decimal, the scaling factor
will
be
1000, resulting in 125. When scaling a value, the
function must keep track of where the decimal point lies in the final decimal value.
Description of Operation
Converting a floating-point number to decimal ASCII takes three major steps: identifying the magni-
tude of the number, scaling it for the BCD data type, and converting the BCD data type
to
a decimal
ASCII
string.
Identifying the magnitude of the result requires finding the value
X such
that
the number
is
repre-
sented
by
1*
lOX,
where
1.0
< = I < 10.0. Scaling the number requires multiplying it
by
a scaling
factor
lOS,
so
that the result
is
an integer requiring
no
more decimal digits than provided for in the
ASCII
string.
Once scaled, the numeric rounding modes and BCD conversion put the number
in
a form easy to
convert
to
decimal
ASCII
by host software.
4-15