From 9e151cf7065e6e057ecbcc65b0a82ae8d0e88879 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jun 1989 11:23:43 +0000 Subject: [PATCH] Added routines to read and write LONGREALS --- lang/m2/libm2/PascalIO.def | 6 ++++++ lang/m2/libm2/PascalIO.mod | 24 ++++++++++++++++++------ lang/m2/libm2/RealInOut.def | 12 ++++++++++++ lang/m2/libm2/RealInOut.mod | 34 ++++++++++++++++++++++++++++------ 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/lang/m2/libm2/PascalIO.def b/lang/m2/libm2/PascalIO.def index a913466e3..e9db8a3ec 100644 --- a/lang/m2/libm2/PascalIO.def +++ b/lang/m2/libm2/PascalIO.def @@ -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. diff --git a/lang/m2/libm2/PascalIO.mod b/lang/m2/libm2/PascalIO.mod index cbd99ddcc..07c11dbaf 100644 --- a/lang/m2/libm2/PascalIO.mod +++ b/lang/m2/libm2/PascalIO.mod @@ -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; diff --git a/lang/m2/libm2/RealInOut.def b/lang/m2/libm2/RealInOut.def index 5ab39ced8..b508d307c 100644 --- a/lang/m2/libm2/RealInOut.def +++ b/lang/m2/libm2/RealInOut.def @@ -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. diff --git a/lang/m2/libm2/RealInOut.mod b/lang/m2/libm2/RealInOut.mod index 28ed945f6..3a09cf306 100644 --- a/lang/m2/libm2/RealInOut.mod +++ b/lang/m2/libm2/RealInOut.mod @@ -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.