ack/lang/m2/libm2/RealInOut.mod

75 lines
1.5 KiB
Modula-2
Raw 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
Version: $Header$
*)
1987-05-13 14:36:45 +00:00
IMPORT InOut;
1987-05-22 17:15:09 +00:00
IMPORT RealConversions;
1987-06-26 15:59:52 +00:00
IMPORT Traps;
1987-05-22 17:15:09 +00:00
FROM SYSTEM IMPORT WORD;
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);
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;
1987-10-19 10:06:24 +00:00
RealConversions.RealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
1987-05-13 14:36:45 +00:00
InOut.WriteString(buf);
END WriteReal;
1989-03-08 17:28:08 +00:00
PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL);
VAR buf: RBUF;
ok : BOOLEAN;
BEGIN
IF n > MAXWIDTH THEN n := MAXWIDTH END;
RealConversions.RealToString(arg, n, k, buf, ok);
InOut.WriteString(buf);
END WriteFixPt;
1987-05-13 14:36:45 +00:00
PROCEDURE ReadReal(VAR x: REAL);
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
InOut.ReadString(Buf);
1987-05-22 17:15:09 +00:00
RealConversions.StringToReal(Buf, x, ok);
1987-06-23 17:12:42 +00:00
IF NOT ok THEN
1987-06-26 15:59:52 +00:00
Traps.Message("real expected");
HALT;
1987-06-23 17:12:42 +00:00
END;
Done := TRUE;
1987-05-13 14:36:45 +00:00
END ReadReal;
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
InOut.WriteOct(CARDINAL(x[i]), 0);
InOut.WriteString(" ");
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;
BEGIN
Done := FALSE;
END RealInOut.