summaryrefslogtreecommitdiff
path: root/old/dw/html/rounding-errors.html
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-01-01 23:40:52 +0100
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-01-01 23:40:52 +0100
commit5ea943a5e789222472e45864e119cf786498bfcd (patch)
treeea307589de0fdb202474ad4d07c0bef7fe1c53e8 /old/dw/html/rounding-errors.html
Import original dillo.org website into old/
Diffstat (limited to 'old/dw/html/rounding-errors.html')
-rw-r--r--old/dw/html/rounding-errors.html74
1 files changed, 74 insertions, 0 deletions
diff --git a/old/dw/html/rounding-errors.html b/old/dw/html/rounding-errors.html
new file mode 100644
index 0000000..72814fa
--- /dev/null
+++ b/old/dw/html/rounding-errors.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<meta http-equiv="X-UA-Compatible" content="IE=9"/>
+<meta name="generator" content="Doxygen 1.8.8"/>
+<title>Dillo: How to Avoid Rounding Errors</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<script type="text/javascript" src="https://www.dillo.org/dw/html/jquery.js"></script>
+<script type="text/javascript" src="dynsections.js"></script>
+<link href="doxygen.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
+<div id="titlearea">
+<table cellspacing="0" cellpadding="0">
+ <tbody>
+ <tr style="height: 56px;">
+ <td style="padding-left: 0.5em;">
+ <div id="projectname">Dillo
+ </div>
+ </td>
+ </tr>
+ </tbody>
+</table>
+</div>
+<!-- end header part -->
+<!-- Generated by Doxygen 1.8.8 -->
+ <div id="navrow1" class="tabs">
+ <ul class="tablist">
+ <li><a href="index.html"><span>Main&#160;Page</span></a></li>
+ <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
+ <li><a href="namespaces.html"><span>Namespaces</span></a></li>
+ <li><a href="annotated.html"><span>Classes</span></a></li>
+ <li><a href="files.html"><span>Files</span></a></li>
+ </ul>
+ </div>
+</div><!-- top -->
+<div class="header">
+ <div class="headertitle">
+<div class="title">How to Avoid Rounding Errors </div> </div>
+</div><!--header-->
+<div class="contents">
+<div class="textblock"><p>(Probably, this is a standard algorithm, so if someone knows the name, drop me a note.)</p>
+<p>If something like</p>
+<p class="formulaDsp">
+<img class="formulaDsp" alt="\[y_i = {x_i a \over b}\]" src="form_49.png"/>
+</p>
+<p>is to be calculated, and all numbers are integers, a naive implementation would result in something, for which</p>
+<p class="formulaDsp">
+<img class="formulaDsp" alt="\[\sum y_i \ne {(\sum x_i) a \over b}\]" src="form_50.png"/>
+</p>
+<p>because of rounding errors, due to the integer division. This can be avoided by transforming the formula into</p>
+<p class="formulaDsp">
+<img class="formulaDsp" alt="\[y_i = {(\sum_{j=0}^{j=i} x_j) a \over b} - \sum_{j=0}^{j=i-1} y_j\]" src="form_51.png"/>
+</p>
+<p>Of corse, when all <img class="formulaInl" alt="$y_i$" src="form_8.png"/> are calculated in a sequence, <img class="formulaInl" alt="$\sum_{j=0}^{j=i} x_j$" src="form_52.png"/> and <img class="formulaInl" alt="$\sum_{j=0}^{j=i-1} y_j$" src="form_53.png"/> can be accumulated in the same loop. Regard this as sample:</p>
+<div class="fragment"><div class="line"><span class="keywordtype">int</span> n, x[n], a, b; <span class="comment">// Should all be initialized.</span></div>
+<div class="line"><span class="keywordtype">int</span> y[n], cumX = 0, cumY = 0;</div>
+<div class="line"></div>
+<div class="line"><span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; n; i++) {</div>
+<div class="line"> cumX += x[i]</div>
+<div class="line"> y[i] = (cumX * a) / b - cumY;</div>
+<div class="line"> cumY += y[i];</div>
+<div class="line">}</div>
+</div><!-- fragment --> </div></div><!-- contents -->
+<!-- start footer part -->
+<hr class="footer"/><address class="footer"><small>
+Generated on Sat May 28 2016 11:47:43 for Dillo by &#160;<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/>
+</a> 1.8.8
+</small></address>
+</body>
+</html>