Minimize Floating Point Roundoff Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the floating point error example workings and policies of this site About Us Learn more about Stack floating point rounding error Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs rounding error example Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them;
What Every Computer Scientist Should Know About Floating-point Arithmetic
it only takes a minute: Sign up How to reduce C/C++ floating-point roundoff up vote 1 down vote favorite 1 Are there any generally-applicable tips to reduce the accumulation of floating-point roundoff errors in C or C++? I'm thinking mainly about how to write code that gets compiled into optimal assembly language instructions, although strategies on overall algorithm design catastrophic cancellation are also welcome. c++ c floating-point floating-accuracy share|improve this question edited Sep 19 '12 at 8:21 Pascal Cuoq 58.6k5101194 asked Sep 19 '12 at 2:13 1'' 9,2981566143 1 Please explain how 2/3 is imprecise in C/C++ but precise in assembly ;-) --- but you may want to look into things like the GMP library; see eg stackoverflow.com/questions/6414714/… –Dirk Eddelbuettel Sep 19 '12 at 2:15 I've edited for clarity. I'm not concerned about the absolute precision of floating-point numbers (which is limited by the IEEE standard and the fact that only powers of 2 can be accurately represented as floats), but rather the accumulation of floating-point roundoff errors in, for instance, loops that run millions of times. –1'' Sep 19 '12 at 2:19 3 First, read What Every Computer Scientist Should Know About Floating-Point Arithmetic, a classic, a must-read. There exist a few algorithms for specific problems like Kahan summation algorithm. That's the starting point. And then in C(++) there's a danger that some of floating-point operations can be carried out in higher
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn floating point precision more about Stack Overflow the company Business Learn more about hiring developers or
Truncation Error
posting ads with us Programmers Questions Tags Users Badges Unanswered Ask Question _ Programmers Stack Exchange is a question and
Floating Point Representation
answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer http://stackoverflow.com/questions/12487659/how-to-reduce-c-c-floating-point-roundoff The best answers are voted up and rise to the top Solutions for floating point rounding errors up vote 10 down vote favorite 4 In building an application that deals with a lot of mathematical calculations, I have encountered the problem that certain numbers cause rounding errors. While I understand that floating point is not exact, the problem is how do I deal with exact numbers to http://programmers.stackexchange.com/questions/202843/solutions-for-floating-point-rounding-errors make sure that when calculations are preformed on them floating point rounding doesn't cause any issues? software software-developer design numeric-precision floating-point share|improve this question edited Jul 12 '13 at 15:29 asked Jun 26 '13 at 16:38 JNL 6031717 2 Is there a specific problem you are facing? There are many ways to do testing, all right for some problem. Questions that can have multiple answers are a poor fit for the Q&A format. It would be best if you could define the problem you are having in a way that could have one right answer rather than casting a net for ideas and recommendations. –user40980 Jun 26 '13 at 16:40 I am building a Software Application with lot of mathematical caluclations. I understand NUNIT or JUNIT testing would be good, but would love to have an idea on how to approach the issues with Mathematical Calulations. –JNL Jun 26 '13 at 16:42 1 Can you give an example of a calculation you would be testing? One typically wouldn't be unit testing raw math (unless you are testing your own numerical types), but testing something like distanceTraveled(startVel, duration, acceleration) would be tested. –user40980 Jun 26
general: Multiplication and division are “safe” operations Addition and http://floating-point-gui.de/errors/propagation/ subtraction are dangerous, because when numbers of different magnitudes are involved, digits of the smaller-magnitude number are lost. This loss of digits can https://support.microsoft.com/en-us/kb/214118 be inevitable and benign (when the lost digits also insignificant for the final result) or catastrophic (when the loss is magnified and distorts floating point the result strongly). The more calculations are done (especially when they form an iterative algorithm) the more important it is to consider this kind of problem. A method of calculation can be stable (meaning that it tends to reduce rounding errors) or unstable (meaning that minimize floating point rounding errors are magnified). Very often, there are both stable and unstable solutions for a problem. There is an entire sub-field of mathematics (in numerical analysis) devoted to studying the numerical stability of algorithms. For doing complex calculations involving floating-point numbers, it is absolutely necessary to have some understanding of this discipline. The article What Every Computer Scientist Should Know About Floating-Point Arithmetic gives a detailed introduction, and served as an inspiration for creating this website, mainly due to being a bit too detailed and intimidating to programmers without a scientific background. © Published at floating-point-gui.de under the Creative Commons Attribution License (BY) The Floating-Point Guide Home Basic Answers References xkcd Number Formats Binary Fractions Floating-Point Exact Types On Using Integers Errors Rounding Comparison Propagation Languagecheat sheets C# Java JavaScript Perl PHP Python Ruby SQL
360 games PC games Windows games Windows phone games Entertainment All Entertainment Movies & TV Music Business & Education Business Students & educators Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security Internet Explorer Microsoft Edge Skype OneNote OneDrive Microsoft Health MSN Bing Microsoft Groove Microsoft Movies & TV Devices & Xbox All Microsoft devices Microsoft Surface All Windows PCs & tablets PC accessories Xbox & games Microsoft Lumia All Windows phones Microsoft HoloLens For business Cloud Platform Microsoft Azure Microsoft Dynamics Windows for business Office for business Skype for business Surface for business Enterprise solutions Small business solutions Find a solutions provider Volume Licensing For developers & IT pros Develop Windows apps Microsoft Azure MSDN TechNet Visual Studio For students & educators Office for students OneNote in classroom Shop PCs & tablets perfect for students Microsoft in Education Support Sign in Cart Cart Javascript is disabled Please enable javascript and refresh the page Cookies are disabled Please enable cookies and refresh the page CV: {{ getCv() }} English (United States) Terms of use Privacy & cookies Trademarks © 2016 Microsoft