[Oberon] Texts.WriteInt
Paul Reed
paulreed at paddedcell.com
Fri Mar 28 19:45:16 CET 2014
Dear all,
>> IF ROR(x, 31) = 1 ...
...
> IF x = {31} ...
But x is not a SET, it's an INTEGER. And as some people have pointed out,
it's not really self-documenting, nor indeed is the ROR version in the
first place. In the following, I've attempted to establish the loop
invariant for the the edge case:
PROCEDURE WriteInt* (VAR W: Writer; x, n: LONGINT);
VAR i: INTEGER; x0: LONGINT;
a: ARRAY 10 OF CHAR;
BEGIN
IF x < 0 THEN DEC(n); x0 := -x ELSE x0 := x END;
IF x0 < 0 THEN a[0] := "8"; i := 1; x0 := 214748364 ELSE i := 0 END;
REPEAT
a[i] := CHR(x0 MOD 10 + 30H); x0 := x0 DIV 10; INC(i)
UNTIL x0 = 0;
WHILE n > i DO Write(W, " "); DEC(n) END;
IF x < 0 THEN Write(W, "-") END;
REPEAT DEC(i); Write(W, a[i]) UNTIL i = 0
END WriteInt;
Any advances on this? :)
Cheers,
Paul
More information about the Oberon
mailing list