Skip to content

Commit

Permalink
generating and testing the quad-precision constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 14, 2024
1 parent 48edae5 commit eaffec3
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 35 deletions.
76 changes: 42 additions & 34 deletions include/universal/number/qd/qd_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ class qd {

u = quick_two_sum(u, v, v);

double x[4] = { 0.0, 0.0, 0.0, 0.0 };
double c[4] = { 0.0, 0.0, 0.0, 0.0 };
while (k < 4) {
if (i >= 4 && j >= 4) {
x[k] = u;
c[k] = u;
if (k < 3) {
x[++k] = v;
c[++k] = v;
}
break;
}
Expand All @@ -419,16 +419,16 @@ class qd {
double s = quick_three_accumulation(u, v, t);

if (s != 0.0) {
x[k++] = s;
c[k++] = s;
}
}

// add the rest
for (k = i; k < 4; k++) x[3] += a[k];
for (k = j; k < 4; k++) x[3] += b[k];
for (k = i; k < 4; k++) c[3] += a[k];
for (k = j; k < 4; k++) c[3] += b[k];

sw::universal::renorm(x[0], x[1], x[2], x[3]);
return qd(x[0], x[1], x[2], x[3]);
sw::universal::renorm(c[0], c[1], c[2], c[3]);
return qd(c[0], c[1], c[2], c[3]);
}

qd approximate_addition(const qd& a, const qd& b) {
Expand Down Expand Up @@ -1057,35 +1057,43 @@ class qd {

//////////////////////// precomputed constants of note /////////////////////////////////

// precomputed quad-double constants

constexpr qd qd_2pi (6.283185307179586232e+00, 2.449293598294706414e-16);
constexpr qd qd_pi (3.141592653589793116e+00, 1.224646799147353207e-16);
constexpr qd qd_pi2 (1.570796326794896558e+00, 6.123233995736766036e-17);
constexpr qd qd_pi4 (7.853981633974482790e-01, 3.061616997868383018e-17);
constexpr qd qd_3pi4 (2.356194490192344837e+00, 9.1848509936051484375e-17);
constexpr qd qd_e (2.718281828459045091e+00, 1.445646891729250158e-16);
constexpr qd qd_log2 (6.931471805599452862e-01, 2.319046813846299558e-17);
constexpr qd qd_log10 (2.302585092994045901e+00, -2.170756223382249351e-16);

constexpr qd qd_max (1.79769313486231570815e+308, 9.97920154767359795037e+291);
constexpr qd qd_safe_max(1.7976931080746007281e+308, 9.97920154767359795037e+291);


// precomputed quad-double constants courtesy of constants example program

constexpr qd qd_ln2 (0.69314718055994529e+00, 2.3190468138462996e-17);
constexpr qd qd_ln10 (2.30258509299404590e+00, -2.1707562233822494e-16);
constexpr qd qd_lge (1.44269504088896340e+00, 2.0355273740931027e-17);
constexpr qd qd_lg10 (3.32192809488736220e+00, 1.6616175169735918e-16);
constexpr qd qd_loge (0.43429448190325182e+00, 1.0983196502167652e-17);

constexpr qd qd_sqrt2 (1.41421356237309510e+00, -9.6672933134529122e-17);
// Golden ratio PHI
constexpr qd qd_phi (1.6180339887498949, -5.4321152036825061e-17, 2.6543252083815655e-33, -3.3049919975020988e-50);
constexpr qd qd_inv_phi(0.6180339887498949, -5.4321152036825061e-17, 2.6543252083815655e-33, -3.3049919975021111e-50);
// Euler's number e
constexpr qd qd_e (2.7182818284590451, 1.4456468917292502e-16, -2.1277171080381768e-33, 1.515630159841219e-49);
constexpr qd qd_inv_e (0.36787944117144233, -1.2428753672788363e-17, -5.830044851072742e-34, -2.8267977849017436e-50);

// pi multiples and fractions
constexpr qd qd_2pi (6.2831853071795862, 2.4492935982947064e-16, -5.9895396194366793e-33, 2.2249084417267313e-49);
constexpr qd qd_pi (3.1415926535897931, 1.2246467991473532e-16, -2.9947698097183397e-33, 1.1124542208633657e-49);
constexpr qd qd_pi2 (1.5707963267948966, 6.123233995736766e-17, -1.4973849048591698e-33, 5.5622711043168283e-50);
constexpr qd qd_pi4 (0.78539816339744828, 3.061616997868383e-17, -7.4869245242958492e-34, 2.7811355521584142e-50);
constexpr qd qd_3pi4 (2.3561944901923448, 9.1848509936051484e-17, 3.9168984647504003e-33, -2.586798163270486e-49);
constexpr qd qd_inv_pi (0.31830988618379069, -1.9678676675182486e-17, -1.0721436282893004e-33, 8.053563926594112e-50);
constexpr qd qd_inv_pi2(0.63661977236758138, -3.9357353350364972e-17, -2.1442872565786008e-33, 1.6107127853188224e-49);

// natural logarithm (base = e)
constexpr qd qd_ln2 (0.69314718055994529, 2.3190468138462996e-17, 5.7077084384162121e-34, -3.5824322106018105e-50);
constexpr qd qd_lne (1.0, 0.0, 0.0, 0.0);
constexpr qd qd_ln10 (2.3025850929940459, -2.1707562233822494e-16, -9.9842624544657766e-33, -4.0233574544502071e-49);
// binary logarithm (base = 2)
constexpr qd qd_lg2 (1.0, 0.0, 0.0, 0.0);
constexpr qd qd_lge (1.4426950408889634, 2.0355273740931033e-17, -1.0614659956117258e-33, -1.3836716780181395e-50);
constexpr qd qd_lg10 (3.3219280948873622, 1.661617516973592e-16, 1.2215512178458181e-32, 5.9551189702782481e-49);
// common logarithm (base = 10)
constexpr qd qd_log2 (0.3010299956639812, -2.8037281277851704e-18, 5.4719484023146385e-35, 5.1051389831070996e-51);
constexpr qd qd_loge (0.43429448190325182, 1.0983196502167651e-17, 3.717181233110959e-34, 7.7344843465042927e-51);
constexpr qd qd_log10 (1.0, 0.0, 0.0, 0.0);

constexpr qd qd_sqrt2 (1.4142135623730951, -9.6672933134529135e-17, 4.1386753086994136e-33, 4.9355469914683538e-50);
constexpr qd qd_inv_sqrt2(0.70710678118654757, -4.8336466567264567e-17, 2.0693376543497068e-33, 2.4677734957341745e-50);


constexpr qd qd_max(1.79769313486231570815e+308, 9.97920154767359795037e+291);

constexpr qd qd_inv_pi (0.31830988618379069e+00, -1.9678676675182486e-17);
constexpr qd qd_inv_pi2 (0.63661977236758138e+00, -3.9357353350364972e-17);
constexpr qd qd_inv_e (0.36787944117144233e+00, -1.2428753672788364e-17);
constexpr qd qd_inv_sqrt2(0.70710678118654757e+00, -4.8336466567264561e-17);

//////////////////////// helper functions /////////////////////////////////

Expand Down
Loading

0 comments on commit eaffec3

Please sign in to comment.