41 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Modula-2
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Modula-2
		
	
	
	
	
	
| DEFINITION MODULE RealConversions;
 | |
| (*
 | |
|   Module:	string-to-real and real-to-string conversions
 | |
|   Author:	Ceriel J.H. Jacobs
 | |
|   Version:	$Id$
 | |
| *)
 | |
| 
 | |
|   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}]
 | |
| 	['E' ['+'|'-'] digit {digit}]
 | |
| 
 | |
|      ok := "conversion succeeded"
 | |
|      Leading blanks are skipped;
 | |
|      Input terminates with a blank or any control character.
 | |
|   *)
 | |
| 
 | |
|   PROCEDURE StringToLongReal(str: ARRAY OF CHAR;
 | |
| 			     VAR r: LONGREAL;
 | |
| 			     VAR ok: BOOLEAN);
 | |
| 
 | |
|   PROCEDURE RealToString(r: REAL;
 | |
| 			 width, digits: 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.
 | |
|   *)
 | |
| 
 | |
|   PROCEDURE LongRealToString(r: LONGREAL;
 | |
| 			 width, digits: INTEGER;
 | |
| 			 VAR str: ARRAY OF CHAR;
 | |
| 			 VAR ok: BOOLEAN);
 | |
| 
 | |
| END RealConversions.
 |