home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / math / parall.sit / Parallaxis 2.0 / pi.p < prev    next >
Encoding:
Text File  |  1990-05-31  |  523 b   |  24 lines

  1. SYSTEM compute_pi;
  2. (* parallel reference algorithm, used by R. Babb *)
  3. CONST intervalls = 100;
  4.       width      = 1.0 / float(intervalls);
  5. CONFIGURATION list [1..intervalls];
  6. CONNECTION (* none *);
  7.  
  8. VECTOR val: real;
  9.  
  10. PROCEDURE f (VECTOR x: real): VECTOR real;
  11. (* function to be integrated *)
  12. BEGIN
  13.   RETURN(4.0 / (1.0 + x*x))
  14. END f;
  15.  
  16. BEGIN
  17.   PARALLEL
  18.     (* integral approximation with rectangle-rule *)
  19.     val := width * f( (float(id_no)-0.5) * width );
  20.   ENDPARALLEL;
  21.   WriteReal(REDUCE.sum(val), 15);
  22. END compute_pi.
  23.  
  24.