c - How to distinguish zero from very small number in floating-form -
i develop scientific calculator. question is: how can distinguish 0 result small numbers using float number?
for example, 0.3 - 0.2 - 0.1, result 1e-19, not pure 0 (precision problem, of course). want print out result (0.0). use epsilon comparison zero.
the problem is, calculation: 3e-19 - 2e-19 result should 1e-19. should print out result (though small) 1e-19. if still use epsilon comparison, result forced zero.
so, again, question is: how can check 0 , small numbers?
this inherently not possible if use binary floating point datatype.
instead, if want precise control on numeric precision , rounding, should use decimal number library, example gnu multiprecision (gmp) or boost.multiprecision.
Comments
Post a Comment