Loading...
Searching...
No Matches
gpr::extended Namespace Reference

Namespaces

namespace  directed
namespace  scaled

Classes

struct  DoubleDouble
struct  WorkingPrecision
struct  WorkingPrecision< long double >
struct  WorkingPrecision< DoubleDouble >
struct  FormedFactor
struct  VarianceScaleEnclosure

Typedefs

using WorkingReal

Functions

double modelUnitRoundoff ()
double modelEpsilon ()
void twoSum (double a, double b, double &sum, double &error)
void twoProd (double a, double b, double &product, double &error)
DoubleDouble renorm (double hi, double lo)
DoubleDouble operator+ (DoubleDouble a, DoubleDouble b)
DoubleDouble operator- (DoubleDouble a, DoubleDouble b)
DoubleDouble operator- (DoubleDouble a)
DoubleDouble operator* (DoubleDouble a, DoubleDouble b)
DoubleDouble operator/ (DoubleDouble a, DoubleDouble b)
DoubleDouble & operator+= (DoubleDouble &a, DoubleDouble b)
DoubleDouble & operator-= (DoubleDouble &a, DoubleDouble b)
DoubleDouble & operator*= (DoubleDouble &a, DoubleDouble b)
DoubleDouble & operator/= (DoubleDouble &a, DoubleDouble b)
bool unordered (DoubleDouble a)
bool operator== (DoubleDouble a, DoubleDouble b)
bool operator!= (DoubleDouble a, DoubleDouble b)
bool operator< (DoubleDouble a, DoubleDouble b)
bool operator> (DoubleDouble a, DoubleDouble b)
bool operator<= (DoubleDouble a, DoubleDouble b)
bool operator>= (DoubleDouble a, DoubleDouble b)
DoubleDouble abs (DoubleDouble a)
DoubleDouble sqrt (DoubleDouble a)
bool isfinite (DoubleDouble a)
bool isnan (DoubleDouble a)
constexpr bool nativeLongDoubleIsExtended ()
constexpr bool binary64SupportsDoubleDouble ()
constexpr bool certificationAvailable ()
template<typename Work>
bool workingFinite (Work value)
bool lowLimbFinite (double)
bool lowLimbFinite (long double)
bool lowLimbFinite (const DoubleDouble &value)
template<typename Work>
double roundedToDouble (Work value)
template<typename Work>
double roundDownToDouble (Work value)
template<typename Work>
double roundUpToDouble (Work value)
template<typename Work>
Work directedGammaUpper (long long expression_ops)
template<typename Work>
Work directedUpperBound (Work value, long long expression_ops)
template<typename Work, typename ComputedMatrix, typename AbsMatrix>
Work frobeniusResidualUpperBound (const ComputedMatrix &computed, const AbsMatrix &abs_terms, long long entry_ops)
template<typename Work>
Work formedEntryRelativeFloor ()
template<typename Work>
Work formedEntryAbsoluteError ()
template<typename Work, typename DiagScale, typename Vectors, typename Values>
FormedFactor< Work > formScaledFactor (const DiagScale &diag_scale, const Vectors &evecs_asc, const Values &evals_asc, Eigen::Index rank, int entry_ops)
template<typename Work>
VarianceScaleEnclosure< Work > varianceScaleEnclosure (double y_scale, double calibration)
template<typename Work>
double scaledLowerBound (double value, const VarianceScaleEnclosure< Work > &scale)
template<typename Work>
double scaledUpperBound (double value, const VarianceScaleEnclosure< Work > &scale)
void outwardProduct (double a, double b, double &down, double &up)

Variables

constexpr int kDoubleDoubleUnitRoundoffExp = -104
constexpr int kDoubleDoubleEpsilonExp = -103
constexpr int kDoubleDoubleDigits = 104
constexpr int kDirectedScaleOps = 4

Typedef Documentation

◆ WorkingReal

Initial value:
std::conditional_t<nativeLongDoubleIsExtended(), long double, DoubleDouble>
constexpr bool nativeLongDoubleIsExtended()

