Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8096 → Rev 8097

/programs/develop/oberon07/Samples/Windows/Console/exp.ob07
0,0 → 1,117
(*
adapted to Oberon-07 by 0CodErr, KolibriOS team
*)
(* Print first 'PRINT' digits of 'e'.
*
* Originally written in Pascal by Scott Hemphill
* Rewritten in Modula-2 and modified by Andrew Cadach
*
*)
 
MODULE exp;
 
IMPORT In, Out, Console;
 
 
CONST
PRINT = 1024;
DIGITS = PRINT + (PRINT + 31) DIV 32;
 
 
TYPE
number = ARRAY DIGITS + 1 OF INTEGER;
 
 
VAR
s, x: number;
xs, i: INTEGER;
 
 
PROCEDURE init (VAR x: number; n: INTEGER);
VAR
i: INTEGER;
 
BEGIN
x[0] := n;
FOR i := 1 TO DIGITS DO x[i] := 0 END
END init;
 
 
PROCEDURE divide (VAR x: number; xs, n: INTEGER;
VAR y: number; VAR ys: INTEGER);
VAR
i, c: INTEGER;
 
BEGIN
c := 0;
FOR i := xs TO DIGITS DO
c := 10 * c + x[i];
y[i] := c DIV n;
c := c MOD n
END;
ys := xs;
WHILE (ys <= DIGITS) & (y[ys] = 0) DO INC(ys) END
END divide;
 
 
PROCEDURE add (VAR s, x: number; xs: INTEGER);
VAR
i, c: INTEGER;
BEGIN
c := 0;
FOR i := DIGITS TO xs BY -1 DO
c := c + s[i] + x[i];
IF c >= 10 THEN
s[i] := c - 10;
c := 1
ELSE
s[i] := c;
c := 0
END
END;
i := xs;
WHILE c # 0 DO
DEC(i);
c := c + s[i];
IF c >= 10 THEN
s[i] := c - 10;
c := 1
ELSE
s[i] := c;
c := 0
END
END
END add;
 
 
BEGIN
Console.open;
 
init(s, 0);
init(x, 1);
xs := 0;
add(s, x, xs);
i := 0;
REPEAT
INC(i);
divide(x, xs, i, x, xs);
add(s, x, xs);
UNTIL xs > DIGITS;
Out.Ln;
Out.String (" e = ");
Out.Char (CHR(s[0] + ORD("0")));
Out.Char (".");
FOR i := 1 TO PRINT DO
Out.Char (CHR(s[i] + ORD("0")));
IF i MOD 64 = 0 THEN
Out.Ln;
Out.Int (i, 5);
Out.String (" ")
END
END;
Out.Ln;
Out.Ln;
In.Ln;
 
Console.exit(TRUE)
END exp.