Added routines to read and write LONGREALS

This commit is contained in:
ceriel 1989-06-20 11:23:43 +00:00
parent 761312d0dd
commit 9e151cf706
4 changed files with 64 additions and 12 deletions

View file

@ -102,6 +102,9 @@ DEFINITION MODULE PascalIO;
Input stops at the character following the real.
*)
PROCEDURE ReadLongReal(InputText: Text; VAR Real: LONGREAL);
(* Like ReadReal, but for LONGREAL *)
(***************************************************************************
Output routines;
All these routines result in a runtime error when not called with either
@ -149,4 +152,7 @@ DEFINITION MODULE PascalIO;
Always use at least "Width" places, blank-padding to the left if needed.
*)
PROCEDURE WriteLongReal(OutputText: Text; Real: LONGREAL;
Width, Nfrac: CARDINAL);
(* Like WriteReal, but for LONGREAL *)
END PascalIO.

View file

@ -272,6 +272,13 @@ IMPLEMENTATION MODULE PascalIO;
END ReadCardinal;
PROCEDURE ReadReal(InputText: Text; VAR real: REAL);
VAR x1: LONGREAL;
BEGIN
ReadLongReal(InputText, x1);
real := x1
END ReadReal;
PROCEDURE ReadLongReal(InputText: Text; VAR real: LONGREAL);
VAR
buf: numbuf;
ch: CHAR;
@ -328,13 +335,13 @@ IMPLEMENTATION MODULE PascalIO;
END;
IF ok THEN
buf[index] := 0C;
RealConversions.StringToReal(buf, real, ok);
RealConversions.StringToLongReal(buf, real, ok);
END;
IF NOT ok THEN
Traps.Message("Illegal real");
HALT;
END;
END ReadReal;
END ReadLongReal;
PROCEDURE WriteCardinal(OutputText: Text; card: CARDINAL; width: CARDINAL);
VAR
@ -362,6 +369,11 @@ IMPLEMENTATION MODULE PascalIO;
END WriteBoolean;
PROCEDURE WriteReal(OutputText: Text; real: REAL; width, nfrac: CARDINAL);
BEGIN
WriteLongReal(OutputText, LONG(real), width, nfrac)
END WriteReal;
PROCEDURE WriteLongReal(OutputText: Text; real: LONGREAL; width, nfrac: CARDINAL);
VAR
buf: numbuf;
ok: BOOLEAN;
@ -371,18 +383,18 @@ IMPLEMENTATION MODULE PascalIO;
width := SIZE(buf);
END;
IF nfrac > 0 THEN
RealConversions.RealToString(real, width, nfrac, buf, ok);
RealConversions.LongRealToString(real, width, nfrac, buf, ok);
ELSE
IF width < 9 THEN width := 9; END;
IF real < 0.0 THEN
IF real < 0.0D THEN
digits := 7 - INTEGER(width);
ELSE
digits := 6 - INTEGER(width);
END;
RealConversions.RealToString(real, width, digits, buf, ok);
RealConversions.LongRealToString(real, width, digits, buf, ok);
END;
WriteString(OutputText, buf, 0);
END WriteReal;
END WriteLongReal;
PROCEDURE WriteString(OutputText: Text; str: ARRAY OF CHAR; width: CARDINAL);
VAR index: CARDINAL;

View file

@ -19,18 +19,30 @@ DEFINITION MODULE RealInOut;
DEL or BACKSPACE, depending on the implementation of ReadString.
*)
PROCEDURE ReadLongReal(VAR x: LONGREAL);
(* Like ReadReal, but for LONGREAL *)
PROCEDURE WriteReal(x: REAL; n: CARDINAL);
(* Write x using n characters.
If fewer than n characters are needed, leading blanks are inserted.
*)
PROCEDURE WriteLongReal(x: LONGREAL; n: CARDINAL);
(* Like WriteReal, but for LONGREAL *)
PROCEDURE WriteFixPt(x: REAL; n, k: CARDINAL);
(* Write x in fixed-point notation usign n characters with k digits
after the decimal point. If fewer than n characters are needed,
leading blanks are inserted.
*)
PROCEDURE WriteLongFixPt(x: LONGREAL; n, k: CARDINAL);
(* Like WriteFixPt, but for LONGREAL *)
PROCEDURE WriteRealOct(x: REAL);
(* Write x in octal words.
*)
PROCEDURE WriteLongRealOct(x: LONGREAL);
(* Like WriteRealOct, but for LONGREAL *)
END RealInOut.

View file

@ -21,39 +21,56 @@ IMPLEMENTATION MODULE RealInOut;
TYPE RBUF = ARRAY [0..MAXWIDTH+1] OF CHAR;
PROCEDURE WriteReal(arg: REAL; ndigits: CARDINAL);
BEGIN
WriteLongReal(LONG(arg), ndigits)
END WriteReal;
PROCEDURE WriteLongReal(arg: LONGREAL; ndigits: CARDINAL);
VAR buf : RBUF;
ok : BOOLEAN;
BEGIN
IF ndigits > MAXWIDTH THEN ndigits := MAXWIDTH; END;
IF ndigits < 10 THEN ndigits := 10; END;
RealConversions.RealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
RealConversions.LongRealToString(arg, ndigits, -INTEGER(ndigits - 7), buf, ok);
InOut.WriteString(buf);
END WriteReal;
END WriteLongReal;
PROCEDURE WriteFixPt(arg: REAL; n, k: CARDINAL);
BEGIN
WriteLongFixPt(LONG(arg), n, k)
END WriteFixPt;
PROCEDURE WriteLongFixPt(arg: LONGREAL; n, k: CARDINAL);
VAR buf: RBUF;
ok : BOOLEAN;
BEGIN
IF n > MAXWIDTH THEN n := MAXWIDTH END;
RealConversions.RealToString(arg, n, k, buf, ok);
RealConversions.LongRealToString(arg, n, k, buf, ok);
InOut.WriteString(buf);
END WriteFixPt;
END WriteLongFixPt;
PROCEDURE ReadReal(VAR x: REAL);
VAR x1: LONGREAL;
BEGIN
ReadLongReal(x1);
x := x1
END ReadReal;
PROCEDURE ReadLongReal(VAR x: LONGREAL);
VAR Buf: ARRAY[0..512] OF CHAR;
ok: BOOLEAN;
BEGIN
InOut.ReadString(Buf);
RealConversions.StringToReal(Buf, x, ok);
RealConversions.StringToLongReal(Buf, x, ok);
IF NOT ok THEN
Traps.Message("real expected");
HALT;
END;
Done := TRUE;
END ReadReal;
END ReadLongReal;
PROCEDURE wroct(x: ARRAY OF WORD);
VAR i: CARDINAL;
@ -69,6 +86,11 @@ IMPLEMENTATION MODULE RealInOut;
wroct(x);
END WriteRealOct;
PROCEDURE WriteLongRealOct(x: LONGREAL);
BEGIN
wroct(x);
END WriteLongRealOct;
BEGIN
Done := FALSE;
END RealInOut.