Definition at line 275 of file ExtendedReal.h.

Function Documentation

◆ abs()

DoubleDouble gpr::extended::abs ( DoubleDouble a)
inline

Definition at line 214 of file ExtendedReal.h.

215{
216 if (a.hi < 0.0 || (a.hi == 0.0 && a.lo < 0.0))
217 return DoubleDouble(-a.hi, -a.lo);
218 return a;
219}

◆ binary64SupportsDoubleDouble()

bool gpr::extended::binary64SupportsDoubleDouble ( )
inlineconstexpr

Definition at line 251 of file ExtendedReal.h.

252{
253 return std::numeric_limits<double>::digits == 53 &&
254 std::numeric_limits<double>::radix == 2 &&
255 std::numeric_limits<double>::is_iec559;
256}

◆ certificationAvailable()

bool gpr::extended::certificationAvailable ( )
inlineconstexpr

Definition at line 271 of file ExtendedReal.h.

272{
274}
constexpr bool binary64SupportsDoubleDouble()

◆ directedGammaUpper()

template<typename Work>
Work gpr::extended::directedGammaUpper ( long long expression_ops)

Definition at line 545 of file ExtendedReal.h.

546{
547 using Prec = WorkingPrecision<Work>;
548 const long long total = expression_ops + kDirectedScaleOps;
549 if (total <= 0 || total > (1LL << 53))
550 return Work(std::numeric_limits<double>::infinity());
551 const Work k(static_cast<double>(total));
552 const Work u = Prec::unitRoundoff();
553 if (!(k * u < Work(1)))
554 return Work(std::numeric_limits<double>::infinity());
555 return (k * u) / (Work(1) - k * u);
556}
constexpr int kDirectedScaleOps

◆ directedUpperBound()

template<typename Work>
Work gpr::extended::directedUpperBound ( Work value,
long long expression_ops )

Definition at line 563 of file ExtendedReal.h.

564{
565 using Prec = WorkingPrecision<Work>;
566 if (!workingFinite(value))
567 return Work(std::numeric_limits<double>::infinity());
568 if (!(value > Work(0))) return Work(0);
569 return Prec::nextUp(value *
570 (Work(1) + directedGammaUpper<Work>(expression_ops)));
571}
Work directedGammaUpper(long long expression_ops)
bool workingFinite(Work value)

◆ formedEntryAbsoluteError()

template<typename Work>
Work gpr::extended::formedEntryAbsoluteError ( )

Definition at line 806 of file ExtendedReal.h.

807{
808 if constexpr (std::is_same_v<Work, DoubleDouble>)
809 return Work(std::ldexp(1.0, -1068));
810 else
811 return Work(64) * std::numeric_limits<Work>::denorm_min();
812}

◆ formedEntryRelativeFloor()

template<typename Work>
Work gpr::extended::formedEntryRelativeFloor ( )

Definition at line 791 of file ExtendedReal.h.

792{
793 if constexpr (std::is_same_v<Work, DoubleDouble>)
794 return Work(std::ldexp(1.0, -968));
795 else
796 return std::numeric_limits<Work>::min();
797}

◆ formScaledFactor()

template<typename Work, typename DiagScale, typename Vectors, typename Values>
FormedFactor< Work > gpr::extended::formScaledFactor ( const DiagScale & diag_scale,
const Vectors & evecs_asc,
const Values & evals_asc,
Eigen::Index rank,
int entry_ops )

Definition at line 849 of file ExtendedReal.h.

