1987-05-22 17:15:09 +00:00
|
|
|
DEFINITION MODULE RealConversions;
|
1988-02-19 15:54:01 +00:00
|
|
|
(*
|
|
|
|
Module: string-to-real and real-to-string conversions
|
|
|
|
Author: Ceriel J.H. Jacobs
|
|
|
|
Version: $Header$
|
|
|
|
*)
|
1987-05-22 17:15:09 +00:00
|
|
|
|
|
|
|
PROCEDURE StringToReal(str: ARRAY OF CHAR; VAR r: REAL; VAR ok: BOOLEAN);
|
|
|
|
(* Convert string "str" to a real number "r" according to the syntax:
|
|
|
|
|
|
|
|
['+'|'-'] digit {digit} ['.' digit {digit}]
|
1987-06-26 15:59:52 +00:00
|
|
|
['E' ['+'|'-'] digit {digit}]
|
1987-05-22 17:15:09 +00:00
|
|
|
|
|
|
|
ok := "conversion succeeded"
|
|
|
|
Leading blanks are skipped;
|
|
|
|
Input terminates with a blank or any control character.
|
|
|
|
*)
|
|
|
|
|
|
|
|
PROCEDURE RealToString(r: REAL;
|
|
|
|
digits, width: INTEGER;
|
|
|
|
VAR str: ARRAY OF CHAR;
|
|
|
|
VAR ok: BOOLEAN);
|
|
|
|
(* Convert real number "r" to string "str", either in fixed-point or
|
|
|
|
exponent notation.
|
|
|
|
"digits" is the number digits to the right of the decimal point,
|
|
|
|
"width" is the maximum width of the notation.
|
|
|
|
If digits < 0, exponent notation is used, otherwise fixed-point.
|
|
|
|
If fewer than "width" characters are needed, leading blanks are inserted.
|
|
|
|
If the representation does not fit in "width", then ok is set to FALSE.
|
|
|
|
*)
|
|
|
|
|
|
|
|
END RealConversions.
|