                         EFORM



          A useful routine for the mathematical

          dabbler provided by David Roberts of

                        London.



The following BASIC subroutine allows the user to PRINT any

numeric variable or constant in E format as opposed to

leaving it to the discretion of the ROM. Also, a variable

number of significant figures is available and rounded up

where necessary. The principal advantage of this utility is

knowing, a priori, how much space a number will take in the

display.

   The subroutine can be used without any acquaintance with

the principles involved. The value to be PRINTed is placed

in a reserved variable which has been called 'a'. For

example, if we want to print x, y, z(3) and so on we simply

LET a=x, y, z(3) and so on. The number of significant

figures required is defined by n, either permanently at the

beginning of a program or as a temporary value just prior

to calling the subroutine. The PRINT position is expected

to have been set by the calling routine; the first position

being a space for positive numbers and, would you believe,

a minus sign for negative numbers. A GO SUB EFORM (EFORM,

of course, being defined at an earlier stage) completes the

operation.

   The value of n may be an integer in the range 2 to 8

with a default value of 6 in the event of a typing error -

I don't like the term idiot proofing because of the dispro-

portionate use I make of the safeguards provided in other

people's programs!

   Rigorous tests have not been carried out on the speed of

the subroutine since it will vary from program to program

but the following test program PRINTed numbers about 10

times slower than the ROM. This may sound an eternity but

scientific users should find it tolerable. EFORM can easily

be converted to work on a ZX81 but it was found intolerable

in SLOW mode. Users crunching numbers on a ZX81 will pro-

bably have the machine working in FAST mode anyway. The

PRINTing of the exponent differs to the Sinclair represen-

tation. The following examples illustrate the differences.



Sinclair      EFORM

E+9           E+09

E-9           E-09



and with E 00 PRINTed for a zero exponent. This is purely

cosmetic and can easily be altered if required.

   Those who may be interested in how EFORM works would be

best advised to work through some examples by hand. How-

ever, line 1040 requires a little explanation. After calcu-

lating the exponent b and mantissa c, provided that c is

not an integer, from a PRINTing point of view the conver-

sion of c into a string is not necessary remembering that

the machine accuracy is greater than 9 significant figures

decimal, but less than 10 and the PRINT accuracy is 8

rounded. The calculation of b may fail because of machine

accuracy but this creates a complimentary situation in

calculating c and so requires no additional work. Gene-

rally, we would need the services of INT and VAL but since,

in theory, 1<=c<10 we can simplify the checking by using

LEN. In practice c may take the values 1 and 10, and

integers in between, hence line 1040.

   Inevitably, the number to be PRINTed is corrupted simply

by examining it but this corruption is in the 9th signifi-

cant figure. Rounding to 8 significant figures will then be

suspect, if not already by virtue of whatever number crun-

ching is involved prior to calling EFORM.

   Readers who would prefer a faster routine may like to

adapt a little routine in the ROM starting at address 2DE3

which Ian Logan calls PRINT_FP. I've allocated the next

bank holiday weekend for this task (tongue firmly in

cheek).