Command Prompt for Windows




Command CALC

Function:

Perform basic arithmetic calculations in a batch file. The result is either displayed or stored in an environment variable called CALC.

Syntax:

CALC [?] expr
?Display the result only. Does not set the environment variable.
exprSequence of tokens, that can include the following :-
+Addition
-Subtraction
*Multiplication
/ or \Division
%Remainder or modulus
~Bitwise NOT
^Bitwise XOR
&Bitwise AND
|Bitwise OR
<<Left bit shift
>>Right bit shift
&&Logical AND
||Logical OR
!Logical NOT
<Boolean less then
>Boolean greater then
<=Boolean less then or equal to
>=Boolean greater then or equal to
==Boolean equal to
!=Boolean not equal to
(Left bracket
)right bracket
numbersEither integer or real numbers
stringsSequence of characters, enclosed in double quotes
environment variable namesName of an environment variable that contains either a number or a string. Do not include any %s around the environment variable name
functionsScientific and Miscellaneous functions

Warning:

When using tokens that include characters that have a special meaning (eg. <, >, & etc) then enclose the complete expr in brackets, as follows :-

CALC [?] ( expr )

When in doubt, use the above syntax.

Note:

The normal operator precedence is assumed, unless the left and right brackets are used to over-ride the default precedence.

When specifying an environment variable name in an expression, do not surround the name in %s. The parser will automatically load the environment variable at evaluation time. For example :-

SET count=1
CALC ? (count + 100)

will output the answer 101.

Examples on using CALC.

Also see command LET and Batch Files.