home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols200 / vol224 / printf.dqc / PRINTF.DOC
Text File  |  1986-02-09  |  4KB  |  106 lines

  1.         PRINTF Library Documentation
  2.  
  3. PRINTF2 supplies formatted output like that described by
  4. Kernighan and Richie. Input conversion routines utoi (for
  5. unsigned integers) and atof (for floating point numbers) are
  6. also supplied. PRINTF1 is identical except that formats 'f'
  7. and 'e', of printf, and functions ftoe, ftoa, and atof, are
  8. missing. Thus, PRINTF2 requires FLOAT while PRINTF1 does not
  9. require it.
  10.  
  11.  
  12. FUNCTIONS
  13.  
  14. printf(controlstring, arg, arg, ...) -- formatted print 
  15.     "controlstring" is a string which can contain any of
  16.     the following format codes: 
  17.         %d    decimal integer 
  18.         %u    unsigned decimal integer 
  19.         %x    hexidecimal integer 
  20.         %c    ASCII character 
  21.         %s    null-terminated ASCII string 
  22.         %f    fixed point conversion for double
  23.         %e    floating point conversion for double 
  24.     For each format code, there is an "arg" - a pointer to
  25.     an object of that type. Between the '%' and the format
  26.     code letter field specification may appear. For formats
  27.     'f' and 'e', the specification consists of two integers
  28.     separated by a period. The first specifies the minimum
  29.     field width, and the second the number of digits to be
  30.     printed after the decimal point. For all other formats,
  31.     the specification consists only of the one integer
  32.     giving the minimum field width. If there is no field 
  33.     specification, the item is printed in no more space 
  34.     than is necessary. 
  35.         Example              Output 
  36.     printf(" decimal: %d ",15+2)      decimal: 17  
  37.     printf(" unsigned: %u ",-1)      unsigned: 65535  
  38.     printf(" hexidecimal: %x ",-1)      hexidecimal: FFFF  
  39.     printf(" string: %s ","hello")      string: hello  
  40.     printf(" character: %c ",65)      character: A  
  41.     printf(" fixed: %f ",1./7.)      fixed: .142857  
  42.     printf(" exponent: %8.5e ",1./7.) exponent: 1.42857e-1
  43.  
  44. itod(n, str, sz)  int n;  char str[];  int sz;  
  45.     convert n to signed decimal string of width sz, 
  46.     right adjusted, blank filled; returns str 
  47.     if sz > 0 terminate with null byte 
  48.     if sz = 0 find end of string 
  49.     if sz < 0 use last byte for data 
  50.   
  51. itou(nbr, str, sz)  int nbr;  char str[];  int sz;  
  52.     convert nbr to unsigned decimal string of width sz, 
  53.     right adjusted, blank filled; returns str 
  54.     if sz > 0 terminate with null byte 
  55.     if sz = 0 find end of string 
  56.     if sz < 0 use last byte for data 
  57.   
  58. itox(n, str, sz)  int n;  char str[];  int sz;  
  59.     converts n to hex string of length sz, right adjusted 
  60.     and blank filled, returns str 
  61.     if sz > 0 terminate with null byte 
  62.     if sz = 0 find end of string 
  63.     if sz < 0 use last byte for data 
  64.   
  65. ftoa(x,f,str) double x; int f; char *str; 
  66.     converts x to fixed point string with f digits after 
  67.     the decimal point, return str 
  68.   
  69. ftoe(x,f,str) double x; int f; char *str; 
  70.     converts x to floating point string with f digits after
  71.     the decimal point, return str 
  72.  
  73. utoi(decstr, nbr)  char *decstr;  int *nbr;  
  74.     converts unsigned decimal ASCII string to integer 
  75.     number. Returns field size, else ERR on error. (This is
  76.     used to interpret the specification fields.) 
  77.  
  78. atof(str) char *str;
  79.     converts from ASCII to floating point, returns the
  80.     double value. The general input format is
  81.     [-][integer][.[fraction]][e[-]exponent], where things
  82.     in brackets are optional (except that either an integer
  83.     or a fractional part must be present).
  84.     Examples                Values
  85.     1   1.   1.0                1.
  86.     .1   1.e-1   10.e-2   .01e1        0.1
  87.     Conversion stops with the first character that doesn't
  88.     match the above format. 
  89.  
  90.  
  91. AUTHOR
  92.     J. E. Hendrix for the original routines. J. R.
  93.     Van Zandt for ftoa, ftoe, atof, and the floating point
  94.     modifications in printf.
  95.  
  96.  
  97. INTERNAL DOCUMENTATION 
  98.  
  99.     The method used in ftoa to convert to a decimal string
  100. involves more divisions than the classical method, but does not
  101. require that the original number be scaled down at the
  102. beginning. It was found that this initial scaling was causing
  103. loss of precision. The present algorithm should always convert
  104. an integer exactly if it can be represented exactly as a
  105. floating point number (that is, if it is less than 2**40).
  106.