java - precision of a sum of double in jvm -


i have tests assert sum of values equal expected results. these sum not value, need put precision. logical sum([a, a, a, ...n-times..., a]) != n*a.

but instead of putting arbitrary precision, know expected bound. how can compute such bound?

in specific case lead question, sum n zeros , k ones (which obtained computing difference of doubles, v1-v2). should equals k +- precision.

so precision should used?

  • k * 10e-15
  • (n+k) * 10e-15

i guess 10e-15 depends on values added: 0 , 1 here


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -