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. Input stops at the character following the real.
*) *)
PROCEDURE ReadLongReal(InputText: Text; VAR Real: LONGREAL);
(* Like ReadReal, but for LONGREAL *)
(*************************************************************************** (***************************************************************************
Output routines; Output routines;
All these routines result in a runtime error when not called with either 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. 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. END PascalIO.

View file

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

View file

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

View file

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