home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / BCDD.DOC < prev    next >
Text File  |  1997-07-05  |  4KB  |  95 lines

  1. +++Date last modified: 05-Jul-1997
  2.  
  3. ---------------------------------------------------------------
  4. bcd_to_double()
  5. ---------------------------------------------------------------
  6. NAME:
  7.     bcd_to_double() - Converts a binary coded decimal value to type double.
  8.  
  9. SYNOPSIS:
  10.     #include "toolbox.h"
  11.     double bcd_to_double( void *buf, unsigned length, int digits );
  12.  
  13. DESCRIPTION:
  14.     The bcd_to_double() function will convert a buffer containing binary
  15.     coded values to a value of type double.  Binary coded decimal values
  16.     are typically data downloaded from a mainframe type computer.
  17.  
  18. ARGUMENTS:
  19.     void *buf       - Address of buffer containing binary coded value.
  20.     unsigned length - The length of the buffer.
  21.     int  digits     - The number of digits to the right of the decimal
  22.                       point.
  23.  
  24. RETURN VALUE:
  25.     A value of type double.
  26.  
  27. EXAMPLE:
  28.  
  29.     #include <stdio.h>
  30.     double bcd_to_double( void *buf, unsigned length, int digits );
  31.  
  32.     int main ( void ) {
  33.  
  34.         double rv;
  35.         char test1[] = { 0x00, 0x12, 0x34, 0x5c };
  36.         char test2[] = { 0x00, 0x12, 0x34, 0x56, 0x7d };
  37.  
  38.         printf( "%.2f\n", bcd_to_double( test1, sizeof(test1), 0));
  39.         printf( "%.2f\n", bcd_to_double( test2, sizeof(test2), 2));
  40.         return 0;
  41.     }
  42.  
  43. ---------------------------------------------------------------
  44. double_to_bcd()
  45. ---------------------------------------------------------------
  46. NAME:
  47.     double_to_bcd() - Converts a value of type double to Binary Coded
  48.                       Decimal format.
  49.  
  50. SYNOPSIS:
  51.     #include "toolbox.h"
  52.     int double_to_bcd(double arg, char *buf, unsigned len, unsigned digits);
  53.  
  54. DESCRIPTION:
  55.     The double_to_bcd() function converts a numeric value of type double
  56.     to a signed binary coded decimal format used by IBM mainframe
  57.     computers.  The function allows the number of decimal digits to be
  58.     specified as well as the number of significant digits to be
  59.     specified.  The resulting binary coded decimal value is adjusted
  60.     according to the position, if any, of the decimal point.
  61.  
  62. ARGUMENTS:
  63.     double   arg    - The numeric double value to be converted.
  64.     char     *buf   - The address of a buffer where the BCD format is to
  65.                       be stored.
  66.     unsigned len    - The number of significant digits to be stored.
  67.     unsigned digits - The number of decimal digits to be stored.
  68.  
  69. RETURN VALUE:
  70.     An integer value indicating the packed length of the BCD value.  A
  71.     -1 is returned if the value can not be converted.  Reasons for a
  72.     conversion failure are: (1) Both the len and digits arguments are
  73.     zero, or (2) The sum of the len and digits arguments is greater than
  74.     the number of significant digits that can be respresented by a value
  75.     of type double.  This value is specified by the manifest constant
  76.     DBL_DIG in the standard header file float.h.
  77.  
  78. SEE ALSO:
  79.     bcd_to_double()
  80.  
  81. EXAMPLE:
  82.  
  83.     Double       Length     Digits    Return
  84.     Argument     Argument   Argument  Value    Buffer
  85.     ===================================================================
  86.      12345.670      0          0       -1      Undetermined
  87.      12345.670      5          0        3      12 34 5C 
  88.      12345.670      5          1        4      01 23 45 6C 
  89.      12345.670      4          3        4      23 45 67 0C 
  90.      12345.678      1          2        2      56 7C 
  91.     -12345.000      8          2        6      00 00 12 34 50 0D 
  92.      -1234.560      5          3        5      00 12 34 56 0D 
  93.       1234.567      1          3        3      04 56 7C 
  94.  
  95.