853{
854 using std::abs;
855 using std::sqrt;
856 const Eigen::Index n = evecs_asc.rows();
858 out.B.resize(n, rank);
859 const Work floor2 = Work(2) * formedEntryRelativeFloor<Work>();
860 const Work eta = formedEntryAbsoluteError<Work>();
861 Work allowance(0);
862 bool scaled_norm = false;
863 for (Eigen::Index j = 0; j < rank; ++j) {
864 const Eigen::Index src = n - 1 - j;
865 const Work s = sqrt(evals_asc(src));
866 const bool root_small = abs(evals_asc(src)) < floor2;
867 for (Eigen::Index i = 0; i < n; ++i) {
868 const Work product = diag_scale(i) * evecs_asc(i, src);
869 const Work entry = product * s;
870 out.B(i, j) = entry;
871 if (entry != Work(0)) {
872 const int exponent = scaled::leadingExponent(entry);
873 if (exponent - 1 < scaled::kSafeLow ||
874 exponent > scaled::kSafeHigh)
875 scaled_norm = true;
876 }
877 const bool exact_zero =
878 diag_scale(i) == Work(0) || evecs_asc(i, src) == Work(0);
879 if (exact_zero) continue;
880 const bool product_small = abs(product) < floor2;
881 const bool entry_small = abs(entry) < floor2;
882 if (!(product_small || root_small || entry_small)) continue;
883 out.underflow = true;
884 if (product_small) allowance += Work(2) * abs(s);
885 if (root_small) allowance += Work(2) * (abs(product) + floor2) / s;
886 if (entry_small) allowance += Work(1);
887 }
888 }
889
890 const Work gamma = directedGammaUpper<Work>(entry_ops);
891 if (!(gamma < Work(1))) {
892 out.gram_error = Work(std::numeric_limits<double>::infinity());
893 out.norm = out.gram_error;
894 return out;
895 }
896 const Work gap = Work(1) - gamma;
897 const Work bb = directedUpperBound<Work>(Work(2) * gamma / (gap * gap), 6);
898 if (!out.underflow && !scaled_norm) {
899 out.gram_error = bb * out.B.squaredNorm();
900 out.norm = out.B.norm();
901 return out;
902 }
903
904 const long long entries = static_cast<long long>(out.B.size());
905 const Work dmin = scaled::limbDenormMin<Work>();
906 const Work norm = frobeniusResidualUpperBound<Work>(
907 out.B, decltype(out.B)::Zero(n, rank), 1);
908 const Work H =
910 eta * directedUpperBound<Work>(allowance, entries + 4), 1) +
911 Work(2) * dmin;
912 const Work total = norm + H;
913 const Work relative = directedUpperBound<Work>(bb * total * total, 3);
914 const Work absolute =
915 directedUpperBound<Work>(H * (Work(2) * norm + Work(3) * H), 4);
916 out.gram_error =
917 directedUpperBound<Work>(relative + absolute + Work(4) * dmin, 2);
918 out.norm = norm;
919 out.underflow = true;
920 return out;
921}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
constexpr int kSafeLow
constexpr int kSafeHigh
int leadingExponent(long double value)
Work frobeniusResidualUpperBound(const ComputedMatrix &computed, const AbsMatrix &abs_terms, long long entry_ops)
Work formedEntryAbsoluteError()
DoubleDouble sqrt(DoubleDouble a)
DoubleDouble abs(DoubleDouble a)
Work directedUpperBound(Work value, long long expression_ops)
Work formedEntryRelativeFloor()

◆ frobeniusResidualUpperBound()

template<typename Work, typename ComputedMatrix, typename AbsMatrix>
Work gpr::extended::frobeniusResidualUpperBound ( const ComputedMatrix & computed,
const AbsMatrix & abs_terms,
long long entry_ops )

Definition at line 727 of file ExtendedReal.h.

730{
731 using Prec = WorkingPrecision<Work>;
732 const long long norm_ops = static_cast<long long>(computed.size()) + 2;
733 const Work inf(std::numeric_limits<double>::infinity());
734 const Work u = Prec::unitRoundoff();
735 const Work m(static_cast<double>(entry_ops));
736 if (entry_ops <= 0 || !(m * u < Work(1))) return inf;
737 // Magnitudes, not computed.eval(): Eigen assigns X - A B as X, then
738 // -= A B, which rounds differently from the product the norm of the
739 // expression evaluates on its own.
740 const auto computed_magnitude = computed.cwiseAbs().eval();
741 const auto abs_magnitude = abs_terms.cwiseAbs().eval();
742 const scaled::ScaledNorm<Work> computed_norm =
743 scaled::scaledFrobeniusNorm<Work>(computed_magnitude, norm_ops);
744 const scaled::ScaledNorm<Work> abs_norm =
745 scaled::scaledFrobeniusNorm<Work>(abs_magnitude, norm_ops);
746 const Work gamma_entry = (m * u) / (Work(1) - m * u);
747 const Work head =
748 directedUpperBound<Work>(computed_norm.mantissa, computed_norm.ops);
749 const Work tail = directedUpperBound<Work>(
750 gamma_entry * abs_norm.mantissa, 3 + abs_norm.ops + entry_ops + 1);
751 if (!workingFinite(head) || !workingFinite(tail)) return inf;
752
753 const bool has_head = head > Work(0);
754 const bool has_tail = tail > Work(0);
755 int top = 0;
756 if (has_head && has_tail)
757 top = std::max(computed_norm.exponent, abs_norm.exponent);
758 else if (has_head)
759 top = computed_norm.exponent;
760 else if (has_tail)
761 top = abs_norm.exponent;
762 bool aligned_exact = true;
763 const Work head_at_top =
764 has_head ? scaled::scaleByPowerOfTwo(head, computed_norm.exponent - top,
765 aligned_exact)
766 : Work(0);
767 const Work tail_at_top =
768 has_tail ? scaled::scaleByPowerOfTwo(tail, abs_norm.exponent - top,
769 aligned_exact)
770 : Work(0);
771 Work sum = head_at_top + tail_at_top;
772 long long sum_ops = 1;
773 if (!aligned_exact) {
774 sum += Work(std::ldexp(1.0, -1072));
775 sum_ops = 2;
776 }
777 const Work bound_at_top = directedUpperBound<Work>(sum, sum_ops);
778 if (top == 0) return bound_at_top;
779 bool unscaled_exact = true;
780 const Work bound =
781 scaled::scaleByPowerOfTwo(bound_at_top, top, unscaled_exact);
782 if (!workingFinite(bound)) return inf;
783 if (unscaled_exact) return bound;
784 return Prec::nextUp(bound + Work(2) * scaled::limbDenormMin<Work>());
785}
ScaledNorm< Work > scaledFrobeniusNorm(const Plain &matrix, long long norm_ops)
long double scaleByPowerOfTwo(long double value, int shift, bool &exact)

◆ isfinite()

bool gpr::extended::isfinite ( DoubleDouble a)
inline

Definition at line 234 of file ExtendedReal.h.

235{
236 return std::isfinite(a.hi) && std::isfinite(a.lo);
237}

◆ isnan()

bool gpr::extended::isnan ( DoubleDouble a)
inline

Definition at line 239 of file ExtendedReal.h.

240{
241 return std::isnan(a.hi) || std::isnan(a.lo);
242}

◆ lowLimbFinite() [1/3]

bool gpr::extended::lowLimbFinite ( const DoubleDouble & value)
inline

Definition at line 378 of file ExtendedReal.h.

379{
380 return std::isfinite(value.lo);
381}

◆ lowLimbFinite() [2/3]

bool gpr::extended::lowLimbFinite ( double )
inline

Definition at line 368 of file ExtendedReal.h.

369{
370 return true;
371}

◆ lowLimbFinite() [3/3]

bool gpr::extended::lowLimbFinite ( long double )
inline

Definition at line 373 of file ExtendedReal.h.

374{
375 return true;
376}

◆ modelEpsilon()

double gpr::extended::modelEpsilon ( )
inline

Definition at line 75 of file ExtendedReal.h.

76{
77 return std::ldexp(1.0, kDoubleDoubleEpsilonExp);
78}
constexpr int kDoubleDoubleEpsilonExp

◆ modelUnitRoundoff()

double gpr::extended::modelUnitRoundoff ( )
inline

Definition at line 70 of file ExtendedReal.h.

71{
72 return std::ldexp(1.0, kDoubleDoubleUnitRoundoffExp);
73}
constexpr int kDoubleDoubleUnitRoundoffExp

