~ubuntu-branches/ubuntu/maverick/bc/maverick

« back to all changes in this revision

Viewing changes to doc/dc.texi

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2004-04-29 20:54:22 UTC
  • Revision ID: james.westby@ubuntu.com-20040429205422-7p6w6hg8d5x5z2tn
Tags: 1.06-15
* configure.in: Patch was supposed to be '-I -8' (Closes: #237957)
* Also ran autoconf2.50 to re-create configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
@ifinfo
24
24
@direntry
25
 
* dc: (dc).                   Arbritrary precision RPN ``Desktop Calculator''.
 
25
* dc: (dc).                   Arbitrary precision RPN ``Desktop Calculator''.
26
26
@end direntry
27
 
This file documents @sc{dc}, an arbitrary precision calculator.
 
27
This file documents @command{dc}, an arbitrary precision calculator.
28
28
 
29
29
Published by the Free Software Foundation, Inc.
30
30
59 Temple Place, Suite 330
107
107
@comment  node-name,  next,  previous,  up
108
108
@chapter Introduction
109
109
 
110
 
@sc{dc} is a reverse-polish desk calculator
 
110
@command{dc} is a reverse-polish desk calculator
111
111
which supports unlimited precision arithmetic.
112
112
It also allows you to define and call macros.
113
 
Normally @sc{dc} reads from the standard input;
 
113
Normally @command{dc} reads from the standard input;
114
114
if any command arguments are given to it, they are filenames,
115
 
and @sc{dc} reads and executes the contents of the files
 
115
and @command{dc} reads and executes the contents of the files
116
116
instead of reading from standard input.
117
117
All normal output is to standard output;
118
118
all error messages are written to standard error.
126
126
Entering a number pushes it on the stack.
127
127
Arithmetic operations pop arguments off the stack and push the results.
128
128
 
129
 
To enter a number in @sc{dc}, type the digits,
 
129
To enter a number in @command{dc}, type the digits,
130
130
with an optional decimal point.
131
131
Exponential notation is not supported.
132
132
To enter a negative number, begin the number with @samp{_}.
139
139
@node Invocation, Printing Commands, Introduction, Top
140
140
@chapter Invocation
141
141
 
142
 
@sc{dc} may be invoked with the following command-line options:
 
142
@command{dc} may be invoked with the following command-line options:
143
143
@table @samp
144
144
 
145
145
@item -e @var{expr}
146
146
@item --expression=@var{expr}
147
 
Evaluate @var{expr} as @sc{dc} commands.
 
147
Evaluate @var{expr} as @command{dc} commands.
148
148
 
149
149
@item -f @var{file}
150
150
@item --file=@var{file}
151
 
Read and evaluate @sc{dc} commands from @var{file}.
 
151
Read and evaluate @command{dc} commands from @var{file}.
152
152
 
153
153
@item -h
154
154
@item --help
188
188
Assuming that (UCHAR_MAX+1) is 256
189
189
(as it is on most machines with 8-bit bytes),
190
190
the sequence
191
 
@code{KSK 0k1/ [_1*]sx d0>x [256~aPd0<x]dsxx sxLKk}
192
 
could also accomplish this function,
193
 
except for the side-effect of clobbering the x register.
 
191
@code{KSK0k1/ _1Ss[ls*]Sxd0>x
 
192
[256~Ssd0<x]dsxx
 
193
sx[q]Sq[Lsd0>qaPlxx]dsxx
 
194
sx0sqLqsxLxLK+k}
 
195
could also accomplish this function.
 
196
(Much of the complexity of the above native-dc code is due
 
197
to the ~ computing the characters backwards,
 
198
and the desire to ensure that all registers wind up back
 
199
in their original states.)
194
200
(Details of the behavior with a number are a GNU extension.)
195
201
 
196
202
@item f
266
272
The third value popped is the base which gets exponentiated,
267
273
which should be an integer.
268
274
For small integers this is like the sequence @code{Sm^Lm%},
269
 
but, unlike @code{^}, this command will work with arbritrarily large exponents.
 
275
but, unlike @code{^},
 
276
this command will work with arbritrarily large exponents.
270
277
(This command is a GNU extension.)
271
278
 
272
279
@item v
295
302
 
296
303
@item r
297
304
Reverses the order of (swaps) the top two values on the stack.
 
305
(This can also be accomplished with the sequence @code{SaSbLaLb}.)
298
306
(This command is a GNU extension.)
299
307
@end table
300
308
 
301
309
@node Registers, Parameters, Stack Control, Top
302
310
@chapter Registers
303
311
 
304
 
@sc{dc} provides at least 256 memory registers,
 
312
@command{dc} provides at least 256 memory registers@footnote{The
 
313
exact number of registers provided by @command{dc} depends
 
314
on the range of an @code{unsigned char} in the C compiler
 
315
used to create the @command{dc} executable.},
305
316
each named by a single character.
306
317
You can store a number in a register and retrieve it later.
307
318
 
338
349
@node Parameters, Strings, Registers, Top
339
350
@chapter Parameters
340
351
 
341
 
@sc{dc} has three parameters that control its operation:
 
352
@command{dc} has three parameters that control its operation:
342
353
the precision, the input radix, and the output radix.
343
354
The precision specifies the number of fraction digits
344
355
to keep in the result of most arithmetic operations.
381
392
@node Strings, Status Inquiry, Parameters, Top
382
393
@chapter Strings
383
394
 
384
 
@sc{dc} can operate on strings as well as on numbers.
385
 
The only things you can do with strings are print them
 
395
@command{dc} has a limited ability
 
396
to operate on strings as well as on numbers;
 
397
the only things you can do with strings are print them
386
398
and execute them as macros
387
 
(which means that the contents of the string are processed as @sc{dc} commands).
 
399
(which means that the contents of the string are processed
 
400
as @command{dc} commands).
388
401
Both registers and the stack can hold strings,
389
 
and @sc{dc} always knows whether any given object is a string or a number.
 
402
and @command{dc} always knows whether any given object is
 
403
a string or a number.
390
404
Some commands such as arithmetic operations demand numbers
391
405
as arguments and print errors if given strings.
392
406
Other commands can accept either a number or a string;
398
412
Makes a string containing @var{characters} and pushes it on the stack.
399
413
For example, @samp{[foo]P} prints the characters @samp{foo}
400
414
(with no newline).
 
415
Note that all square brackets (@samp{[}s and @samp{]}s) must be balanced;
 
416
there is no mechanism provided for handling unbalanced square brackets.
401
417
 
402
418
@item a
403
419
The mnemonic for this is somewhat erroneous: asciify.
404
420
The top-of-stack is popped.
405
421
If it was a number, then the low-order byte of this number
406
 
is converted into a string and pushed onto the stack.
 
422
is converted into a 1-character string
 
423
and pushed onto the stack.
407
424
Otherwise the top-of-stack was a string,
408
425
and the first character of that string is pushed back.
409
426
(This command is a GNU extension.)
455
472
this command exits from the macro and also from the macro which invoked it.
456
473
If called from the top level,
457
474
or from a macro which was called directly from the top level,
458
 
the @samp{q} command will cause @sc{dc} to exit.
 
475
the @samp{q} command will cause @command{dc} to exit.
459
476
 
460
477
@item Q
461
478
Pops a value off the stack and uses it as a count