.TH "YADC" 1x local
.SH NAME
yadc - yet another desk calculator.  
.SH SYNOPSIS
yadc < stdin > stdout
.SH DESCRIPTION
\fIyadc\fP is a simple desk calculator,
derived from Appendix A of the Yacc(1) manual, with
a couple of trivial elaborations to achieve at last a truly
convenient and flexible tool
for doing address and character arithmetic and 
bit-wise logic tests in mixed bases.
.PP
This approach has the following virtues:
.IP \(bu
One can specify individual
operands in their own base, integer decimal, octal, or hex, and 
.IP \(bu
get the result back in a different base, if desired.  
Operands are typed in the same
way as in C: octal constants are preceeded by a 0, hex numbers by the 
characters 0x.
.IP \(bu
Because of its bias towards address arithmetic, it implements
integer arithmetic only.
.IP \(bu
It works with the precision of the underlying hardware.
.IP \(bu
Character arithmetic is also available.  The method, again, is exactly like C:
the character to be evaluated is placed 
in single quotes, for example: 'a'.  Control characters are available,
as in C, by using backslash escapes: '\\n', '\\xxx', where xxx is 1 to 3
octal digits.
.IP \(bu
It implements the factorial! operator.
.PP
The default input radix is decimal.  To obtain other input radicies,
you must explicitly type the value of constants as octal or hex by preceeding
each number in a different base
with the character '0' for octal and the characters "0x" for hex.
There is no way to change the default input radix other than number by number.
.PP
To obtain the 
printed result in other than decimal, the expression may be preceeded with
a type specifier such as %o or %x.  The output type specifiers are exactly
as in the C output routine, printf.  (In fact the type specifier you supply
is handed bodily to printf with no checking, so be careful.)
Upon completion of an expression coerced with a '%' type specifier,
the output radix reverts to the default, which is initially
decimal.  
To coerce the output radix to stay on another base, use
a '$' sign instead of '%'.  Examples:
.RS .5i
.PP
.nf
7+1
8
%o7+1		(result of this one will be octal)
010
$o017+1		(all subsequent results will be in octal)
020
%x0xfe00+0xfe00 (this result will be hex, default still octal)
0x1fc00
$c055		(result will be interpreted as a character)
-		(which happens to be '-')
'a'-'\\t'	(character a minus character tab)
X		(interpreted as a character)
.RE
.fi
.PP
Available arithmetic operations, in order of increasing precedence:
(standard C precedence, and action)
.RS 1i
.PP
.nf
    | 
    ^
    &
    <<  >>
    +  -
    *  /  %
    @		(integer exponentiation, right associative)
    ~		(unary, one's complement)
    -		(unary minus)
    !		(factorial)
.RE
.fi
.PP
Nestable parenthesis, "()", are also available.  This is the order of
operator precedence given in [Kernighan].
.PP
There are individual storage registers labeled a-z (upper/lower case
independent) to which values may be assigned with '='.  
.SH SEE ALSO
.nf
dc(1), bc(1), yacc(2b)
[Kernighan], "The C Programming Language", pages 181, 215.
.SH BUGS
It only handles integer arithmetic.  All calculations are done as longs.  
It is thus not useful in modeling fractional integer binary number systems.
Storage registers
are also longs.
