I was just reading about rounding errors in C++. So, if I’m making a math intense program (or any important calculations) should I just drop floats all together and use only doubles or is there an easier way to prevent rounding errors?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Obligatory lecture: What Every Programmer Should Know About Floating-Point Arithmetic.
Also, try reading IEEE Floating Point standard.
You’ll always get rounding errors. Unless you use an
infinitearbitrary precision library, like gmplib. You have to decide if your application really needs this kind of effort.Or, you could use integer arithmetic, converting to floats only when needed. This is still hard to do, you have to decide if it’s worth it.
Lastly, you can use
floatordoubletaking care not to make assumption about values at the limit of representation’s precision. I’d wish this Valgrind plugin was implemented (grep for float)…