◆ nativeLongDoubleIsExtended()

bool gpr::extended::nativeLongDoubleIsExtended ( )
inlineconstexpr

Definition at line 244 of file ExtendedReal.h.

245{
246 return std::numeric_limits<long double>::digits > 53 &&
247 std::numeric_limits<long double>::radix == 2 &&
248 std::numeric_limits<long double>::is_iec559;
249}

◆ operator!=()

bool gpr::extended::operator!= ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 187 of file ExtendedReal.h.

188{
189 return !(a == b);
190}

◆ operator*()

DoubleDouble gpr::extended::operator* ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 120 of file ExtendedReal.h.

121{
122 double product, error;
123 twoProd(a.hi, b.hi, product, error);
124 error += a.hi * b.lo;
125 error += a.lo * b.hi;
126 error += a.lo * b.lo;
127 return renorm(product, error);
128}
DoubleDouble renorm(double hi, double lo)
void twoProd(double a, double b, double &product, double &error)

◆ operator*=()

DoubleDouble & gpr::extended::operator*= ( DoubleDouble & a,
DoubleDouble b )
inline

Definition at line 159 of file ExtendedReal.h.

160{
161 a = a * b;
162 return a;
163}

◆ operator+()

DoubleDouble gpr::extended::operator+ ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 101 of file ExtendedReal.h.

102{
103 double sum, error;
104 twoSum(a.hi, b.hi, sum, error);
105 error += a.lo;
106 error += b.lo;
107 return renorm(sum, error);
108}
void twoSum(double a, double b, double &sum, double &error)

◆ operator+=()

DoubleDouble & gpr::extended::operator+= ( DoubleDouble & a,
DoubleDouble b )
inline

Definition at line 147 of file ExtendedReal.h.

148{
149 a = a + b;
150 return a;
151}

◆ operator-() [1/2]

DoubleDouble gpr::extended::operator- ( DoubleDouble a)
inline

Definition at line 115 of file ExtendedReal.h.

116{
117 return DoubleDouble(-a.hi, -a.lo);
118}

◆ operator-() [2/2]

DoubleDouble gpr::extended::operator- ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 110 of file ExtendedReal.h.

111{
112 return a + DoubleDouble(-b.hi, -b.lo);
113}

◆ operator-=()

DoubleDouble & gpr::extended::operator-= ( DoubleDouble & a,
DoubleDouble b )
inline

Definition at line 153 of file ExtendedReal.h.

154{
155 a = a - b;
156 return a;
157}

◆ operator/()

DoubleDouble gpr::extended::operator/ ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 130 of file ExtendedReal.h.

131{
132 if (b.hi == 0.0) {
133 const double quotient = a.hi / b.hi;
134 return DoubleDouble(quotient, 0.0);
135 }
136 const double q1 = a.hi / b.hi;
137 DoubleDouble remainder = a - DoubleDouble(q1) * b;
138 const double q2 = remainder.hi / b.hi;
139 remainder = remainder - DoubleDouble(q2) * b;
140 const double q3 = remainder.hi / b.hi;
141 double sum, error;
142 twoSum(q1, q2, sum, error);
143 error += q3;
144 return renorm(sum, error);
145}

◆ operator/=()

DoubleDouble & gpr::extended::operator/= ( DoubleDouble & a,
DoubleDouble b )
inline

Definition at line 165 of file ExtendedReal.h.

166{
167 a = a / b;
168 return a;
169}

◆ operator<()

bool gpr::extended::operator< ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 192 of file ExtendedReal.h.

193{
194 if (unordered(a) || unordered(b)) return false;
195 if (a.hi != b.hi) return a.hi < b.hi;
196 return std::isfinite(a.hi) && a.lo < b.lo;
197}
bool unordered(DoubleDouble a)

◆ operator<=()

bool gpr::extended::operator<= ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 204 of file ExtendedReal.h.

205{
206 return a < b || a == b;
207}

◆ operator==()

bool gpr::extended::operator== ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 181 of file ExtendedReal.h.

