home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / mystic.zip / PAS5.DOC < prev    next >
Text File  |  1986-02-27  |  23KB  |  1,712 lines

  1.  
  2.         Mystic Pascal  User Manual                                      29
  3.  
  4.  
  5.         8.  Procedures and Functions
  6.  
  7.              This   section  of  the  manual  describes  procedures   and 
  8.         functions.    Procedures   and   functions  which  are  used   in 
  9.         Input/Output  processing  are described  in  section  9.   Multi-
  10.         tasking procedures are described in section 7.
  11.  
  12.  
  13.                 Procedure       Purpose
  14.                 ---------       -------
  15.                 DISPOSE         deallocate dynamic variable 
  16.         +       INTR            interrupt call
  17.                 NEW             allocate dynamic variable 
  18.                 PACK            unimplemented
  19.                 UNPACK          unimplemented
  20.  
  21.                 Function        Return Value
  22.                 --------        ------------
  23.                 ABS             absolute value
  24.                 ARCTAN          arctangent
  25.                 CHR             convert integer to character
  26.                 COS             cosine
  27.                 EXP             exponential function
  28.         +       FLOAT           convert integer to real
  29.         +       FRACTION        fractional part of real
  30.         +1.6    INTSTR          convert integer to string
  31.                 LN              natural logarithm
  32.                 ODD             test for odd integer
  33.         +       OFFSET          offset of a variable
  34.                 ORD             convert ordinal to integer
  35.                 PRED            preceding ordinal
  36.         +1.6    REALSTR         convert real number to string
  37.                 ROUND           convert real number to integer
  38.         +       SEGMENT         segment of a variable
  39.                 SIN             sine
  40.                 SQR             square
  41.                 SQRT            square root
  42.         +1.6    STRINT          convert string to integer
  43.         +1.6    STRREAL         convert string to real number
  44.                 SUCC            succeeding ordinal 
  45.                 TRUNC           convert real number to integer
  46.         +1.6    UPCASE          convert char to upper case
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.         Section 8:  Procedures and Functions
  58.  
  59.         Mystic Pascal  User Manual                                      30
  60.  
  61.  
  62.         8.1  ABS
  63.  
  64.  
  65.         ABS( expression ) 
  66.            
  67.  
  68.              The  ABS standard function returns the absolute value of  an 
  69.         integer  or real expression.   The result is of the same type  as 
  70.         the input expression.
  71.  
  72.         Examples:
  73.  
  74.                 A := ABS( X );
  75.  
  76.                 WRITELN( 'ABSOLUTE VALUE IS',ABS( COS( Y )));
  77.  
  78.                 B := ABS( X + Y / Z );
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.         Section 8:  Procedures and Functions
  115.  
  116.         Mystic Pascal  User Manual                                      31
  117.  
  118.  
  119.         8.2  ARCTAN
  120.  
  121.  
  122.         ARCTAN( expression ) 
  123.  
  124.  
  125.              This  standard function returns the arctangent of a real  or 
  126.         integer expression.   The result type is real and is expressed in 
  127.         radians.
  128.  
  129.  
  130.         Examples:
  131.  
  132.                 WRITELN( ARCTAN( A + 3.14159 ));
  133.  
  134.                 NODE.VALUE := OLDNODE.VALUE + ARCTAN( V );
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.         Section 8:  Procedures and Functions
  172.  
  173.         Mystic Pascal  User Manual                                      32
  174.  
  175.  
  176.         8.3  CHR
  177.  
  178.  
  179.         CHR( integer_expression ) 
  180.  
  181.  
  182.              The  CHR  standard function converts an  integer  expression 
  183.         into  a  character.   The result type is char.   If  the  integer 
  184.         expression  is  less than zero or greater than  255,  a  run-time 
  185.         error occurs.
  186.  
  187.              CHR  is often used for sending control characters to  output 
  188.         devices.
  189.  
  190.  
  191.         Examples:
  192.  
  193.                 WRITE( CHR( 12 ));
  194.  
  195.                 TAB := CHR( 9 );
  196.  
  197.                 CARRIAGERETURN := CHR(13);
  198.  
  199.                 LINEFEED := CHR(10);
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.         Section 8:  Procedures and Functions
  229.  
  230.         Mystic Pascal  User Manual                                      33
  231.  
  232.  
  233.         8.4  COS
  234.  
  235.  
  236.         COS( expression ) 
  237.  
  238.  
  239.              The  COS standard function returns the cosine of a  real  or 
  240.         integer expression whose value is given in radians.   The  result 
  241.         type is real.
  242.  
  243.  
  244.         Examples:
  245.  
  246.                 WRITELN( COS( ANGLE ));
  247.  
  248.                 NODE.COSINE := COS( N );
  249.  
  250.                 WRITELN( COS( VELOCITY / CHARGE ));
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.         Section 8:  Procedures and Functions
  286.  
  287.         Mystic Pascal  User Manual                                      34
  288.  
  289.  
  290.         8.5  DISPOSE
  291.  
  292.  
  293.         DISPOSE( pointer_variable ) 
  294.  
  295.               
  296.              The   DISPOSE  procedure  is  used  to  deallocate   dynamic 
  297.         variables.  The  pointer_variable addresses a dynamic variable in 
  298.         dynamic  storage.   After  execution of the procedure  the  space 
  299.         released is available for other uses.
  300.            
  301.              Mystic  Pascal  supports  true dynamic  storage  with  auto-
  302.         compression.   When  blocks are freed up,  storage  fragmentation 
  303.         occurs -- unused blocks tend to accumulate.   Because many blocks 
  304.         tend to be small,  they cannot be immediately reused for  another 
  305.         purpose.   When  storage  becomes  short an  auto-compression  is 
  306.         initiated by the Pascal system.  
  307.  
  308.  
  309.         Example:
  310.  
  311.                 PROCEDURE DISPOSEDEMO;
  312.                 TYPE
  313.                 DYNVAR = ARRAY [1..200] OF CHAR;
  314.                 VAR
  315.                 POINTER : ^DYNVAR;
  316.                 BEGIN
  317.                 NEW( POINTER );  (* ALLOCATE A DYNAMIC VAR *)
  318.  
  319.                 (* DO SOME PROCESSING WITH THE DYNAMIC VAR *)
  320.  
  321.                 DISPOSE( POINTER ); (* FREE UP THE 200 BYTES *)
  322.                 END;
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.         Section 8:  Procedures and Functions
  343.  
  344.         Mystic Pascal  User Manual                                      35
  345.  
  346.  
  347.         8.6  EXP
  348.  
  349.  
  350.         EXP( expression ) 
  351.  
  352.  
  353.         The exponential function computes e to the x power,  where x is a 
  354.         real or integer expression.  The result type is real.
  355.  
  356.  
  357.         Examples:
  358.  
  359.                 X := EXP( Y );
  360.  
  361.                 SHIPVELOCITY := EXP( WARPFACTOR );
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.         Section 8:  Procedures and Functions
  400.  
  401.         Mystic Pascal  User Manual                                      36
  402.  
  403.  
  404.         8.7  FLOAT         (Non-Standard Feature)
  405.  
  406.  
  407.         FLOAT( integer_expression )
  408.  
  409.  
  410.              The Float function converts integers to real  numbers.   The 
  411.         result type is real.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.         Section 8:  Procedures and Functions
  457.  
  458.         Mystic Pascal  User Manual                                      37
  459.  
  460.  
  461.         8.8  FRACTION      (Non-Standard Feature)
  462.  
  463.  
  464.         FRACTION( real_expression )
  465.  
  466.  
  467.              The  Fraction function returns the fractional part of a real 
  468.         number.  The result type is real.
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.         Section 8:  Procedures and Functions
  514.  
  515.         Mystic Pascal  User Manual                                      38
  516.  
  517.  
  518.         8.9  INTR          (Non-Standard Feature)
  519.  
  520.  
  521.         INTR( interrupt, registers )
  522.  
  523.  
  524.              The  INTR procedure permits access to DOS and BIOS functions 
  525.         by  directly  calling  interrupt  routines.    The  standard  DOS 
  526.         interrupt is number 33.   The interrupt number must be an integer 
  527.         expression.   The  registers  variable is used to  set  the  8086 
  528.         registers  on  entry  and they are stored into  the  variable  on 
  529.         return from the interrupt routine.
  530.  
  531.              Registers is declared as:
  532.  
  533.              REGISTERS = RECORD
  534.                   AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : INTEGER
  535.                   END;
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.         Section 8:  Procedures and Functions
  571.  
  572.         Mystic Pascal  User Manual                                      39
  573.  
  574.  
  575.         8.10  INTSTR       (Non-Standard Feature)           ** 1.6 **
  576.  
  577.              INTSTR( integer )
  578.  
  579.              The  Intstr function converts an integer to a  string.   The 
  580.         result type is 
  581.  
  582.              PACKED ARRAY [1..6] OF CHAR
  583.  
  584.              The characters are right aligned in the field.
  585.  
  586.  
  587.              CHART.XAXIS[I] := INTSTR( I * DELTA );
  588.  
  589.              REPORT.YEAR1 := INTSTR( YR );
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.         Section 8:  Procedures and Functions
  628.  
  629.         Mystic Pascal  User Manual                                      40
  630.  
  631.  
  632.         8.11 LN
  633.  
  634.  
  635.         LN( expression ) 
  636.  
  637.  
  638.              The  LN function computes the natural logarithm of a real or 
  639.         integer expression.   If the expression is less than or equal  to 
  640.         zero a run-time error occurs.  The result type is real.
  641.  
  642.  
  643.         Examples:
  644.  
  645.                 X := LN( Y );
  646.  
  647.                 WRITELN( LN( X + SQR(Y)));
  648.  
  649.                 IF LN( FACTORBETA ) < 0.1 THEN
  650.                         WRITELN(FACTORBETA);
  651.  
  652.                 A := SQRT( LN(Z));
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.         Section 8:  Procedures and Functions
  685.  
  686.         Mystic Pascal  User Manual                                      41
  687.  
  688.  
  689.         8.12  NEW
  690.  
  691.         Format 1
  692.         NEW( pointer_variable ) 
  693.  
  694.         Format 2
  695.         NEW( pointer_variable, tag1,..., tagn ) 
  696.  
  697.              The NEW procedure allocates new dynamic variables.   A block 
  698.         of dynamic storage of the required size is obtained.  The block's 
  699.         indirect address, not its actual address is stored in the pointer 
  700.         variable.
  701.  
  702.              After  NEW  has been executed,  the dynamic variable may  be 
  703.         accessed.   Dynamic variables remain allocated until specifically 
  704.         deallocated by the DISPOSE procedure.  If a procedure uses NEW to 
  705.         allocate  a dynamic variable,   that variable  remains  allocated 
  706.         after the procedure ends.
  707.           
  708.              Format  2 contains 1 to n tag fields.   These are the fields 
  709.         specified in the CASE clause of variant records.
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.         Section 8:  Procedures and Functions
  742.  
  743.         Mystic Pascal  User Manual                                      42
  744.  
  745.  
  746.         Example:
  747.  
  748.                 (* PROGRAM FRAGMENT TO ALLOCATE A       
  749.                    LINKED LIST OF VARIABLE LENGTH.      
  750.                    THE ROOT OF THE LIST IS A GLOBAL     
  751.                    VARIABLE.  NODES AFTER THE FIRST       
  752.                    ARE INSERTED BETWEEN THE ROOT AND    
  753.                    THE FIRST NODE.                      *)
  754.  
  755.                 TYPE
  756.                 NODE =  RECORD
  757.                         NEXT : INTEGER;
  758.                         DATA : REAL 
  759.                         END;
  760.                 VAR
  761.                 ROOT : ^NODE;
  762.  
  763.                 PROCEDURE LINKEDLIST ( COUNT : INTEGER );
  764.                 VAR
  765.                 I : INTEGER;
  766.                 TEMP : ^NODE;
  767.                 BEGIN
  768.                 (* ALLOCATE FIRST NODE *)
  769.                 NEW( ROOT );
  770.  
  771.                 (* SET END_OF_LIST INDICATOR *)
  772.                 ROOT^.NEXT := NIL;
  773.  
  774.                 (* ALLOCATE LINKED LIST *)
  775.                 FOR I := 1 TO COUNT DO
  776.                         BEGIN
  777.                         NEW( TEMP );
  778.                         TEMP^.NEXT := ROOT;
  779.                         ROOT := TEMP 
  780.                         END 
  781.                 END; (* LINKEDLIST *)
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.         Section 8:  Procedures and Functions
  799.  
  800.         Mystic Pascal  User Manual                                      43
  801.  
  802.  
  803.         8.13  ODD
  804.  
  805.  
  806.         ODD( integer_expression ) 
  807.  
  808.  
  809.              ODD  is a Boolean function which returns the value  true  if 
  810.         the integer_expression is odd otherwise it returns false.
  811.  
  812.              The expression X is odd if (abs(X) mod 2) equals one.
  813.  
  814.  
  815.         Examples:
  816.  
  817.                 IF ODD(X) THEN  TESTFORPRIME(X);
  818.  
  819.                 IF ODD(I) THEN I:=I+1;
  820.  
  821.                 WRITELN( ODD(Y) );
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.         Section 8:  Procedures and Functions
  856.  
  857.         Mystic Pascal  User Manual                                      44
  858.  
  859.  
  860.         8.14  OFFSET       (Non-Standard Feature)
  861.  
  862.  
  863.         OFFSET( variable )
  864.  
  865.  
  866.              The Offset function returns the offset of a variable.   Used 
  867.         with the Segment function, this allows passing parameters such as 
  868.         strings of characters to DOS with the INTR procedure.  The result 
  869.         type is integer.
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.         Section 8:  Procedures and Functions
  913.  
  914.         Mystic Pascal  User Manual                                      45
  915.  
  916.  
  917.         8.15  ORD
  918.  
  919.  
  920.         ORD( ordinal_expression ) 
  921.  
  922.  
  923.              The  ORD  function converts an ordinal value to  an  ordinal 
  924.         number.  For example, if
  925.  
  926.              TYPE  DAYS = (SUN,MON,TUE,WED,THU,FRI,SAT);
  927.  
  928.         then ORD(TUE) is equal to 2.
  929.  
  930.  
  931.         Example:
  932.  
  933.                 REPEAT
  934.                   READ(INFILE, CH);
  935.                   WRITE( CH ) 
  936.                 UNTIL ORD(CH) = 26;     (* EOF CHAR DETECTION *)
  937.  
  938.                 (* ASCII DISPLAY *)
  939.                 FOR CH := ' ' TO 'z' DO
  940.                         WRITELN( CH, ' = ',ORD(CH));
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.         Section 8:  Procedures and Functions
  970.  
  971.         Mystic Pascal  User Manual                                      46
  972.  
  973.  
  974.         8.16  PACK and UNPACK
  975.  
  976.              The  PACK and UNPACK Pascal standard procedures are not used 
  977.         in Mystic Pascal.   A Pascal program may contain these procedures 
  978.         but they will be treated as null operations.
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.         Section 8:  Procedures and Functions
  1027.  
  1028.         Mystic Pascal  User Manual                                      47
  1029.  
  1030.  
  1031.         8.17  PRED
  1032.  
  1033.  
  1034.         PRED( ordinal_expression ) 
  1035.  
  1036.  
  1037.              The PRED function is the inverse of the SUCC function.   The 
  1038.         predecessor  function returns the ordinal value that is one  less 
  1039.         than the input expression.  
  1040.  
  1041.              The PRED of 8 is 7.  The PRED of 'T' is 'S'.  
  1042.  
  1043.  
  1044.         Example:
  1045.  
  1046.                 WRITELN( A, PRED(A) );
  1047.  
  1048.                 WRITELN( CH, PRED(CH) );
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.         Section 8:  Procedures and Functions
  1084.  
  1085.         Mystic Pascal  User Manual                                      48
  1086.  
  1087.  
  1088.         8.18  REALSTR      (Non-Standard Feature)           ** 1.6 **
  1089.  
  1090.         REALSTR( real_expression, mode, width, frac );
  1091.  
  1092.              The Realstr function converts real numbers to strings.   All 
  1093.         four parameters must always be present.  The mode, width and frac 
  1094.         parameters  are all integer expressions.   Three conversion modes 
  1095.         are available.
  1096.  
  1097.         Mode=0   Simple mode  -   no leading blanks,  no trailing  zeros, 
  1098.         exponent field is displayed only if required
  1099.  
  1100.         Mode=1   Floating Point mode -  width parameter specifies  result 
  1101.         size.
  1102.  
  1103.         Mode=2   Fixed Point mode - width parameter specifies result size 
  1104.         and frac parameter specifies number of fractional digits.
  1105.  
  1106.  
  1107.  
  1108.              EDITAREA := REALSTR( AMOUNT, 2, 10, 4 );
  1109.  
  1110.              FIELD4 := REALSTR( TOTAL, 0, 0, 0 );
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.         Section 8:  Procedures and Functions
  1141.  
  1142.         Mystic Pascal  User Manual                                      49
  1143.  
  1144.  
  1145.         8.19  ROUND
  1146.  
  1147.  
  1148.         ROUND( real_expression ) 
  1149.  
  1150.  
  1151.              ROUND   is  a  standard  function  which  converts  a   real 
  1152.         expression  to  an  integer value.   If X >= 0 then  ROUND(X)  is 
  1153.         TRUNC(X + 0.5).  If X < 0 then ROUND(X) is TRUNC(X - 0.5).
  1154.  
  1155.              ROUND( 2.5 ) is 3
  1156.              ROUND( -2.5 ) is -3
  1157.           
  1158.              If  the real value is too large to be converted  to  integer 
  1159.         format a run-time error occurs.
  1160.  
  1161.  
  1162.         Examples:
  1163.  
  1164.                 INT := ROUND( X + Y );
  1165.  
  1166.                 TEMPERATURE := ROUND( THERMOMETERREADING );
  1167.             
  1168.                 PLOTX := ROUND( X / SCALINGFACTOR );
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.         Section 8:  Procedures and Functions
  1198.  
  1199.         Mystic Pascal  User Manual                                      50
  1200.  
  1201.  
  1202.         8.20  SEGMENT      (Non-Standard Feature)
  1203.  
  1204.  
  1205.         SEGMENT( variable )
  1206.  
  1207.  
  1208.              The  Segment  function  returns  the segment  address  of  a 
  1209.         variable.   For  global  variables this is the same as  the  User 
  1210.         Area.   For local variables this will be a value inside the  User 
  1211.         Area.    Used  with  the  Offset  function  this  allows  passing 
  1212.         parameters  such  as strings of characters to DOS with  the  INTR 
  1213.         procedure.  The result type is integer.
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.         Section 8:  Procedures and Functions
  1255.  
  1256.         Mystic Pascal  User Manual                                      51
  1257.  
  1258.  
  1259.         8.21  SIN
  1260.  
  1261.  
  1262.         SIN( expression ) 
  1263.  
  1264.  
  1265.              The  SIN  standard  function returns the sine of a  real  or 
  1266.         integer expression whose value is given in radians.   The  result 
  1267.         type is real.
  1268.  
  1269.  
  1270.         Examples:
  1271.  
  1272.                 WRITELN( SIN( ANGLE ));
  1273.  
  1274.                 NODE.SINE := SIN( N );
  1275.  
  1276.                 WRITELN( SIN( VELOCITY / CHARGE ));
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.         Section 8:  Procedures and Functions
  1312.  
  1313.         Mystic Pascal  User Manual                                      52
  1314.  
  1315.  
  1316.         8.22  SQR
  1317.  
  1318.  
  1319.         SQR( expression ) 
  1320.  
  1321.  
  1322.              The  SQR standard function computes the square of a real  or 
  1323.         integer  expression.   The result type is of the same type as the 
  1324.         input expression.
  1325.  
  1326.  
  1327.         Examples:
  1328.  
  1329.                 WRITELN( 'SQUARE OF X IS ', SQR(X) );
  1330.  
  1331.                 AREA := SQR( SIDE );
  1332.  
  1333.                 CIRCLEAREA := PI * SQR( RADIUS );
  1334.  
  1335.                 ENERGY := MASS * SQR( LIGHTSPEED );
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.         Section 8:  Procedures and Functions
  1369.  
  1370.         Mystic Pascal  User Manual                                      53
  1371.  
  1372.  
  1373.         8.23  SQRT
  1374.  
  1375.  
  1376.         SQRT( expression ) 
  1377.  
  1378.  
  1379.              This standard function returns the square root of a real  or 
  1380.         integer  expression.   The  result type is real and is  always  a 
  1381.         positive value.   A run-time error occurs if the input expression 
  1382.         is negative.
  1383.  
  1384.  
  1385.         Examples:
  1386.  
  1387.                 WRITELN( SQRT( A + 3.14159 ));
  1388.  
  1389.                 NODE.VALUE := OLDNODE.VALUE + SQRT( V );
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.         Section 8:  Procedures and Functions
  1426.  
  1427.         Mystic Pascal  User Manual                                      54
  1428.  
  1429.  
  1430.         8.24  STRINT       (Non-Standard Feature)           ** 1.6 **
  1431.  
  1432.         STRINT( string )
  1433.  
  1434.              The Strint function converts a string to an integer.  If the 
  1435.         string  does  not contain a valid integer as its first  non-blank 
  1436.         characters, a value of -32768 is returned.
  1437.  
  1438.  
  1439.              VALUE := STRINT( INPUTSTRING );
  1440.  
  1441.              X := STRINT( GETNUM );
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.         Section 8:  Procedures and Functions
  1483.  
  1484.         Mystic Pascal  User Manual                                      55
  1485.  
  1486.  
  1487.         8.25  STRREAL      (Non-Standard Feature)           ** 1.6 **
  1488.  
  1489.         STRREAL( string )
  1490.  
  1491.              The Strreal function converts a string to a real number.  If 
  1492.         the string does not contain a valid real number as its first non-
  1493.         blank characters, a value of -9.999E-30 is returned.
  1494.  
  1495.  
  1496.              A := STRREAL( TEXTVALUE );
  1497.  
  1498.              X := STRREAL( VECTOR[ J ] );
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.         Section 8:  Procedures and Functions
  1540.  
  1541.         Mystic Pascal  User Manual                                      56
  1542.  
  1543.  
  1544.         8.26  SUCC
  1545.  
  1546.  
  1547.         SUCC( ordinal_expression ) 
  1548.  
  1549.  
  1550.              The  successor function is the inverse of the PRED function.  
  1551.         The SUCC function takes an ordinal value and returns the  ordinal 
  1552.         value one greater.  
  1553.  
  1554.              The SUCC of 7 is 8.  The SUCC of 'S' is 'T'.
  1555.  
  1556.  
  1557.         Example:
  1558.  
  1559.                 WRITELN( A, SUCC(A) );
  1560.  
  1561.                 WRITELN( CH, SUCC(CH) );
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.         Section 8:  Procedures and Functions
  1597.  
  1598.         Mystic Pascal  User Manual                                      57
  1599.  
  1600.  
  1601.         8.27  TRUNC
  1602.  
  1603.  
  1604.         TRUNC( real_expression ) 
  1605.  
  1606.  
  1607.              TRUNC   is  a  standard  function  which  converts  a   real 
  1608.         expression  to an integer value.   The fractional portion of  the 
  1609.         real expression is truncated.
  1610.  
  1611.              TRUNC(2.5) is 2
  1612.              TRUNC(-2.5) is -2
  1613.           
  1614.              If  the real value is too large to be converted  to  integer 
  1615.         format a run-time error occurs.
  1616.  
  1617.  
  1618.         Examples:
  1619.  
  1620.                 INT := TRUNC( X + Y );
  1621.  
  1622.                 TEMPERATURE := TRUNC( THERMOMETERREADING );
  1623.  
  1624.                 PLOTX := TRUNC( X / SCALINGFACTOR );
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.         Section 8:  Procedures and Functions
  1654.  
  1655.         Mystic Pascal  User Manual                                      58
  1656.  
  1657.  
  1658.         8.28  UPCASE       (Non-Standard Feature)           ** 1.6 **
  1659.  
  1660.  
  1661.         UPCASE( expression ) 
  1662.  
  1663.  
  1664.              The  UPCASE  function  is a Mystic  Pascal  extension  which 
  1665.         converts  a char or string expression to upper case.   The result 
  1666.         type is the same as the input expression type.  
  1667.  
  1668.  
  1669.  
  1670.         Examples:
  1671.  
  1672.                 IF UPCASE( COMMAND ) = 'X' THEN
  1673.                         CMDX;
  1674.  
  1675.                 WRITE( F1, UPCASE(NAME) );
  1676.  
  1677.                 READLN( OPTION );
  1678.                 IF UPCASE( OPTION ) = 'EXIT' THEN GOTO 99;
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.         Section 8:  Procedures and Functions
  1711.  
  1712.