Estimate recip(const Estimate &arg) { if (!arg.IsNonZero()) throw PrecisionException("recip"); LongFloat r(arg.m_Value.recip()); ErrorEstimate e(arg.m_Value, ErrorEstimate::Down); ErrorEstimate re(RoundingError(r, r.DivisionRoundingError())); return Estimate(r, (arg.m_Error / (e - arg.m_Error) / e) + re); // multiplication in denominator would have the wrong rounding mode }
Estimate operator / (const Estimate &lhs, const Estimate &rhs) { if (!rhs.IsNonZero()) throw PrecisionException("division"); // this also assures e - rhs.m_Error > 0 LongFloat r(lhs.m_Value / rhs.m_Value); ErrorEstimate e(rhs.m_Value, ErrorEstimate::Down); ErrorEstimate n(ErrorEstimate(lhs.m_Value) * rhs.m_Error + ErrorEstimate(rhs.m_Value, ErrorEstimate::Up) * lhs.m_Error); return Estimate(r, n / (e - rhs.m_Error) / e + RoundingError(r, r.DivisionRoundingError())); // multiplication in denominator would have the wrong rounding mode }