home *** CD-ROM | disk | FTP | other *** search
- PRINTF Library Documentation
-
- PRINTF2 supplies formatted output like that described by
- Kernighan and Richie. Input conversion routines utoi (for
- unsigned integers) and atof (for floating point numbers) are
- also supplied. PRINTF1 is identical except that formats 'f'
- and 'e', of printf, and functions ftoe, ftoa, and atof, are
- missing. Thus, PRINTF2 requires FLOAT while PRINTF1 does not
- require it.
-
-
- FUNCTIONS
-
- printf(controlstring, arg, arg, ...) -- formatted print
- "controlstring" is a string which can contain any of
- the following format codes:
- %d decimal integer
- %u unsigned decimal integer
- %x hexidecimal integer
- %c ASCII character
- %s null-terminated ASCII string
- %f fixed point conversion for double
- %e floating point conversion for double
- For each format code, there is an "arg" - a pointer to
- an object of that type. Between the '%' and the format
- code letter field specification may appear. For formats
- 'f' and 'e', the specification consists of two integers
- separated by a period. The first specifies the minimum
- field width, and the second the number of digits to be
- printed after the decimal point. For all other formats,
- the specification consists only of the one integer
- giving the minimum field width. If there is no field
- specification, the item is printed in no more space
- than is necessary.
- Example Output
- printf(" decimal: %d ",15+2) decimal: 17
- printf(" unsigned: %u ",-1) unsigned: 65535
- printf(" hexidecimal: %x ",-1) hexidecimal: FFFF
- printf(" string: %s ","hello") string: hello
- printf(" character: %c ",65) character: A
- printf(" fixed: %f ",1./7.) fixed: .142857
- printf(" exponent: %8.5e ",1./7.) exponent: 1.42857e-1
-
- itod(n, str, sz) int n; char str[]; int sz;
- convert n to signed decimal string of width sz,
- right adjusted, blank filled; returns str
- if sz > 0 terminate with null byte
- if sz = 0 find end of string
- if sz < 0 use last byte for data
-
- itou(nbr, str, sz) int nbr; char str[]; int sz;
- convert nbr to unsigned decimal string of width sz,
- right adjusted, blank filled; returns str
- if sz > 0 terminate with null byte
- if sz = 0 find end of string
- if sz < 0 use last byte for data
-
- itox(n, str, sz) int n; char str[]; int sz;
- converts n to hex string of length sz, right adjusted
- and blank filled, returns str
- if sz > 0 terminate with null byte
- if sz = 0 find end of string
- if sz < 0 use last byte for data
-
- ftoa(x,f,str) double x; int f; char *str;
- converts x to fixed point string with f digits after
- the decimal point, return str
-
- ftoe(x,f,str) double x; int f; char *str;
- converts x to floating point string with f digits after
- the decimal point, return str
-
- utoi(decstr, nbr) char *decstr; int *nbr;
- converts unsigned decimal ASCII string to integer
- number. Returns field size, else ERR on error. (This is
- used to interpret the specification fields.)
-
- atof(str) char *str;
- converts from ASCII to floating point, returns the
- double value. The general input format is
- [-][integer][.[fraction]][e[-]exponent], where things
- in brackets are optional (except that either an integer
- or a fractional part must be present).
- Examples Values
- 1 1. 1.0 1.
- .1 1.e-1 10.e-2 .01e1 0.1
- Conversion stops with the first character that doesn't
- match the above format.
-
-
- AUTHOR
- J. E. Hendrix for the original routines. J. R.
- Van Zandt for ftoa, ftoe, atof, and the floating point
- modifications in printf.
-
-
- INTERNAL DOCUMENTATION
-
- The method used in ftoa to convert to a decimal string
- involves more divisions than the classical method, but does not
- require that the original number be scaled down at the
- beginning. It was found that this initial scaling was causing
- loss of precision. The present algorithm should always convert
- an integer exactly if it can be represented exactly as a
- floating point number (that is, if it is less than 2**40).
-