4.0; dcalc (desk_calculator), revision 4.0, 82/01/08
DCALC (Desk_Calculator) -- Evaluate logical and arithmetic expressions.
usage: DCALC [-H] [pathname...]
FORMAT
DCALC [-H] [pathname...]
DCALC mimics the features of a desk calculator, evaluating both logical and
arithmetic expressions.
ARGUMENT
pathname
(optional) Specify input file containing expressions to be evaluated,
one expression per line.
Default if omitted: read standard input; stop with CTRL/Z
OPTION
If no options are specified, all operations are decimal-based.
-H Specify hexadecimal operations.
EXPRESSIONS
Input expressions can be simple arithmetic expressions or variable assignment
expressions. DCALC writes the value of each evaluated expression on standard
output. Variables hold temporary values, which DCALC does not automatically
write.
Expressions may include any of the operators listed below (in order of
precedence):
1. + - unary plus and negation operators. These may only appear
at the start of an expression or within parentheses.
2. << >> logical left and right shift
3. ** exponentiation
4. * / % multiply, divide, modulo (remainder)
5. + - add, subtract
6. == equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
7. ! unary logical not
8. | logical or
& logical and
^ logical xor
Relational operators return the value 1 for true and 0 for false. DCALC
performs operations in double precision floating point, except for logical
operators listed as items 2 and 8 above, which use 32-bit integers.
VARIABLES
Expressions may include previously declared variables. Use this format to
declare a variable:
name = expression
o A variable name must begin with a letter and may consist of any
combination of letters and digits.
o DCALC does not automatically print replacement expressions, because they
usually contain temporary values.
RADIX CONTROL
You can change the default base for input or output using ibase (input base)
and obase (output base) statements. For example,
ibase = 2
obase = 16
causes DCALC to interpret input in binary and print results in hexadecimal.
o To set an individual number's radix, precede it with the desired radix
and a pound sign. For example,
16#100
specifies the hexadecimal number 100 (equals 256 in decimal).
EXAMPLES
Your input: DCALC output:
1. 10 + (-64 / 2**4) 6
2. temp = 2#101
temp == 5 1 (true)
3. ibase = 16
obase = 2
1a + f 101001
4. ibase = 16
numa = 100
numb = 100
numa + numb 512