diff options
Diffstat (limited to 'doc/dc.1')
-rw-r--r-- | doc/dc.1 | 86 |
1 files changed, 59 insertions, 27 deletions
@@ -2,27 +2,18 @@ .\" dc.1 - the *roff document processor source for the dc manual .\" .\" This file is part of GNU dc. -.\" Copyright (C) 1994, 1997, 1998, 2000 Free Software Foundation, Inc. +.\" Copyright (C) 1994, 1997, 1998, 2000, 2001, 2005, 2006, 2008, 2013, 2016 +.\" Free Software Foundation, Inc. .\" -.\" This program is free software; you can redistribute it and/or modify -.\" it under the terms of the GNU General Public License as published by -.\" the Free Software Foundation; either version 2 of the License , or -.\" (at your option) any later version. +.\" Permission is granted to copy, distribute and/or modify this document +.\" under the terms of the GNU Free Documentation License, Version 1.2 or +.\" any later version published by the Free Software Foundation; with no +.\" Invariant Sections, with no Front-Cover Texts, and with no Back-Cover +.\" Texts. .\" -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU General Public License for more details. -.\" -.\" You should have received a copy of the GNU General Public License -.\" along with this program; see the file COPYING. If not, write to: -.\" The Free Software Foundation, Inc. -.\" 59 Temple Place, Suite 330 -.\" Boston, MA 02111 USA -.\" -.TH DC 1 "1997-03-25" "GNU Project" +.TH dc 1 "2008-05-22" "GNU Project" .ds dc \fIdc\fP -.ds Dc \fIDc\fP +.ds Dc \fIdc\fP .SH NAME dc \- an arbitrary precision calculator .SH SYNOPSIS @@ -48,7 +39,14 @@ Arithmetic operations pop arguments off the stack and push the results. .PP To enter a number in .IR dc , -type the digits with an optional decimal point. +type the digits +(using upper case letters +.I A +through +.I F +as "digits" when working +with input bases greater than ten), +with an optional decimal point. Exponential notation is not supported. To enter a negative number, begin the number with ``_''. @@ -93,7 +91,8 @@ be processed. A file name of .B - refers to the standard input stream. -The standard input will processed if no file names are specified. +The standard input will processed if no script files or +expressions are specified. .PD .SH Printing Commands @@ -114,9 +113,14 @@ Otherwise it is a number, and the integer portion of its absolute value is printed out as a "base (UCHAR_MAX+1)" byte stream. Assuming that (UCHAR_MAX+1) is 256 (as it is on most machines with 8-bit bytes), -the sequence \fBKSK 0k1/ [_1*]sx d0>x [256~aPd0<x]dsxx sxLKk\fP -could also accomplish this function, -except for the side-effect of clobbering the x register. +the sequence \fBKSK0k1/_1Ss [ls*]Sxd0>x +[256~Ssd0<x]dsxxsx[q]Sq[Lsd0>qaPlxx] +dsxxsx0sqLqsxLxLK+k\fP +could also accomplish this function. +(Much of the complexity of the above native-dc code is due +to the ~ computing the characters backwards, +and the desire to ensure that all registers wind up back +in their original states.) .TP .B f Prints the entire contents of the stack @@ -197,7 +201,8 @@ but, unlike \fB^\fP, this command will work with arbitrarily large exponents. Pops one value, computes its square root, and pushes that. -The precision value specifies the number of fraction digits in the result. +The maximum of the precision value and the precision of the argument +is used to determine the number of fraction digits in the result. .PP Most arithmetic operations are affected by the ``precision value'', which you can set with the @@ -219,6 +224,27 @@ Thus, ``4d*p'' computes 4 squared and prints it. .TP .B r Reverses the order of (swaps) the top two values on the stack. +(This can also be accomplished with the sequence \fBSaSbLaLb\fP.) +.TP +.B R +Pops the top-of-stack as an integer +.IR n . +Cyclically rotates the top +.I n +items on the updated stack. +If +.I n +is positive, then the rotation direction will make the topmost +element the second-from top; +if +.I n +is negative, then the rotation will make the topmost element the +.IR n -th +element from the top. +If the stack depth is less than +.IR n , +then the entire stack is rotated (in the appropriate direction), +without any error being reported. .SH Registers .PP @@ -235,6 +261,7 @@ it into register Copy the value in register .I r and push it onto the stack. +The value 0 is retrieved if the register is uninitialized. This does not alter the contents of .IR r . .PP @@ -311,8 +338,9 @@ Pushes the current precision on the stack. .SH Strings .PP -\*(Dc can operate on strings as well as on numbers. -The only things you can do with strings are +\*(Dc has a limited ability to operate on strings +as well as on numbers; +the only things you can do with strings are print them and execute them as macros (which means that the contents of the string are processed as \*(dc commands). @@ -434,9 +462,13 @@ Status Inquiry .TP .B Z Pops a value off the stack, -calculates the number of digits it has +calculates the number of decimal digits it has (or number of characters, if it is a string) and pushes that number. +The digit count for a number does +.I not +include any leading zeros, +even if those appear to the right of the radix point. .TP .B X Pops a value off the stack, |