Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/tests/rtest/tests/heron/heron.diderot
ViewVC logotype

Diff of /branches/vis15/src/tests/rtest/tests/heron/heron.diderot

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4404, Thu Aug 11 14:00:48 2016 UTC revision 4405, Fri Aug 12 13:20:37 2016 UTC
# Line 21  Line 21 
21    
22  strand SqRoot (real arg)  strand SqRoot (real arg)
23  {  {
24      output real out = arg;  // holds root approximation      real root = arg;  // holds root approximation
25        int iter = 0;
26        output vec4 out = [0,0,0,0];        // value, root, iters, error
27    
28        initially {
29            if (arg <= 0) {
30                stabilize;
31            }
32        }
33    
34      update {      update {
35          out = (out + arg/out) / 2.0;          iter += 1;
36          if (|out^2 - arg| / arg < eps)          root = (root + arg/root) / 2.0;
37            if (|root^2 - arg| / arg < eps)
38              stabilize;              stabilize;
39      }      }
40    
41        stabilize {
42            out = [arg, root, iter, sqrt(arg)-root];
43        }
44    
45  }  }
46    
47  collection { SqRoot(args{i}) | i in 0 .. nArgs-1 }  collection { SqRoot(args{i}) | i in 0 .. nArgs-1 }

Legend:
Removed from v.4404  
changed lines
  Added in v.4405

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0