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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3361 - (download) (annotate)
Sat Oct 31 23:13:18 2015 UTC (3 years, 10 months ago) by glk
File size: 843 byte(s)
author tags now indicate who wrote this example and for what
/*! \file heron.diderot
 *
 * \author John Reppy
 * \author Gordon Kindlmann
 *
 * This example illustrates using Heron's method for computing square roots, originally
 * created by Gordon Kindlmann for the VIS'12 submission.  It also serves as a test for
 * loading data sequences.
 */

/*
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 */

input int{} args = load("numbers.nrrd");
//int{} args = load("numbers.nrrd");
int nArgs = length(args);
input real eps = 0.00001;
input bool dummy;

strand SqRoot (real arg)
{
    output real root = arg;

    update {
	if (dummy) root = arg+1;
	root = (root + arg/root) / 2.0;
	if (|root^2 - arg| / arg < eps)
	    stabilize;
    }
}

initially { SqRoot(args{i}) | i in 0 .. nArgs-1 };

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