Added note about GUI architecture to doc/hacking.txt + doc/img/gui_flow/.
[hooke.git] / doc / img / gui_flow / math.sqrt.template.xsl
1 <?xml version="1.0"?>\r
2 <!-- http://www.exslt.org/math/functions/sqrt/math.sqrt.template.xsl -->\r
3 <xsl:stylesheet version="1.0"\r
4                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
5                 xmlns:math="http://exslt.org/math"\r
6                 extension-element-prefixes="math">\r
7 \r
8 <xsl:template name="sqrt">\r
9   <!-- The number you want to find the square root of -->\r
10   <xsl:param name="number" select="0" />  \r
11   <!-- The current 'try'.  This is used internally. -->\r
12   <xsl:param name="try" select="1" />\r
13   <!-- The current iteration, checked against maxiter to limit loop count -->  \r
14   <xsl:param name="iter" select="1" />\r
15   <!-- Set this up to ensure against infinite loops -->\r
16   <xsl:param name="maxiter" select="10" />\r
17 \r
18   <!-- This template was written by Nate Austin using Sir Isaac Newton's\r
19        method of finding roots -->\r
20 \r
21   <xsl:choose>\r
22     <xsl:when test="$try * $try = $number or $iter > $maxiter">\r
23       <xsl:value-of select="$try"/>\r
24     </xsl:when>\r
25     <xsl:otherwise>\r
26       <xsl:call-template name="sqrt">\r
27         <xsl:with-param name="number" select="$number"/>\r
28         <xsl:with-param name="try" \r
29                         select="$try - (($try * $try - $number) div (2 * $try))"/>\r
30         <xsl:with-param name="iter" select="$iter + 1"/>\r
31         <xsl:with-param name="maxiter" select="$maxiter"/>\r
32       </xsl:call-template>\r
33     </xsl:otherwise>\r
34   </xsl:choose>\r
35 </xsl:template>\r
36 \r
37 </xsl:stylesheet>\r