Browse Prior Art Database

Portable Conversion from IEEE Double Float to ASCII

IP.com Disclosure Number: IPCOM000105884D
Original Publication Date: 1993-Sep-01
Included in the Prior Art Database: 2005-Mar-20
Document File: 2 page(s) / 89K

Publishing Venue

IBM

Related People

Cross, MR: AUTHOR [+2]

Abstract

In database operations it is often necessary to convert numbers stored or defined as IEEE Double (Floating Point) to ASCII. When this function was added to the OS/2 */Database Manager it was determined that the new function must meet three essential criteria:

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 52% of the total text.

Portable Conversion from IEEE Double Float to ASCII

      In database operations it is often necessary to convert numbers
stored or defined as IEEE Double (Floating Point) to ASCII.  When
this function was added to the OS/2 */Database Manager it was
determined that the new function must meet three essential criteria:

1) Good performance characteristics.

2) Portability/predictability - provide the same results on different
   platforms and operating systems.

3) Uniformity - output always conforms to format prescribed by
calling
   parameters.

      Disclosed here is a numerical algorithm to be used in future
releases of OS/2 Database Manager.  It meets the above requirements
by providing excellent speed, portability, and uniform result format.
This algorithm assumes the following standard definitions:

1) A byte consists of eight bits.

2) A LONG INTEGER (4 bytes in the IBMC2 Compiler) has the capacity to
   contain the value 99999999.  (A LONG actually has a much higher
   capacity than needed, enough to handle 2147483647.)

3) A DOUBLE is as defined in the IEEE and SAA standards.

      This algorithm constructs the ASCII result from right to left.
Eight digits at a time are extracted from the FLOAT "fval" and put
into a LONG.  In turn, two digits at a time are taken from the LONG
and written into the ASCII string result.  The size of these moves
was chosen for efficiency and speed.

      Next, the following check is made to find if the value is
equivalent to zero so no further conversion is needed.  If the FLOAT
lies inside the interval (-MIN, MIN), the ASCII string result will be
+0.00000000000000e+000.  This value is machine-dependent and for the
IBMC2 Compiler, MIN is 2.25e-307.  After this check the rest of the
algorithm can assume that the FLOAT does not lie in (-MIN, MIN),
meaning equivalent to zero.

      Scientific notation has the form (+/-)d.dddddddddddddde(+/-)ddd
where d is a digit.  To show all accuracy, the ASCII result string
must show all 15 mantissa digits.  Then the FLOAT will be adjusted so
that its exponent is 14 and its magnitude is 10 raised to the
exponent 15.

      The float's exponent (as defined i...