Calculator Library

Version 5.0.0

The calculator library evaluates CHARACTER strings containing FORTRAN-like expressions and returns numeric and string values.

The primary routine JUCALC acts like a powerful desk-top calculator. It supports named variables and has several arrays of 55555 elements each. Many standard FORTRAN functions are available, plus access to user-written functions is permitted via the user-supplied routine JUOWN1().

Using this interface it is easy to make free-format and order-independent input interfaces where values can be expressions and variable names instead of simple formatted numbers.

The programmer (generally) uses just the JUCALC routine or several convenience routines (INUM0, RNUM0, SNUM0, STRGAR2, JUCALCX) that simplify making the most common type of calls to JUCALC.

The library is written in FORTRAN.

The calculator library is composed of the following routines:

A summary of the syntax rules for the expressions follows:

Names must be 1 to 20 characters long, and are case-sensitive. Up to 2345 names are permitted. Numeric variable names should be composed of the letters a-z and underscores and numbers. String variables are similar but start with a dollar sign($). Names must not end in a "digit-E" combination. For example:
   $name="Thomas Jefferson"
Variables may be defined by equating them to an expression. To define or redefine a variable called FRED, simply enter:
     > FRED=300*4/500
The last value assigned to a variable will be used to evaluate the expression on the left of the equals sign when this expression redefines the variable. For example:
     > A=2
     > A
     > A=A+A
     > A=A+A
To allow FORTRAN-type E-format numeric entry and yet not cause the calculator routine to do an excessive amount of checking, a variable name ending in the letter E must not have a digit (012345789) in front of that ending E. Attempting to define such a variable name will produce an error. This limitation prevents the calculator from becoming confused by whether 12E+3 is a variable called 12E plus 3 or the exponential number 12E3=12000.

The variable name '?' is automatically set by the program to contain the last calculated value. This current-value register may be used like any variable or number. It is 0 at program initialization. Example:
       > (300+500)
       > (1/4)*?
       > ?+?

Two arrays called X and Y are available that can contain up to 55555 values each. The arrays are originally initialized to all zeros. To set values in the arrays, use the xstore (or ystore) command. The format of the commands is
where start=array address to start storing at and ex(i) are expressions.

The current value is assigned the last value stored.

In addition there are similar string arrays and functions that can hold up to 50 255-character strings:

For example, to store into the locations 10,11,and 12 the values 1/10,2/10, and 3/10, the following could be entered:

     xstore( 10 , 1/10 , 2/20 , 3/10 )
             *-------Start storing evaluated expressions sequentially,
                     beginning at x(10).

The values stored into the arrays may be referenced by subscript. For example:
   > xstore(1,10,20,30)
   > fred=x(1)+x(2)+x(3)
  1. x and y array values cannot be used on the left of equal signs.
          x(10)=5   #  IS ILLEGAL 
  2. The current value is set to the value of the last expression by the xstore and ystore commands


conversion functions

logical functions

For example:
means return a if b is greater than or equal to c else return d.

lexical logical functions

miscellaneous functions



Random numbers

If ITYPE is present different algorithms are used. The system routines vary from platform to platform. The preferred algorithm is the "Numerical Recipes" algorithm. The ITYPE must agree between the SRAND() call and the RAND() call. A call to SRAND() should precede use of RAND().

ITYPE meanings

  1. The system C routine rand()
  2. The Fortran intrinsic RANDOM_NUMBER()
  3. The algorithm purchased from Numerical Recipes
    This routine (RAN_MOD()), is a modified version of routine RAN1() from the book "Numerical Recipes in FORTRAN" (Cambridge University Press), Copyright (C) 1986, 1992 by Numerical Recipes Software. Used by permission. Use of this routine other than as an integral part of BELOCA-related programs requires an additional license from Numerical Recipes Software. Further distribution in any form is prohibited.
    RAN_MOD() is a "MINIMUM" random number generator of Park and Miller with Bays-Durham shuffle and added safeguards. It returns uniform random deviates between 0.0 and 1.0 (exclusive of the endpoint values). Do not alter the seed between successive deviates in a sequence.


FORTRAN Functions
abs acos aint anint asin
atan atan2 cos cosh dim
exp frac hypot int log
log10 max min mod nint
real sign sin sinh sqrt
tan tanh tan tanh tan asinh acosh atanh tan

A full description of the ANSI FORTRAN Functions is available in The ANSI FORTRAN function supplement .

Displaying variable values: dump
The current value and all defined variable names are displayed via the dump command.
Listing Available Functions: funcs
A display of all available functions can be obtained when executing JUCALC by entering the command 'funcs'. No descriptions are provided.

Changes regarding variable names ending in letter E. Previously variable names could not safely end in the letter E. The previous version of the calculator would be confused by whether 12E+3 is a variable called 12E plus 3 or the exponential number 12E3=12000).If all occurrences of the variable name are placed in brackets, this limitation could be ignored; but typographical errors would be harder to diagnose. With this understanding, the following was acceptable:
       > 12E=10
       > FRED=(12E)+3
This restriction no longer applies

Placed calculator on UNICOS (Already on VMS,NOS,NOS/VE,COS,and several UNIX boxes).

Use at your own risk.
See the LIBRARY homepage for related information.