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

SCM Repository

[diderot] Annotation of /branches/vis12/test/heron/heron.diderot
ViewVC logotype

Annotation of /branches/vis12/test/heron/heron.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1995 - (view) (download)

1 : jhr 1995 /*! \file heron.diderot
2 :     *
3 :     * \author John Reppy
4 :     *
5 :     * This example illustrates using Heron's method for computing square roots. It also
6 :     * serves as a test for loading data sequences.
7 :     */
8 :    
9 :     /*
10 :     * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
11 :     * All rights reserved.
12 :     */
13 :    
14 :     input int{} args = load("numbers.nrrd");
15 :     int nArgs = length(args);
16 :     input real eps = 0.00001;
17 :    
18 :     strand SqRoot (real arg)
19 :     {
20 :     output real root = arg;
21 :    
22 :     update {
23 :     root = (root + arg/root) / 2.0;
24 :     if (|root^2 - arg| / arg < eps)
25 :     stabilize;
26 :     }
27 :     }
28 :    
29 :     initially { SqRoot(args{i}) | i in 0 .. nArgs-1 };

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