The Brick Wall In Your Computer, Part II

Authors

Publication

Pub Details

Date

Pages

BASIC Terms

See all articles from SINCUS v4 n1

Last time we found that every BASIC for every computer contains a “BRICK WALL” that can prevent the computer from doing what you want. Since the wall is different for every computer, we concentrated on the TS1000 and we found a couple of places where we could “smash into it”. As mentioned last time, I don’t consider this a “bug”, since it absolutely must exist in some form. If there is a lot of available memory (and a lot of clever programmers to write the BASIC interpreter) the wall might be very hard to find, but it’s in there somewhere!

To try to understand the wall, let’s look at one of the problems presented last month. If we ENTER the following into a TS1000:

1 LET A = 1
2 LET B = A
3 LET B = B/3
4 LET B = B*3
5 IF A = B THEN PRINT "EQUAL"
6 IF A<>B THEN PRINT "NOT EQUAL"

and RUN the progam, we get a surprising result. At the end, A=1 and B=1, so we should get “EQUAL” as answer. Instead we get “NOT EQUAL”. Curious. If we change the order of lines 3 and 4, which shouldn’t change the answer, we get “EQUAL” as an answer. Curiouser and curiouser. If, instead of changing lines 3 and 4, we transpose the A and B in line 5 (i.e. IF B=A THEN PRINT “EQUAL”), we will get BOTH “EQUAL” and “NOT EQUAL”!!!??

Rather than get involved in binary numbers right now, let’s imagine a computer that really works in decimal. Now it’s possible to specify a number that contains an infinite number of digits. Alas, we can’t build a memory large enough to contain such a number, even with memory as cheap as it is these days. What we need to do is work out a scheme that let’s us store numbers that can be pretty large or pretty small, and hope that we never need to exceed the limit. We might do it with the following format:

EXPONET     MANTISSA
XX XXXX

The mantissa is a fraction with four decimal places. The exponent is a number that tells us how far to move the decimal point to the left or right. For example:

 02   .1000 = 10
51 .1000 = 1 (with 50 zeroes)
00 .3720 = .372
-02 .1200 = .0012
05 .5432 = 54,321

Get the idea? Note that in the last case there aren’t enough digits to exactly represent the number. As such 54321 and 54320 would be the same to the computer. This is the foundation of the “BRICK WALL”.

Now if we walk things through the program that gives us funny answers, we get in lines 1 and 2:

A=B= 01 .1000  =1

In line 3 we divide 1 by 3. However, 1/3 = .3333333… where the 3’s go on forever. The computer shortens this to

00  .3333 = .3333

In line 4, we multiply this by 3 to get 00 .9999 = .9999. Note that .9999 is “NOT EQUAL” to 1, even though they’re very close! Therefore, the computer prints “NOT EQUAL”.

Now let’s try the second case, where we change the order of lines 3 and 4. In line 3, we multiply by 3, where

3 x 1 = 3 = 01 .3000

In line 4 we divide by 3, to get 01 .1000 = 1. The result is still 1, so we get “EQUAL” as an answer. Although the TS1000 does these contortions in binary and there are many more digits in a number, the same problems occurs.

The “BRICK WALL” is revealed!

Could the BASIC interpreter have been rewritten so that the “EQUALS” test would pass if the number were merely “ALMOST EQUAL”? The answer is “Yes”, in fact, some BASICS operate in this manner. It’s possible for this reason that the TS2068 always gives “EQUAL” as an answer to this program. However, this can also have it’s problems, since there could be cases where it would falsely call two numbers equal, when they really should not be. The “BRICK WALL” is still there; it’s just moved to a different place!

We still haven’t discussed the case where both “EQUAL” and “NOT EQUAL” appear together. Did I say that the TS1000 NEVER passes the “EQUALS” test when the numbers are almost equal?

(No, I didn’t, look again.) Apparently, “ALMOST EQUAL” might be good enough, depending on the order of the numbers being tested. If this seems unreasonable, then I’ll have to concede this is more of a “bug” than a “BRICK WALL” problem. Nevertheless, it’s a great bug. It’s somewhat amusing to be able to show two numbers to be equal and not equal at the same time. If there are some kids in your neighborhood who are “too smart” with computers, show that problem to them. It’ll put them in their place.

For space reasons, we’ll have to cover the FOR loop problem next time, although there’s enough information for the reader to figure it out if they haven’t already done so. Also, having thoroughly disgraced the TS1000 here, we’ll continue to pick on the TS2068.

Image Gallery

Source Code

Scroll to Top