c++ - Floating point equality and tolerances -


comparing 2 floating point number a_float == b_float looking trouble since a_float / 3.0 * 3.0 might not equal a_float due round off error.

what 1 fabs(a_float - b_float) < tol.

how 1 calculate tol?

ideally tolerance should larger value of 1 or 2 of least significant figures. if single precision floating point number use tol = 10e-6 should right. not work general case a_float might small or might large.

how 1 calculate tol correctly general cases? interested in c or c++ cases specifically.

this blogpost contains example, foolproof implementation, , detailed theory behind http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ 1 of series, can read more. in short: use ulp numbers, use epsilon numbers near zero, there still caveats. if want sure floating point math recommend reading whole series.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -