[Oberon] RISC emulator and floating-point
Jan Verhoeven
jan at verhoeven272.nl
Wed Mar 26 01:22:34 CET 2014
Paul Onyschuk wrote:
> PROCEDURE WriteInt* (VAR W: Writer; x, n: LONGINT);
> VAR i: INTEGER; x0: LONGINT;
> a: ARRAY 10 OF CHAR;
> BEGIN i := 0;
> (* Taking this branch, since x = 80000000H = -2147483648 *)
> IF x < 0 THEN
> IF x = 0 THEN WriteString(W, " -2147483648")
This is a nonsense statement. If x < 0, it will never be equal to 0. The
second IF branch is never executed.
> REPEAT
> a[i] := CHR(x0 MOD 10 + 30H); x0 := x0 DIV 10; INC(i)
> (* Loop never terminates, since -1 DIV 10 = -1 and x0 is never 0 *)
> UNTIL x0 = 0;
Normally you would make sure the dividend is > 0. To do this, you make a
conditional like
IF x < 0 THEN sign := -1; x = -x ELSE sign := 1 END;
Do the normal conversion (which WILL terminate) and afterwards just do
q := q * sign
and you're done.
--
Groetjes
Jan Verhoeven
More information about the Oberon
mailing list