Product: Standard Apple Numerics Environment (SANE)

Use: Numeric Calculation

For: Apple II, III, Pascal

Company:Apple Computer Inc.

Includes: Documentation and disk

Availability: Apple Computer Dealers

Price: $35

*By J.B. KoonsCall-A.P.P.L.E. Magazine July 1985 PP19-20*

MORE and more often now we hear that the day of the lowly 8 bit microprocessor, such as the 6502 that sits at the heart of all Apple II and Apple III computers, is over. If you want to do real work you need a machine with one of the new 16 or 32 bit wonder chips. Well, don’t you believe it!

With the right software, the Apple II and III can still perform like the troopers they are. And Apple has a new software utility that proves the point once again. It’s called Standard Apple Numerics Environment (SANE). Hence the bad pun in the title. If you need to do high precision math then you need this package. The package reviewed here runs under the Apple II and Apple III Pascal Systems and is provided as a set of three units for use with Pascal programs. Several other versions are also available. These include a version for use with 6502 assembly language, running under the ProDOS operating system, and versions for use on the Macintosh and Lisa computers.

SANE implements the IEEE Standard 754 for Binary Floating Point Arithmetic. The requirements for this standard and thus for SANE, are truly outstanding: the Extended Arithmetic type provides in excess of 19 decimal digits in the mantissa and a range from 10^-4932 to 10^4932.

According to the documentation, this package supports all the features of the draft standard with the exception of rounding precision. The package is said to have been completely validated by test procedures developed by members of the Standards Committee.

There are four data types which may be used by an application. These are Single, Double, Extended and Camp. Single, Double, and Extended are data types defined in the proposed standard while Camp is an additional type defined by the SANE package. Camp values are integer variables of up to 19 decimal digits. (63 bits). Regardless of the storage type used by an application all calculations are performed using the extended type to retain maximum possible accuracy. Extended data values use a 64 bit mantissa and a 16 bit exponent.

Most work will probably be done using single or double precision types. These types require less storage than the extended type and their use allows for guard bits in the actual calculations performed with the extended type.

The double precision routines allow in excess of 15 decimal digits (53 bits) in the mantissa and a decimal exponent range of + /-308. All operations are performed by means of procedure calls. For instance, to solve for the hypotenuse of a right triangle the following program segment might be used. Assume that X, Y and H are double precision and that the two temporaries, Tl and T2 are Extended types.

This is considerably less convenient than standard infix notation. However, when the high precision provided by this package is required, use of separate procedure calls to evaluate an expression is still much simpler than writing your own floating point math routines!

To gain some idea of the speed of SANE in comparison to standard Pascal and Basic arithmetic, I performed timing tests on some simple calculations. Each calculation was performed separately in a loop. The time to run an empty loop was then subtracted from this total and the resulting time was divided by the loop count to obtain a time per calculation value.

D2X(X, T1); D2X(y, T2); XPWRI(2, T1); XPWRI(2, T2); ADDX(T1, T2); SQRT(T2); X2D(T2, H); | { convert X to extended T1 } { convert Y to extended T2 } { square T1 } { square T2 } { T2 < — T1 + T2 (X^2 + Y^2) } { T2 < — SQRT(T2) SQRT(X^2 + Y^2) } { store answer in H } |

The results of these tests are shown in Table 1. The tests were timed by hand using a watch with a sweep second hand. The intent is to provide a gauge of relative times for the various computations and languages, rather than specific figures that can be taken as gospel. In comparing these figures, remember that BASIC calculates to 9 digits, and standard Pascal to 6 digits while all computations are carried to 19 digits in SANE.

Separate SANE units are provided for the II and III computers. These units include procedures for addition, subtraction, multiplication, division, square root, comparison <, > =, =, etc.), remainder or modulo, negation, absolute value and rounding of values.

A full set of routines for converting from external fixed or floating point formats to internal binary form and back is also provided. Especially note-worthy in this regard is the fact that you can enter input values and receive results directly in scientific notation. For instance the distance of the earth from the sun, 93 million miles, could be entered as 93E6.

The third unit, the Elems unit, provides a set of procedures for evaluating trigonometric and other functions with high precision. The Elems unit requires the presence of the appropriate SANE unit. The functions provided include log (bases 2 and e), 1n(1 + x), 2^x, e^x, e^x-1, x^y, sin(x), cos(x), tan(x), and arctan(x). Procedures for working with compound interest and annuities and a random number generator are also included.

When using these units on an Apple II 64K system, they must be installed in the SYSTEM. LIBRARY and the library must be online in the boot drive. If you have an Apple IIc, or a lie with an extended 30-column card, the units can be placed, instead, in a Program Library File for use with the 128K Pascal system. In either case, these are large units. If the units are placed in the SYSTEM.LIBRARY, you may find it useful to create a version of the SYSTEM. LIBRARY that contains only these units and any others which are required by a given application. A library that contains only the SANE and Elems units requires 60 blocks of disk space.

*Table 1: Relative Speeds of Computation*

```
Test Sane BASIC Pascal
A*B 14 5 3
C*D 19 --- ---
SIN(PI/6) 217 26 31
EXP(6) 256 26 32
ATAN(.5) 327 40 98
H=SQRT(A^Z + B^Z) 149 138 45
```

All times are in milliseconds. In comparing measurements remember that SANE calculates to 19 digits. BASIC to 9 and Pascal to 6.

```
A = 123456789E10 B = 987654321E5
C = 123456789E2000 D = 987654321E2000
```

This package is well designed and produced. If you need the functions it provides, it should return big dividends for a small investment. While the use of individual procedure calls is not as convenient as standard infix notation, it is now possible to work to a much higher precision than has ever been possible before on microcomputer.

The SANE package is provided on a single disk that is not copy protected. As we have come to expect from Apple Computer Inc., the documentation is complete and detailed; 90-7×9 inch pages punched for insertion in a special Apple Workbench three-ring binder. The spacing of the holes does not match that of the standard 8.5×11″ format. If your dealer does not have the Workbench binders in stock, a binder designed for 6×9 inch material makes a workable, if less perfect. substitute. When this smaller binder is closed, the manual page projects beyond the binding about a half an inch. SANE is available for $35. from Apple dealers.

A version of this review has previously appeared in Access, a publication of LEDS Publishing Co.