🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1684

Bug in Top Speed

#1684
From: T. Moore
Date: Wed, 09 Jan 1991 01:55
43 lines
1897 bytes
A Possible bug in Top Speed Modula 2

The Lib.Delay function takes a CARDINAL number as its argument.
If we declare
VAR x : SHORTCARD;
and assign
    x := 50;
then the call 
    Lib.Delay(CARDINAL(250 DIV x));
delays for 5 milliseconds.
But the call
    Lib.Delay(CARDINAL(300 DIV x));
delays for less than 6 milliseconds.
The call
    IO.WrCard(CARDINAL(300 DIV x));
will explain why.

In deciding whether to represent 250 as CARDINAL or SHORTCARD, the
decision is made on the basis that it will be combined with a SHORTCARD.
The value of 300 is forced to be SHORTCARD, presumably by deleting the
first byte. (Or perhaps the division algorithm does not check that the 300
is stored as a SHORTCARD.)

Should the compiler have produced a syntax error on trying to store 300
as SHORTCARD? (Or when trying to divide a CARDINAL by a SHORTCARD).

The correct call should be
    Lib.Delay(300 DIV CARDINAL(x));
But I still think the compiler should have told me.

What do other modula2 compilers do?


-- 

Terry Moore <T.Moore@massey.ac.nz>
 Department of Mathematics and Statisics,
 Massey University, Palmerston North, New Zealand

Kroneker:  "God made the natural numbers, the rest is the work of man."
Zermelo:   "But I can construct the natural from the empty set alone."
Bystander: "Who said 'You can't get something for nothing.'?"
Technical Details
Message-ID: <1991Jan9.015511.12475@massey.ac.nz>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!comp.vuw.ac.nz!cc-server4.massey.ac.nz!T.Moore

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!comp.vuw.ac.nz!cc-server4.massey.ac.nz!T.Moore
From: T.Moore@massey.ac.nz (T. Moore)
Newsgroups: comp.lang.modula2
Subject: Bug in Top Speed
Summary: 300 DIV SHORCARD does't work
Keywords: Typecasting, SHORTCARD, CARDINAL, numeric literals
Message-ID: <1991Jan9.015511.12475@massey.ac.nz>
Date: 9 Jan 91 01:55:11 GMT
Organization: Massey University, Palmerston North, New Zealand
Lines: 43
X-Reader: NETNEWS/PC Version 2.1