Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

One important property of IEEE floating-point math that rounding causes "errors" in calculations due to the limited number of bits and the base-2 format.

E.g. in C#:

(Math.PI * 1e20 / 1e20) == Math.PI; // false

Is there a way to determine the magnitude of the error of those operations? .NET exposes the Double.Epsilon field that give the smallest significant value greater than zero, but that's not relevant for comparing non-zero numbers.

EDIT: I'm not asking for a way to exactly compute the error, I'm just trying to find a way to estimate its magnitude.

For example (again, in C#):

(1e20 + 1e3) == 1e20; // true
(1e20 + 1e4) == 1e20; // false

So the error of the operation 1e20 + X appears to be approximately 1e3, which makes sense because doubles have up to 17 digits of decimal precision.

share|improve this question
add comment

1 Answer

What you need is the machine epsilon (which you can calculate) not the smallest (denorm) positive number: see http://www.johndcook.com/blog/2010/06/08/c-math-gotchas/ for the bizarre naming convention.

Once you have the machine epsilon, you know (from the IEEE standard) that any basic algebraic operation *, +, /, -, has a relative error of at most epsilon, i.e. x flop y = (x op y)(1+delta) where:

  • flop is the floating point operation, e.g. a floating-point add
  • op is the corresponding operation in real arithmetic
  • delta is the relative roundoff error and is bounded by |delta| <= epsilon
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["        <li><a href=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2013 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc-wiki</a> \r\n with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"footer-flair\">\r\n                <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" class=\"cc-wiki-link\"></a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2013.12.5.1201\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflo", "ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2013 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc-wiki</a> \r\n with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"footer-flair\">\r\n                <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" class=\"cc-wiki-link\"></a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2013.12.5.1201\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </noscript>\r\n<script type=\"text/javascript\">var p = \"http\", d = \"static\"; if (document.location.protocol == \"https:\") { p += \"s\"; d = \"engine\"; } var"], "copyright__copyright__copyright": ["or of at most epsilon, i.e. x flop y = (x op y)(1+delta) where:\n\n  \u2022 flop is the floating point operation, e.g. a floating-point add\n  \u2022 op is the corresponding operation in real arithmetic\n  \u2022 delta is the relative roundoff error and is bounded by |delta| <= epsilon\nshare|improve this answer\nadd comment\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}