c - Rounding a double to avoid round off in subsequent summation -
how implement this?
// round nearest double x + ref doesn't cause round off error double round(double x, double ref) { }
so that
double x = ....; double y = ....; double x_new = round(x, y); return x_new + y; // no round off!
in other terms (y + x_new) - x_new strictly equal y
let assume x
, y
both positive.
let s
double-precision sum x + y
.
there 2 cases:
if
x
≤y
,s - y
exact sterbenz's lemma. follows addition(s - y) + y
exact (it producess
, double-precision number). therefore, can picks - y
x_new
. noty + x_new
exact, produces same results
y + x
.if
x
>y
, depending on number of bits set in significand ofy
, may have problem. if last bit in significand ofy
set, instance, no numberz
in binade after binade ofy
can have propertyz + y
exact.
this answer vaguely related that answer.
Comments
Post a Comment