ack/lang/m2/libm2/RealInOut.mod

98 lines
2 KiB
Modula-2
Raw Permalink Normal View History

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
1994-06-24 14:02:31 +00:00
Version: $Id$
1988-02-19 15:54:01 +00:00
*)
1987-05-13 14:36:45 +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);
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;
LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
WriteString(buf);
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);
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;
LongRealToString(arg, n, k, buf, ok);
WriteString(buf);
END WriteLongFixPt;
1989-03-08 17:28:08 +00:00
1987-05-13 14:36:45 +00:00
PROCEDURE ReadReal(VAR x: REAL);
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
ReadString(Buf);
StringToLongReal(Buf, x, ok);
1987-06-23 17:12:42 +00:00
IF NOT ok THEN
Message("real expected");
1987-06-26 15:59:52 +00:00
HALT;
1987-06-23 17:12:42 +00:00
END;
Done := TRUE;
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
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;
PROCEDURE WriteLongRealOct(x: LONGREAL);
BEGIN
wroct(x);
END WriteLongRealOct;
1987-05-13 14:36:45 +00:00
BEGIN
Done := FALSE;
END RealInOut.