dot1985e-large-numbers
dot1985e-large-numbers
and
Normally BBC BASIC can only cope with integers in
the range ±(231-1). The command A%+A%= -2.
A%=2j31-1
The difference arises from an error in the BASIC
gives an integer variable its maximum value whilst
interpreter. Integer arithmetic is used wherever
A%=2j31 possible, and the interpreter switches to floating-point
routines when integers become inappropriate. The
produces the error message 'Too big'. computation 2*A% clearly exceeds the maximum
The technical reason for this is that integers are integer size and is performed in floating-point
'
stored internally in four memory locations, each of arithmetic. But A%+ A% is erroneously carried out as
' which can hold an eight-digit binary number. The an integer calculation, with the sum of two thirty-one
number of binary digits available is therefore thirty- digit binary numbers producing an error in the thirty
48
two. One of them is used to represent the sign. Thus the second place. This sets the minus sign, but fails to
To load the procedures into your computer, type reveals the true value of2 i 31- 1.
turns the computer into a simple large-number with the obvious bonus that the result of A$ is stored in
calculator that also prints the time taken for each memory, should it be required again.
operation. For instance, the value of 2200 will be A number of useful procedures for factorizing large
printed as numbers are included in the program. One of these is for
the highest common factor of two large integers and has
160693804425899027554196209234116260 exactly the same form as THE BASIC procedure which
2522202993782792835301376 can be written to find the highest common factor of two
integers of normal size.
in just 0 .15 seconds
DEF FNgcd(X%,Y%) : IFX%=0 THEN=Y%
Investigations confirm that the longer the strings are, ELSE=FNgcd(Y%M ODX%,Y%)
the longer it takes, and addition and subtraction are
much faster than the other operations. gives the highest common factor (or greatest common
Playing with vast numbers may soon pall, as divisor) of the two integers, X% and Y%, of normal size.
meaningless strings of large digits are flashed up before Typing
your eyes, though you may get some perverse pleasure
from causing calculation overflow even with these large PRINT FNgcd(3108 ,4095 ) 49