2 printf - formatted print to standard output
5 printf(fmt, x_1, x_2, ...)
14 The function printf() is similar to the C function with the same name.
15 The most significant difference is that there is no requirement
16 that the types of values of the arguments x_i match the
17 corresponding format specifier in fmt. Thus, whatver the
18 format specifier, a number is printed as a number, a string as
19 a string, a list as a list, a matrix as a matrix, an xx-object
22 Except when a '%' is encountered, characters of the string fmt are
23 printed in succession to the standard output. Occurrence of
24 a '%' indicates the intention to build a format specifier.
25 This is completed by a succession of characters as follows:
28 zero or more decimal digits
29 an optional '. followed by zero or more decimal deigits
31 one of the letters: d, s, c, f, e, r, o, x, b,
33 If any other character is read, the '%' and any characters
34 between '%' and the character are ignored and no specifier is
35 formed. E.g. "%+f" prints as if only "f" were read; "% 10s"
36 prints as "10s", "%X" prints as "X", "%%" prints as "%".
38 The characters in a format specifier are interpreted as follows:
40 a minus sign sets the right-pad flag;
41 the first group of digits determines the width w;
42 w = 0 if there are no digits
43 a dot indicates the precision is to be read from the
44 following digits; if there is no dot,
45 precision = config("display").
46 any digits following the . determines the precision p;
47 p = 0 if there are no digits
48 any 'l' before the final letter is ignored
49 the final letter determines the mode as follows:
51 d, s, c current config("mode")
52 f real (decimal, floating point)
59 If the number of arguments after fmt is less than the
60 number of format specifiers in fmt, the "missing" arguments
61 may be taken to be null values - these contribute nothing to the
62 output; if a positive width w has been specified, the effect is
63 to produce w spaces, e.g. printf("abc%6dxyz") prints "abc xyz".
65 If i <= the number of specifiers in fmt, the value of argument x_i
66 is printed in the format specified by the i-th specifier.
67 If a positive width w has been specified and normal printing of x_i
68 does not include a '\n' character, what is printed will if necessary
69 be padded with spaces so that the length of the printed output
70 is at least the w. Note that control
71 characters like '\t', '\b' each count as one character. If
72 the 'right-pad' flag has been set, the padding is on the right;
73 otherwise it is on the left.
75 If i > the number of specifiers in fmt, the value of argument x_i
76 does not contribute to the printing. However, as all arguments
77 are evaluated before printing occurs, side-effects of the
78 evaluation of x_i might affect the result.
80 If the i-th specifier is of numerical type, any numbers in the
81 printing of x_i will be printed in the specified format, unless
82 this is modified by the printing procedure for x_i's type. Any
83 specified precision will be ignored except for floating-point
86 In the case of floating-point (f) format the precision determines
87 the maximum number of decimal places to be
88 displayed. Other aspects of this printing may be affected by the
89 configuration parameters "outround", "tilde", "fullzero", "leadzero".
92 ; c = config("epsilon", 1e-6); c = config("display", 6);
93 ; c = config("tilde", 1); c = config("outround", 0);
94 ; c = config("fullzero", 0);
95 ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n";
97 ; printf(fmt,a,a,a,a,a,a);
98 1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
100 ; c = config("tilde", 0); c = config("outround",24);
101 ; c = config("fullzero", 1);
102 ; printf(fmt,a,a,a,a,a,a);
103 1.732051, 1.732051,1.732051 , 1.7321,1.7321,2.
105 ; mat A[4] = {sqrt(2), 3/7, "undefined", null()};
106 ; printf("%f%r",A,A);
107 mat [4] (4 elements, 4 nonzero):
113 mat [4] (4 elements, 4 nonzero):
121 The number of arguments of printf() is not to exceed 1024.
127 fprintf, strprintf, print
129 ## Copyright (C) 1999-2006 Landon Curt Noll
131 ## Calc is open software; you can redistribute it and/or modify it under
132 ## the terms of the version 2.1 of the GNU Lesser General Public License
133 ## as published by the Free Software Foundation.
135 ## Calc is distributed in the hope that it will be useful, but WITHOUT
136 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
137 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
138 ## Public License for more details.
140 ## A copy of version 2.1 of the GNU Lesser General Public License is
141 ## distributed with calc under the filename COPYING-LGPL. You should have
142 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
143 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
145 ## @(#) $Revision: 30.1 $
146 ## @(#) $Id: printf,v 30.1 2007/03/16 11:10:42 chongo Exp $
147 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/printf,v $
149 ## Under source code control: 1996/03/12 22:50:41
150 ## File existed as early as: 1996
152 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
153 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/