home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
calculat
/
calc_v22.zip
/
CALC.DOC
< prev
next >
Wrap
Text File
|
1991-01-22
|
19KB
|
513 lines
calc version 2.2
NAME
calc - "infinite" precision calculator
VERSION
2.2 22-Jan-1991 (COPYRIGHT (c) 1991 Frenz)
SYNOPSIS
calc [-h] [file ...] [-q]
DESCRIPTION
calc is a processor for an arithmetic language which has most of
the operators of C and some others and also provides "infinite"
precision numbers. calc executes "calc programs" from any files
given on the command line and then reads from the standard input.
calc provides "infinite" precision integer and real operations.
The maximum integer to be expressed would constitute 68,719,476,735
bits, which is roughly equivalent to 20,686,623,783 decimal digits.
Assuming you printed this number on paper with 60 lines per page,
80 digits per line and both sides of the paper, this would require
2,154,856 sheets of paper. Thus, if you put 1,000 sheets into 1
book, this would require 2,155 books for just this one number.
One must realize that this number would also consume 8.2 gigabytes
of memory, just one number! Thus, even though this is not infinite
precision, most users will not actually reach this limit.
Note however, that some operations only compute efficently for
numbers less than 4,294,967,295 bits or 1,292,913,986 decimal digits.
This number would require about 500MB of memory.
OPTIONS
-h Print a help message
-q quit processing. Useful if a file is known not to have a
'quit' in it.
file process this file as if the user was typing it
VARIABLES
Variables are allowed and can be up to 512 characters long.
Variables in a "calc program" begin with a letter and are followed
by letters, digits or underscores. Also, note that variables will
be case sensitive, in the spirit of C. Therefore, the variable
"a_" will be different than "A_".
A variable can also be designated as an array by following the
variable name with '[', an expression, and ']'.
PREDEFINED VARIABLES
last holds the result of the evaluation of the last expression.
This is useful if you type in an expression without storing
it in a variable and decide that you wanted the result. Now
it can be retrieved with this variable. Thus, you should
assign this to another variable if you really want the result
of the last expression saved.
ibase
specifies the default input base of your numbers
obase
specifies the default output base of your numbers
scale
specifies the precision that calculations will be performed
to and written out in
width
the number of digits to print on a line
pi the constant pi to 28 decimal places (3.1415 ...)
exp the constant exp to 28 decimal places (2.718 ...)
PREDEFINED WORDS
break
used in loops, same meaning as in C
continue
used in loops, same meaning as in C
return
used in functions, same meaning as in C
stats
gives a short message about the current use of internal memory
used in the program
quit quits the program
help prints a help message regarding operators, predefined
functions, and user defined functions.
PREDEFINED FUNCTIONS
trunc( num )
performs a truncation on the real number num, trunc( 3.7 ) = 3
round( num )
rounds the real number num, round( 3.7 ) = 4
choose( n1, n2 )
performs the choose function, or combinations, i.e.
choose( 20, 5 ) = 20! / ( 5! * 15!) = 15504
factorial( num )
performs a factorial on the argument num, for example,
factorial( 6 ) = 6! = 720
note that this function is also called via the ! operator.
lg( num )
performs a logarithm base 2 on the argument num
log( num )
performs a logarithm base 10 on the argument num
ln( num )
performs the natural logarithm on the argument num, i.e.
base 2.718...
sqrt( num )
performs the square root of the given number
sin( num )
returns the sine of num, where num is in radians
cos( num )
returns the cosine of num, where num is in radians
tan( num )
returns the tangent of num, where num is in radians
asin( num )
returns the arc-sine of num, where num is in radians
acos( num )
returns the arc-cosine of num, where num is in radians
atan( num )
returns the arc-tangent of num, where num is in radians
print( str, arg [, arg] )
works like the printf() function in C, str is the format
string, and the arguments follow. A maximum of nine
arguments are allowed.
loan( loan_amount, months, interest, payment )
given three non-zero arguments, this function will
calculate the fourth argument.
show( arg )
will display the argument arg on the screen. If arg is a
user defined function name with the parentheses, the full
definition of the function is displayed on the screen. If
arg is an array name with the brackets, the full array is
displayed.
save( file_name )
will save all user defined functions, variables, and arrays
to the specified file.
load( file_name )
will read in the contents of the specified file. This is useful
for loading already defined functions.
read( variable )
will wait for the user to enter an expression, which is
evaluated and stored into the specified variable
USER DEFINED FUNCTIONS
You may write your own functions by entering the word "define"
followed by a function definition. For example, here is the
abs() function:
define abs( num ) {
if ( num < 0 ) return -num;
return num;
}
The value returned by a function will be the return expression or the
result of the last statement evaluated. The result will be printed
if the return is used.
If you need to declare that a function exists and want to define it
later do this:
define later()
define now( arg1, arg2 ) {
/* some statements */
}
define later( arg1, arg2 ) {
/* some statements */
}
STATEMENTS
An statement is evaluated once a semicolon is entered or a newline
is entered and the statement does not end with an operator. The
result of a statement is printed unless the last operator
evaluated was an assignment or the "_" operator. Also, a
statement is not immediately evaluated if it is enclosed within
another statement or a function.
Remember the result of the last statement is stored in the
variable "last". But don't use this variable within an expression.
A statement can be any of the following:
expression
{ statement; ...; statement; }
if ( expression ) statement
if ( expression ) statement else statement
while ( expression ) statement
for ( expression; expression; expression ) statement
break /* only in a for or while loop */
continue /* only in a for or while loop */
return expression /* only in a function */
quit /* action is immediate */
EXPRESSIONS
An expression can be any of the following:
variable
number
function_call( arguments )
expression operator expression
( expression )
unary-operator expression
expression unary-operator
Note that only one pre/post-unary operator is allowed per
expression. Thus, "- -8" is not allowed, but "-( -8 )" is.
OPERATORS
The allowed operators are like those found in the 'C' language in
addition to some others. Here are the allowed operators in order
of precedence:
, _ = <<= >>= &= ^= |=
+= -= *= /= %= **= || &&
| ^ & == != < > <=
>= << >> + - * / %
** ~ ! ++ -- ! -
The only operators not found in C are:
_ which means to print a number in that base. For
example, '13 _ 2' will print '1101', and '13 _ 16'
will print 'D'. The allowed output bases are 2
through 36, if another base is tried, base 10 is used.
This operator is equivalent to setting the variable
"obase". However, using this operator you can see the
value of the current expression as it evaluates.
** is the exponentiation operator. For example, '5 ** 3'
will print '125', '2 ** 3 ** 2' will print '512' because
this operaotr has precedence from right to left.
**= is the assign exponentiation operator. For example,
if the variable a has the value 5, 'a **= 3' will
assign the number 125 to the variable a.
! the factorial operator, 6! = 720, note that !6 is 0.
Here is a brief explanation of the other C operators. For a full
explanation of these operators, see a C programming text book.
, sequential expression, returns the result of the rightmost
expression
= assignment
<<= assign left shift, for example if a is 25, then "a <<= 2"
assigns the value 100 to the variable a. Shifting left
once is equivalent to multiplying by two, but bit shifting
is faster.
>>= assign right shift, for example is a is 25, then "a >>= 2"
assigns the value 6 to the variable a. Shifting right once
is equivalent to dividing by two. If a is an integer, this
operation is not reversible. However, for real numbers,
this operation is reversible, note that in C bit operators
only work for integer values.
&= assign bitwise AND
^= assign bitwise XOR
|= assign bitwise OR
+= assign sum
-= assign difference
*= assign product
/= assign quotient
%= assign remainder
|| logical or
&& logical and
| bitwise OR
^ bitwise XOR
& bitwise AND
== equal
!= not equal
< less than
> greater than
<= less or equal
>= greater or equal
<< left shift
>> right shift
+ addition
- subtraction
* multiplication
/ division
% remainder
~ bitwise negation
! logical negation
++ increment
-- decrement
- unary minus
NUMBERS
Numbers can also have an embedded '_' within them, unlike C, and
the presently allowed input bases are decimal (default), binary
(0b), octal (0), and hexidecimal (0x). However, by setting the
variable "ibase", a different base can be used. Note that
regardless of what number "ibase" is set to, binary, octal, and
hexidecimal numbers can still be entered.
Thus, if you type 'a = 0b1000', the number 8 will be assigned to
the variable a. Also, if the backslash ('\') character is found
in a number, the next character is read and skipped. Thus, '12\34'
is interpreted as '124'. This is useful for entering long numbers
that are several lines long. Thus, a long number can be entered
by typing digits, a backslash, a return, and more digits.
When numbers are printed, they are printed at 70 characters to a
line. You may change the variable "width" while running the program
to change the width.
Both integers and reals are supported and are stored internally
in binary. Thus, there will be some loss of precision for real
numbers that are not directly converted to binary.
OTHER FILES IN DISTRIBUTION
Along with this documentation and the CALC executable, are a set of
CALC programs which can be loaded either on the command line or via the
load() function after CALC begins. The list of all files are:
CALC.EXE - the calculator executable
CALC.DOC - this documentation
ABS.CLC - an example defining an abs() function
LOAN.CLC - an example using the print statements and loan()
GENERAL INFORMATION
calc also allows the use "/*" and "*/" as comment delimeters as
in C.
This program is not to be used in any way in another product to be
sold in a commercial envrionment without the written consent of
myself. You may make any number of backup copies and distribute
this program anywhere you want as long as no modifications
are made to the documentation or binaries.
If you find this program to be useful, send $10 to:
Timothy C. Frenz
5361 Amalfi Drive
Clay, NY 13041
If you have any suggestions for improvements such as other
functions to implement please send them to the above address. If
you find any errors, please send them to me also.
RELEASE HISTORY
Version Date and modifications
2.2 22-Jan-1991
Added more functions ( read, loan ), enhanced others with
error messages, and improved efficiency of several functions
( sqrt, ln, division, power ). Allowed variables to be any
length up to 512 characters, previous limit was 12. User
defined functions allow any number of arguments, previous
limit was 6.
2.1 26-Jul-1990
Added more extra functions ( lg, ln, log, sqrt ), and
added the functionality to raise a number to a real
exponent.
2.0 05-Apr-1990
Added while loops, for loops, if statements, and user
defined functions to the capabilities of this program.
Added better error detection and corresponding messages.
1.2 15-Feb-1990
Added some extra functions ( round, trunc, factorial, and
choose ), implemented REAL numbers converting all
necessary functions, and added other predefined variables.
1.1 02-Dec-1989
Added my own memory management functions to keep previously
used BIG_NUMs. Overall efficiency of mathematical operations
is improved.
1.0 23-Oct-1989
Initiall release of calc.
DIAGNOSTICS
If something is wrong with an expression an error message is
printed and a '^' is placed under (or close to under) where the
error occured. Here is a list of error messages that could occur:
unmatched ')'
unmatched '('
unmatched '}'
unmatched '{'
unmatched ']'
unmatched '['
operator not valid at this point
only one pre-unary operator allowed
only one post-unary operator allowed
operator expected - parentheses not valid here
operator expected - variable not valid here
operator expected - number not valid here
illegal operator entered
operand expected
operator only valid for variables
the comma operator must be an expression separator.
only X arguments allowed in a function definition
a semicolon is expected here
return is only valid in a function
break and continue are only valid in loops
LICENSE
Copyright (C) 1991 Timothy Frenz, Clay, New York.
Everyone is permitted to copy and distribute verbatim copies of
this software and its corresponding documentation and license,
but modifying it in any form for someone other than yourself
is not allowed.
COPYING POLICIES
1. You may copy and distribute verbatim copies of the CALC program
as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy a valid copyright notice
"Copyright (C) 1991 Timothy Frenz, Clay, New York"; keep intact the
notices on all files that refer to this License Agreement and to the
absence of any warranty; and give any other recipients of the CALC
program a copy of this License Agreement along with the program. You
may charge a distribution fee for the physical act of transferring a
copy, but not for the contents of the copy.
2. Mere aggregation of another unrelated program with this program
on a volume of a storage or distribution medium does not bring the
other program under the scope of these terms.
3. You may not copy, sublicense, distribute or transfer the CALC
program except as expressly provided under this License Agreement.
Any attempt otherwise to copy, sublicense, distribute or transfer the
CALC program is void and your rights to use the CALC program under this
License agreement shall be automatically terminated. However, parties
who have received computer software programs from you with this
License Agreement will not have their licenses terminated so long as
such parties remain in full compliance.
4. If you wish to incorporate parts of the CALC program into other
programs whose distribution conditions are different, write to me.
NO WARRANTY
THE CALC PROGRAM DESCRIBED HEREIN IS PROVIDED WITH ABSOLUTELY NO
WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
WHEN OTHERWISE STATED IN WRITING, THE CALC PROGRAM IS PROVIDED
"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE
RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
SHOULD THE CALC PROGAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL I BE LIABLE TO
YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES
OR A FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED
BY MYSELF) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.