François Van Emelen writes:

> > It is not too difficult to write your own fixed
> > or floating point routines in Basic using basic school maths, but they
would
> > be relatively slow. (The book "Mathematics on the Sinclair QL", by Czes
> > Kosniowski (out of print) might provide a suitable starting point.)
>
> I doubt I could do that myself.

Monetary calculations normally only require the four basic operations, add,
subtract, multiply and divide. These are really not too difficult to
implement using basic arithmetic. (Divide could be a bit tricky, though.)
Heres a silly example I knocked together in a few minutes just to
demonstrate. (Input validation, output formatting and, more challengingly,
the remaining three operations are left as an excercise for the determined
reader.)

100 DEFine FuNction Add$(n1$, n2$)
110 LOCal i%, c%, r%, m$, n$, r$
120 IF LEN(n1$) > LEN(n2$) THEN
130  m$ = n1$: n$ = FILL$("0", LEN(n1$) - LEN(n2$)) & n2$
140 ELSE
150  m$ = n2$: n$ = FILL$("0", LEN(n2$) - LEN(n1$)) & n1$
160 END IF
170 c% = 0: r$ = ''
180 FOR i% = LEN(m$) TO 1 STEP -1
190  r% = c% + m$(i%) + n$(i%)
200  IF r% > 9 THEN
210   r% = r% - 10: c% = 1
220  ELSE
230   c% = 0
240  END IF
250  r$ = r% & r$
260 END FOR i%
270 IF c% = 1: RETurn c% & r$
280 RETurn r$
290 END DEFine
300 :

This will add two integers of "any" size, entered as strings, digit by
digit. On my Athlon 1700 PC, using QPC2v3/SMSQ2.99, it will do
about a thousand 20-digit additions per second.

<>
> > you cant change the world, change yourself!" might usefully be applied
> > to the problem.
> Or in this situation; if more serious work is involved, avoid Qdos/Smsq
> ;-)

No, no. Dyed-in-the-wool QLers should stick with it and always plump for
the change-the-world option instead.

Per


Reply via email to