182{
183 if (unordered(a) || unordered(b)) return false;
184 return a.hi == b.hi && (!std::isfinite(a.hi) || a.lo == b.lo);
185}

◆ operator>()

bool gpr::extended::operator> ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 199 of file ExtendedReal.h.

200{
201 return b < a;
202}

◆ operator>=()

bool gpr::extended::operator>= ( DoubleDouble a,
DoubleDouble b )
inline

Definition at line 209 of file ExtendedReal.h.

210{
211 return b < a || a == b;
212}

◆ outwardProduct()

void gpr::extended::outwardProduct ( double a,
double b,
double & down,
double & up )
inline

Definition at line 1007 of file ExtendedReal.h.

1008{
1009 down = directed::mulDown(a, b);
1010 up = directed::mulUp(a, b);
1011}
double mulUp(double a, double b)
double mulDown(double a, double b)

◆ renorm()

DoubleDouble gpr::extended::renorm ( double hi,
double lo )
inline

Definition at line 94 of file ExtendedReal.h.

95{
96 double sum, error;
97 twoSum(hi, lo, sum, error);
98 return DoubleDouble(sum, error);
99}

◆ roundDownToDouble()

template<typename Work>
double gpr::extended::roundDownToDouble ( Work value)

Definition at line 395 of file ExtendedReal.h.

396{
397 double result = roundedToDouble(value);
398 if (static_cast<Work>(result) > value)
399 result =
400 std::nextafter(result, -std::numeric_limits<double>::infinity());
401 return result;
402}
double roundedToDouble(Work value)

◆ roundedToDouble()

template<typename Work>
double gpr::extended::roundedToDouble ( Work value)

Definition at line 384 of file ExtendedReal.h.

385{
386 const double result = static_cast<double>(value);
387 if (std::isnan(result) || !lowLimbFinite(value))
388 throw std::range_error(
389 "a working-precision value is not finite and has no binary64 "
390 "bound");
391 return result;
392}
bool lowLimbFinite(double)

◆ roundUpToDouble()

template<typename Work>
double gpr::extended::roundUpToDouble ( Work value)

Definition at line 405 of file ExtendedReal.h.

406{
407 double result = roundedToDouble(value);
408 if (static_cast<Work>(result) < value)
409 result =
410 std::nextafter(result, std::numeric_limits<double>::infinity());
411 return result;
412}

◆ scaledLowerBound()

template<typename Work>
double gpr::extended::scaledLowerBound ( double value,
const VarianceScaleEnclosure< Work > & scale )

Definition at line 963 of file ExtendedReal.h.

964{
965 if (std::isnan(value))
966 throw std::range_error("a NaN has no scaled binary64 bound");
967 if (value == 0.0 || std::isinf(value)) return value == 0.0 ? 0.0 : value;
968 using Prec = WorkingPrecision<Work>;
969 const Work factor = value > 0.0 ? scale.lower : scale.upper;
970 const Work product = Work(value) * factor;
971 if (!workingFinite(product))
972 return value > 0.0 ? std::numeric_limits<double>::max()
973 : -std::numeric_limits<double>::infinity();
974 const Work below = Prec::nextDown(product);
975 if (!workingFinite(below))
976 return value > 0.0 ? std::numeric_limits<double>::max()
977 : -std::numeric_limits<double>::infinity();
978 const double bound = roundDownToDouble<Work>(below);
979 return value > 0.0 && std::signbit(bound) ? 0.0 : bound;
980}
double roundDownToDouble(Work value)
STL namespace.

◆ scaledUpperBound()

template<typename Work>
double gpr::extended::scaledUpperBound ( double value,
const VarianceScaleEnclosure< Work > & scale )

Definition at line 983 of file ExtendedReal.h.

