1988-02-19 15:54:01 +00:00
|
|
|
(*
|
|
|
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*)
|
|
|
|
|
1987-08-19 18:07:01 +00:00
|
|
|
(*$R-*)
|
1987-05-13 14:36:45 +00:00
|
|
|
IMPLEMENTATION MODULE RealInOut;
|
1988-02-19 15:54:01 +00:00
|
|
|
(*
|
|
|
|
Module: InOut for REAL numbers
|
|
|
|
Author: Ceriel J.H. Jacobs
|
|
|
|
Version: $Header$
|
|
|
|
*)
|
1987-05-13 14:36:45 +00:00
|
|
|
|
1991-03-05 13:47:08 +00:00
|
|
|
FROM InOut IMPORT ReadString, WriteString, WriteOct;
|
|
|
|
FROM Traps IMPORT Message;
|
|
|
|
FROM SYSTEM IMPORT WORD;
|
|
|
|
FROM RealConversions IMPORT
|
|
|
|
LongRealToString, StringToLongReal;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
1987-05-22 17:15:09 +00:00
|
|
|
CONST MAXNDIG = 32;
|
|
|
|
MAXWIDTH = MAXNDIG+7;
|
|
|
|
TYPE RBUF = ARRAY [0..MAXWIDTH+1] OF CHAR;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
|
|
|
PROCEDURE WriteReal(arg: REAL; ndigits: CARDINAL);
|
1989-06-20 11:23:43 +00:00
|
|
|
BEGIN
|
|
|
|
WriteLongReal(LONG(arg), ndigits)
|
|
|
|
END WriteReal;
|
|
|
|
|
|
|
|
PROCEDURE WriteLongReal(arg: LONGREAL; ndigits: CARDINAL);
|
1987-05-22 17:15:09 +00:00
|
|
|
VAR buf : RBUF;
|
|
|
|
ok : BOOLEAN;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
|
|
|
BEGIN
|
1987-05-22 17:15:09 +00:00
|
|
|
IF ndigits > MAXWIDTH THEN ndigits := MAXWIDTH; END;
|
|
|
|
IF ndigits < 10 THEN ndigits := 10; END;
|
1991-03-05 13:47:08 +00:00
|
|
|
LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
|
|
|
|
WriteString(buf);
|
1989-06-20 11:23:43 +00:00
|
|
|
END WriteLongReal;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
1989-03-08 17:28:08 +00:00
|
|
|
PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL);
|
1989-06-20 11:23:43 +00:00
|
|
|
BEGIN
|
|
|
|
WriteLongFixPt(LONG(arg), n, k)
|
|
|
|
END WriteFixPt;
|
|
|
|
|
|
|
|
PROCEDURE WriteLongFixPt(arg: LONGREAL; n, k: CARDINAL);
|
1989-03-08 17:28:08 +00:00
|
|
|
VAR buf: RBUF;
|
|
|
|
ok : BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF n > MAXWIDTH THEN n := MAXWIDTH END;
|
1991-03-05 13:47:08 +00:00
|
|
|
LongRealToString(arg, n, k, buf, ok);
|
|
|
|
WriteString(buf);
|
1989-06-20 11:23:43 +00:00
|
|
|
END WriteLongFixPt;
|
1989-03-08 17:28:08 +00:00
|
|
|
|
1987-05-13 14:36:45 +00:00
|
|
|
PROCEDURE ReadReal(VAR x: REAL);
|
1989-06-20 11:23:43 +00:00
|
|
|
VAR x1: LONGREAL;
|
|
|
|
BEGIN
|
|
|
|
ReadLongReal(x1);
|
|
|
|
x := x1
|
|
|
|
END ReadReal;
|
|
|
|
|
|
|
|
PROCEDURE ReadLongReal(VAR x: LONGREAL);
|
1987-05-22 17:15:09 +00:00
|
|
|
VAR Buf: ARRAY[0..512] OF CHAR;
|
|
|
|
ok: BOOLEAN;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
|
|
|
BEGIN
|
1991-03-05 13:47:08 +00:00
|
|
|
ReadString(Buf);
|
|
|
|
StringToLongReal(Buf, x, ok);
|
1987-06-23 17:12:42 +00:00
|
|
|
IF NOT ok THEN
|
1991-03-05 13:47:08 +00:00
|
|
|
Message("real expected");
|
1987-06-26 15:59:52 +00:00
|
|
|
HALT;
|
1987-06-23 17:12:42 +00:00
|
|
|
END;
|
|
|
|
Done := TRUE;
|
1989-06-20 11:23:43 +00:00
|
|
|
END ReadLongReal;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
1987-05-22 17:15:09 +00:00
|
|
|
PROCEDURE wroct(x: ARRAY OF WORD);
|
|
|
|
VAR i: CARDINAL;
|
|
|
|
BEGIN
|
|
|
|
FOR i := 0 TO HIGH(x) DO
|
1991-03-05 13:47:08 +00:00
|
|
|
WriteOct(CARDINAL(x[i]), 0);
|
|
|
|
WriteString(" ");
|
1987-05-22 17:15:09 +00:00
|
|
|
END;
|
|
|
|
END wroct;
|
|
|
|
|
1987-05-13 14:36:45 +00:00
|
|
|
PROCEDURE WriteRealOct(x: REAL);
|
|
|
|
BEGIN
|
1987-05-22 17:15:09 +00:00
|
|
|
wroct(x);
|
1987-05-13 14:36:45 +00:00
|
|
|
END WriteRealOct;
|
|
|
|
|
1989-06-20 11:23:43 +00:00
|
|
|
PROCEDURE WriteLongRealOct(x: LONGREAL);
|
|
|
|
BEGIN
|
|
|
|
wroct(x);
|
|
|
|
END WriteLongRealOct;
|
|
|
|
|
1987-05-13 14:36:45 +00:00
|
|
|
BEGIN
|
|
|
|
Done := FALSE;
|
|
|
|
END RealInOut.
|