175 HPReal(
double avalue,
double acorrection)
177 , m_correction(acorrection)
181 Real
value()
const {
return m_value; }
189 *
this = accumulate(v, *
this);
195 *
this = reduce(*
this, v);
201 return value() + correction();
207 return reduce(*
this, b);
213 *
this = product(v, *
this);
219 *
this = product(*
this, v);
225 *
this = div2(v, *
this);
231 *
this = div2(*
this, v);
238 std::istream& assign(std::istream& i);
240 std::ostream& print(std::ostream& o)
const;
242 std::ostream& printPretty(std::ostream& o)
const;
253 return _doQuickTwoSum(x.value(), c);
257 static HPReal reduce(HPReal a, HPReal b)
259 HPReal x(_doTwoSum(a.value(), b.value()));
260 Real c = x.correction() + a.correction() + b.correction();
261 return _doQuickTwoSum(x.value(), c);
265 static HPReal product(HPReal a, HPReal b)
267 HPReal x(_doTwoProducts(a.value(), b.value()));
268 Real w = x.correction() + (a.value() * b.correction() + b.value() * a.correction());
269 return HPReal(x.value(), w);
272 static HPReal product(Real a, HPReal b)
274 HPReal x(_doTwoProducts(a, b.value()));
275 Real w = x.correction() + (a * b.correction());
276 return HPReal(x.value(), w);
283 static HPReal div2(HPReal a, HPReal b)
285 Real c = a.value() / b.value();
286 HPReal u(_doTwoProducts(c, b.value()));
287 Real w = ((((a.value() - u.value()) + -u.correction()) + a.correction()) - c * b.correction()) / b.value();
291 static HPReal div2(Real b, HPReal a)
293 Real c = a.value() / b;
294 HPReal u(_doTwoProducts(c, b));
295 Real w = (((a.value() - u.value()) + -u.correction()) + a.correction()) / b;
305 static HPReal _doTwoSum(Real a, Real b)
308 Real approx_b = value - a;
309 Real sum_error = (a - (value - approx_b)) + (b - approx_b);
310 return HPReal(value, sum_error);
313 static HPReal _doQuickTwoSum(Real a1, Real b1)
317 if (std::abs(b1) > std::abs(a1)) {
322 Real error_value = (b - (value - a));
323 return HPReal(value, error_value);
326 static HPReal _doTwoProducts(Real a, Real b)
329 HPReal aw = SPLIT(a);
330 HPReal bw = SPLIT(b);
331 Real y = aw.correction() * bw.correction() - (((x - aw.value() * bw.value()) - aw.correction() * bw.value()) - aw.value() * bw.correction());
334 static HPReal SPLIT(Real a)
336 const Real f = 134217729;
338 Real x = c - (c - a);