984{
985 if (std::isnan(value))
986 throw std::range_error("a NaN has no scaled binary64 bound");
987 if (value == 0.0 || std::isinf(value)) return value == 0.0 ? 0.0 : value;
988 using Prec = WorkingPrecision<Work>;
989 const Work factor = value > 0.0 ? scale.upper : scale.lower;
990 const Work product = Work(value) * factor;
991 if (!workingFinite(product))
992 return value > 0.0 ? std::numeric_limits<double>::infinity()
993 : std::numeric_limits<double>::lowest();
994 const Work above = Prec::nextUp(product);
995 if (!workingFinite(above))
996 return value > 0.0 ? std::numeric_limits<double>::infinity()
997 : std::numeric_limits<double>::lowest();
998 const double bound = roundUpToDouble<Work>(above);
999 return value < 0.0 && !std::signbit(bound) ? -0.0 : bound;
1000}
double roundUpToDouble(Work value)

◆ sqrt()

DoubleDouble gpr::extended::sqrt ( DoubleDouble a)
inline

Definition at line 221 of file ExtendedReal.h.

222{
223 if (!(a.hi > 0.0)) {
224 if (a.hi == 0.0 && a.lo == 0.0) return DoubleDouble(0.0);
225 return DoubleDouble(std::numeric_limits<double>::quiet_NaN(), 0.0);
226 }
227 const double root = std::sqrt(a.hi);
228 const DoubleDouble correction =
229 (a - DoubleDouble(root) * DoubleDouble(root)) /
230 DoubleDouble(2.0 * root);
231 return DoubleDouble(root) + correction;
232}

◆ twoProd()

void gpr::extended::twoProd ( double a,
double b,
double & product,
double & error )
inline

Definition at line 88 of file ExtendedReal.h.

89{
90 product = a * b;
91 error = std::fma(a, b, -product);
92}

◆ twoSum()

void gpr::extended::twoSum ( double a,
double b,
double & sum,
double & error )
inline

Definition at line 80 of file ExtendedReal.h.

81{
82 sum = a + b;
83 const double b_virtual = sum - a;
84 const double a_virtual = sum - b_virtual;
85 error = (a - a_virtual) + (b - b_virtual);
86}

◆ unordered()

bool gpr::extended::unordered ( DoubleDouble a)
inline

Definition at line 176 of file ExtendedReal.h.

177{
178 return std::isnan(a.hi) || !std::isfinite(a.lo);
179}

◆ varianceScaleEnclosure()

template<typename Work>
VarianceScaleEnclosure< Work > gpr::extended::varianceScaleEnclosure ( double y_scale,
double calibration )

Definition at line 935 of file ExtendedReal.h.

937{
938 using Prec = WorkingPrecision<Work>;
940 if (!std::isfinite(y_scale) || !(y_scale > 0.0) ||
941 !std::isfinite(calibration) || !(calibration > 0.0))
942 return out;
943 const Work y(y_scale);
944 const Work square = y * y;
945 const Work c(calibration);
946 out.lower = Prec::nextDown(Prec::nextDown(square) * c);
947 out.upper = Prec::nextUp(Prec::nextUp(square) * c);
948 out.valid = out.lower > Work(0) && workingFinite(out.upper);
949 return out;
950}
@ y
Definition Enums.h:28

◆ workingFinite()

template<typename Work>
bool gpr::extended::workingFinite ( Work value)

Definition at line 356 of file ExtendedReal.h.

357{
358 using std::isfinite;
359 return isfinite(value);
360}
bool isfinite(DoubleDouble a)

Variable Documentation

◆ kDirectedScaleOps

int gpr::extended::kDirectedScaleOps = 4
inlineconstexpr

Definition at line 353 of file ExtendedReal.h.

◆ kDoubleDoubleDigits

int gpr::extended::kDoubleDoubleDigits = 104
inlineconstexpr

Definition at line 68 of file ExtendedReal.h.

◆ kDoubleDoubleEpsilonExp

int gpr::extended::kDoubleDoubleEpsilonExp = -103
inlineconstexpr

Definition at line 67 of file ExtendedReal.h.

◆ kDoubleDoubleUnitRoundoffExp

int gpr::extended::kDoubleDoubleUnitRoundoffExp = -104
inlineconstexpr

Definition at line 66 of file ExtendedReal.h.