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 mut_point = { mutable x : float; mutable y : float; }
  10. let iters2_mut 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 begin
  16.         p.x <- x *. x -. y *. y +. xc;
  17.         p.y <- 2.0 *. x *. y +. yc;
  18.         aux (count+1) p
  19.       end
  20.     end in
  21.   aux 0 {x=xc;y=yc}
  22.  
  23. (* use with "-pp camlp4of" *)
  24. DEFINE UNBOX(e) = (e +. 0.)    
  25.  
  26. let iters6 max_iter xc_boxed yc_boxed =
  27.   let xc = UNBOX xc_boxed in
  28.   let yc = UNBOX yc_boxed in
  29.   let x = ref (UNBOX xc) in
  30.   let y = ref (UNBOX yc) in
  31.   let count = ref 0 in
  32.   for i = 1 to max_iter do
  33.     if !x *. !x  +. !y *. !y >= 4.0 then raise Exit;
  34.     x := (!x *. !x -. !y *. !y +. xc);
  35.     y := (2.0 *. !x *. !y +. yc);
  36.   done; !count
Advertisement
Add Comment
Please, Sign In to add comment