source: trunk/minix/lib/ack/libm2/RealInOut.mod@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.1 KB
Line 
1(*
2 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 See the copyright notice in the ACK home directory, in the file "Copyright".
4*)
5
6(*$R-*)
7IMPLEMENTATION MODULE RealInOut;
8(*
9 Module: InOut for REAL numbers
10 Author: Ceriel J.H. Jacobs
11 Version: $Header: /cvsup/minix/src/lib/ack/libm2/RealInOut.mod,v 1.1 2005/10/10 15:27:46 beng Exp $
12*)
13
14 FROM InOut IMPORT ReadString, WriteString, WriteOct;
15 FROM Traps IMPORT Message;
16 FROM SYSTEM IMPORT WORD;
17 FROM RealConversions IMPORT
18 LongRealToString, StringToLongReal;
19
20 CONST MAXNDIG = 32;
21 MAXWIDTH = MAXNDIG+7;
22 TYPE RBUF = ARRAY [0..MAXWIDTH+1] OF CHAR;
23
24 PROCEDURE WriteReal(arg: REAL; ndigits: CARDINAL);
25 BEGIN
26 WriteLongReal(LONG(arg), ndigits)
27 END WriteReal;
28
29 PROCEDURE WriteLongReal(arg: LONGREAL; ndigits: CARDINAL);
30 VAR buf : RBUF;
31 ok : BOOLEAN;
32
33 BEGIN
34 IF ndigits > MAXWIDTH THEN ndigits := MAXWIDTH; END;
35 IF ndigits < 10 THEN ndigits := 10; END;
36 LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
37 WriteString(buf);
38 END WriteLongReal;
39
40 PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL);
41 BEGIN
42 WriteLongFixPt(LONG(arg), n, k)
43 END WriteFixPt;
44
45 PROCEDURE WriteLongFixPt(arg: LONGREAL; n, k: CARDINAL);
46 VAR buf: RBUF;
47 ok : BOOLEAN;
48
49 BEGIN
50 IF n > MAXWIDTH THEN n := MAXWIDTH END;
51 LongRealToString(arg, n, k, buf, ok);
52 WriteString(buf);
53 END WriteLongFixPt;
54
55 PROCEDURE ReadReal(VAR x: REAL);
56 VAR x1: LONGREAL;
57 BEGIN
58 ReadLongReal(x1);
59 x := x1
60 END ReadReal;
61
62 PROCEDURE ReadLongReal(VAR x: LONGREAL);
63 VAR Buf: ARRAY[0..512] OF CHAR;
64 ok: BOOLEAN;
65
66 BEGIN
67 ReadString(Buf);
68 StringToLongReal(Buf, x, ok);
69 IF NOT ok THEN
70 Message("real expected");
71 HALT;
72 END;
73 Done := TRUE;
74 END ReadLongReal;
75
76 PROCEDURE wroct(x: ARRAY OF WORD);
77 VAR i: CARDINAL;
78 BEGIN
79 FOR i := 0 TO HIGH(x) DO
80 WriteOct(CARDINAL(x[i]), 0);
81 WriteString(" ");
82 END;
83 END wroct;
84
85 PROCEDURE WriteRealOct(x: REAL);
86 BEGIN
87 wroct(x);
88 END WriteRealOct;
89
90 PROCEDURE WriteLongRealOct(x: LONGREAL);
91 BEGIN
92 wroct(x);
93 END WriteLongRealOct;
94
95BEGIN
96 Done := FALSE;
97END RealInOut.
Note: See TracBrowser for help on using the repository browser.