# String arithmetic functions

The string arithmetic functions and pre-compiler are the last
method of using AccuMath in your applications. These functions are
compatible with the Ultimate string math functions. Using the
pre-compiler, source code compatibility with programs using
Ultimate's string arithmetic functions can be maintained.

Only SADD(),
SSUB(),
SMUL(),
SDIV()
and SCMP()
are defined as string arithmetic functions. These functions will
accept either two or three arguments. The first two arguments are
the two operands supplied to the function. The third, optional
operand, is an explicit precision for the function. These functions
behave exactly like the explicit precision subroutines (if the
third argument is missing, the default precision is used).

If the other AccuMath functions are required, call the explicit
precision mode BASIC subroutines.

For compatibility with Ultimate string arithmetic, use only two
arguments in the string arithmetic functions. The third argument,
allowing the specification of function precision, is an extension
added to AccuMath.

## Pre-compiler

When using the string arithmetic functions, it is necessary to
compile your programs using the AccuMath pre-compiler: XP-BASIC.
The pre-compiler translates the string arithmetic functions into
OCONV()
functions. It then calls the BASIC compiler to compile the
program.

When using the pre-compiler, it is necessary to include the
following statement in your program:

```
INCLUDE XP XPA.DEFS
```
If a program INCLUDEs
a program fragment which contains string arithmetic functions, they
will not be converted by the pre-compiler, and will not compile
properly. In this case, the pre-compiler may be used to translate
the INCLUDEd
program fragment and update the source code with the translated
version. To do this, copy the original source program fragment to
another file (since the source code will be updated). Next, execute
the XP-PRECOMP
verb with the (O)
option to update the source code. Now when you compile the main
program, the INCLUDEd
program fragment will have been translated by XP-PRECOMP,
and the program will compile successfully.

The syntax for the XP-BASIC
and XP-PRECOMP
verbs is exactly the same as the BASIC verb.

Note: for Open Architecture only, XP-BASIC
and XP-PREBASIC
are case insensitive, and XP-COMPILE
and XP-PRECOMP
are case sensitive.

The following sections describe the string arithmetic functions
in more detail.

## Addition

Two arguments may be added together using the SADD
function. If the third argument is omitted, the precision of the
result will be the greater of the precision of either of the
arguments. If the third argument is specified, the result will be
rounded to the specified precision.

```
RESULT = SADD(ARG1,ARG2)
RESULT = SADD(ARG1,ARG2,PRECISION)
```

## Subtraction

The difference between two arguments (ARG1 -
ARG2) may be computed using the SSUB
function. If the third argument is omitted, the precision of the
result will be the greater of the precision of either of the
arguments. If the third argument is specified, the result will be
rounded to the specified precision.

```
RESULT = SSUB(ARG1,ARG2)
RESULT = SSUB(ARG1,ARG2,PRECISION)
```

## Multiplication

The product of two arguments may be computed using the
SMUL
function. If the third argument is omitted, the precision of the
result will be sum of the precision of each of the arguments. For
example, if ARG1=1.25 (precision=2) and ARG2=0.375
(precision=3), then RESULT=0.46875
(precision=5). If the third argument is specified, the product will
be rounded to the specified precision.

```
RESULT = SMUL(ARG1,ARG2)
RESULT = SMUL(ARG1,ARG2,PRECISION)
```

## Division

The quotient of two arguments (ARG1 /
ARG2) may be computed using the SDIV
function. If the third argument is omitted, the precision of the
result will be the default precision (standard default is 14). If
the third argument is specified, the result will be rounded to the
specified precision.

```
RESULT = SDIV(ARG1,ARG2)
RESULT = SDIV(ARG1,ARG2,PRECISION)
```

## Comparison

Two arguments may be compared, and the results (lower, equal,
higher) determined. If the first argument is less than the second
argument then -1 is returned. If the first argument is greater than
the second argument then 1 is returned. If the first argument is
equal to the second argument then 0 is returned. A third argument,
if specified, is ignored.

```
RESULT = SCMP(ARG1,ARG2)
RESULT = SCMP(ARG1,ARG2,PRECISION)
```

## Calculator

The AccuMath package contains two algebraic calculator programs.
These may be used to aid in developing programs utilizing the
AccuMath subroutines, testing formulas, and for general use. One of
the calculators (ALG) uses the implicit precision mode, the other
(ALGX)
uses the explicit precision mode.

To use the calculator program, type ALG
or ALGX
at TCL. If you run ALGX,
the program will prompt:

```
Maximum precision for calculations (RETURN for default)?
```
Enter any valid precision (4-50), or press RETURN to use the
default precision (standard default precision is 14).

Next, either ALG
or ALGX
will prompt:

```
Enter Expression:
```
At this prompt, you can enter any valid expression in standard
algebraic notation. The syntax is similar to BASIC, except that the
only operands allowed are numbers or references to the calculator's
memory elements.

If a valid expression was entered, the calculator will print the
result:

```
1>  result
```
 After the result is printed, the calculator will again
prompt for an expression.

As each result is displayed, a memory element number is printed
before it. The result may be used as an operand in another
expression by preceding the memory element number by a percent
sign. For example, consider the following sequence:

```
Enter Expression: SIN(23)
  1>  0.39073112848927
 
Enter Expression: COS(23)
  2>  0.92050485345244
 
Enter Expression: (%1)^2 + (%2)^2
  3>  1
 
Enter Expression: 2*(1.34563421349784/.20145265)^3
  4>  596.06291722886108
 
Enter Expression: 100000^1.1875/(5*.140328642283449)
  5>  1234194.68651440253212
 
Enter Expression: LN(1.12)
  6>  0.113328685307
 
Enter Expression: 500000/(1+0.0675)^5
  7>  360687.07992475241642
```

---
Source: https://d3codex.com/accumath/string-arithmetic-functions/ - part of the D3Codex reference.
