Command: compute
COMPUTE is a very simple program for evaluating mathematical ex-
pressions.
Syntax:
Use common notation used on computers. Powers can be specified
by "^" operator. These functions are supported:
SIN
COS
SQR
TAN
COTAN
ARCSIN
ARCCOS
ARCTAN
LN
EXP
NOT
You can also use these bit operators: AND, OR, XOR
Options:
Argument can be given as a program parameter or can be typed inter-
actively.
If everything is OK, return code is 0, else it is non-zero:
1: non valid expression
2: division by zero
3: wrong argument for power
4: floating point number for logical operation
5: result is too big
6: result is too small
7: zero or negative logarithm
Comments:
COMPUTE can use the language resource strings if ENVIRONMENT VARIABLES
LANG and NLSPATH are properly set. Otherwise default strings will be
used.
Examples:
Create test.bat (to make the errorlevels visible):
TEST.BAT
---------------------------------------------
@echo off
compute %1 %2 %3 %4 %5 %6 %7 %8 %9
for %%e in (0,1,2,3,4,5,6,7,8,9) do if errorlevel %%e set err=%%e
echo Errorlevel value: %err%
set err=
---------------------------------------------
Then execute test.bat:
Example 1: Alternative:
TEST 5+5 compute 5+5
10 10
Errorlevel value: 0 (Errorlevel 0 is given but not shown)
Example 2:
TEST 5+ compute 5+
Error on pos. n. 2 Error on pos. n. 2
Errorlevel value: 1 (Errorlevel 1 is given but not shown)
Example 3:
TEST 5/0 etc. etc.
division by zero
Errorlevel value: 2
Example 4:
TEST 5^11
48828125
Errorlevel value: 0
Example 5:
TEST 222^999
too big result in math operation
errorlevel value: 6
Example 6:
TEST 1*2*3*4*5*6+7-8/9
726.111
errorlevel value: 0
See also:
environment variable
errorlevel/exitcode/return code
Copyright © 2008 Laaca, help version 2023 W. Spiegl.
This file is derived from the FreeDOS Spec Command HOWTO.
See the file H2Cpying for copying conditions.