Guest User

Untitled

a guest
Dec 6th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let iters1 max_iter xc yc =
  2.   let rec aux count x y =
  3.     if count = max_iter then max_iter else begin
  4.       if x *. x  +. y *. y >= 4.0 then count else
  5.       aux (count+1) (x *. x -. y *. y +. xc) (2.0 *. x *. y +. yc)
  6.     end in
  7.   aux 0 xc yc
  8.  
  9. type point = { x : float; y : float }
  10. let iters2 max_iter pc =
  11.   let {x=xc;y=yc} = pc in
  12.   let rec aux count p =
  13.     if count = max_iter then max_iter else begin
  14.       let {x;y} = p in
  15.       if x *. x  +. y *. y >= 4.0 then count else
  16.         aux (count+1) {p with x = x *. x -. y *. y +. xc; y = 2.0 *. x *. y +. yc}
  17.     end in
  18.   aux 0 {x=0.;y=0.}
  19.  
  20. * use with "-pp camlp4of" *)
  21. DEFINE UNBOX(e) = (e +. 0.)    
  22.  
  23. let iters6 max_iter xc_boxed yc_boxed =
  24.   let xc = UNBOX xc_boxed in
  25.   let yc = UNBOX yc_boxed in
  26.   let x = ref (UNBOX xc) in
  27.   let y = ref (UNBOX yc) in
  28.   let count = ref 0 in
  29.   for i = 1 to max_iter do
  30.     if !x *. !x  +. !y *. !y >= 4.0 then raise Exit;
  31.     x := (!x *. !x -. !y *. !y +. xc);
  32.     y := (2.0 *. !x *. !y +. yc);
  33.   done; !count
Advertisement
Add Comment
Please, Sign In to add comment