         Edinburgh IMP77 Compiler - Version 8.4

    1  %EXTERNALSTRING(255)%SPEC ERRMSG
    2  !%EXTERNALREALFNSPEC FRACPT(%LONGREAL R)
    3  
    4  
    5  %ROUTINE FRACTION(%REAL R, %INTEGER PLACES)
    6    %RETURN %IF PLACES<=0
    7    PRINTSYMBOL('.')
    8    %WHILE PLACES>0 %CYCLE
    9      R = FRACPT(R)*10.0
   10      PLACES=PLACES-1
   11      PRINTSYMBOL(INTPT(R)+'0')
   12    %REPEAT
   13  %END
   14  
   15  
   16  !  %routine PRINT(%long %real X, %integer I, J)
   17  !
   18  !     This routine transmits to the currently selected output stream the
   19  !     value of the real expression specified by the first parameter.  The
   20  !     second and third parameters should be integer expressions
   21  !     specifying the number of places to be allowed before and after the
   22  !     decimal point.  If the integer part needs more positions than are
   23  !     specified by the parameter, then more positions will be taken.  One
   24  !     position is allowed for a sign which is printed only in the
   25  !     negative case.  If necessary, the fractional part will be rounded.
   26  !
   27  !     Examples:
   28  !                   PRINT(A, 2, 3)
   29  !                   PRINT(COS(A-B), 1, 10)
   30  !
   31  !     {IMP77: The second parameter is interpreted in the same way as the
   32  !             second parameter of WRITE (described above).}
   33  
   34  
   35  !  %routine PRINT FL(%longreal X, %integer I)
   36  !
   37  !     This routine transmits to the currently selected output stream the
   38  !     value of the real expression specified by the first parameter.  The
   39  !     second parameter specifies the number of places to be allowed after
   40  !     the decimal point.  The printed number takes up the specified
   41  !     number of places, plus 7 additional places.
   42  !
   43  !     Example:
   44  !                   PRINT FL(X,4)
   45  !
   46  !     If X has the value 17.63584, this would be printed as  1.7636@ 1.
   47  !     The number is standardised in the range 1 <= X < 10.  One position
   48  !     each is allowed for signs for mantissa and exponent; in each case
   49  !     the sign is only printed when negative.
   50                      
   51  
   52  %EXTERNALROUTINE PRINTFL(%REAL R, %INTEGER P)
   53    %INTEGER EXP,SIGN
   54    SIGN=' '
   55    SIGN='-' %AND R=-R %IF R<0
   56    PRINTSYMBOL(SIGN)
   57    %IF R=0 %START
   58      EXP=-99
   59    %ELSE
   60      %IF P<=0 %START
   61        R=R+0.5
   62      %ELSE
   63        R=R+0.5*10\(-P)
   64      %FINISH
   65      EXP=0
   66      EXP=EXP+1 %AND R=R*0.1 %WHILE R >=10.0
   67      EXP=EXP-1 %AND R=R*10.0 %WHILE R< 1.0
   68    %FINISH
   69    PRINTSYMBOL(INT PT(R)+'0')
   70    FRACTION(R,P)
   71    PRINTSYMBOL('@'); WRITE(EXP,1)
   72  %END
   73  
   74  %EXTERNALROUTINE PRINT(%REAL R, %INTEGER B,A)
   75    %REAL RM
   76    %CONSTINTEGER MAX INT= 8_377777777777
   77    %INTEGER SIGN
   78    %ROUTINE P(%INTEGER N)
   79      B = B-1
   80      P(N//10) %IF N >= 10
   81      %IF SIGN # 0 %START
   82        SPACES(B-1)
   83        PRINTSYMBOL(SIGN);  SIGN = 0
   84      %FINISH
   85      PRINTSYMBOL(REM(N,10)+'0')
   86    %END
   87    RM=|R|
   88    PRINTFL(R, B+A) %AND %RETURN %IF RM> MAX INT
   89    %IF A<=0 %START
   90      RM=RM+0.5
   91    %ELSE
   92      RM=RM+0.5*10\(-A)
   93    %FINISH
   94    %IF B<=0 %THEN SIGN=0 %ELSE SIGN=' '
   95    %IF R<0 %THEN SIGN='-'
   96    P(INT PT(RM));  !THUS ALLOWING FOR -0.1 ETC.
   97    FRACTION(RM,A)
   98  %END
   99  
  100  %begin
  101  %end
  102  
  103  %ENDOFFILE

   61 Statements compiled
