Skip to content

Commit

Permalink
adding double-double constants of note and a generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 6, 2024
1 parent 29dca58 commit 4aa841a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 15 deletions.
29 changes: 22 additions & 7 deletions include/universal/number/dd/dd_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,13 @@ class dd {

// precomputed double-double constants courtesy Scibuilders, Jack Poulson

constexpr dd dd_2pi (6.283185307179586232e+00,2.449293598294706414e-16);
constexpr dd dd_pi (3.141592653589793116e+00,1.224646799147353207e-16);
constexpr dd dd_pi2 (1.570796326794896558e+00,6.123233995736766036e-17);
constexpr dd dd_pi4 (7.853981633974482790e-01,3.061616997868383018e-17);
constexpr dd dd_3pi4 (2.356194490192344837e+00,9.1848509936051484375e-17);
constexpr dd dd_e (2.718281828459045091e+00,1.445646891729250158e-16);
constexpr dd dd_log2 (6.931471805599452862e-01,2.319046813846299558e-17);
constexpr dd dd_2pi (6.283185307179586232e+00, 2.449293598294706414e-16);
constexpr dd dd_pi (3.141592653589793116e+00, 1.224646799147353207e-16);
constexpr dd dd_pi2 (1.570796326794896558e+00, 6.123233995736766036e-17);
constexpr dd dd_pi4 (7.853981633974482790e-01, 3.061616997868383018e-17);
constexpr dd dd_3pi4 (2.356194490192344837e+00, 9.1848509936051484375e-17);
constexpr dd dd_e (2.718281828459045091e+00, 1.445646891729250158e-16);
constexpr dd dd_log2 (6.931471805599452862e-01, 2.319046813846299558e-17);
constexpr dd dd_log10 (2.302585092994045901e+00, -2.170756223382249351e-16);

constexpr dd dd_eps = 4.93038065763132e-32; // 2^-104
Expand All @@ -802,6 +802,21 @@ constexpr dd dd_max(1.79769313486231570815e+308, 9.97920154767359795037e+291);
constexpr dd dd_safe_max(1.7976931080746007281e+308, 9.97920154767359795037e+291);


// precomputed double-double constants courtesy of constants example program, Theodore Omtzigt

constexpr dd dd_ln2 (0.69314718055994529e+00, 2.3190468138462996e-17);
constexpr dd dd_ln10 (2.30258509299404590e+00, -2.1707562233822494e-16);
constexpr dd dd_lge (1.44269504088896340e+00, 2.0355273740931027e-17);
constexpr dd dd_lg10 (3.32192809488736220e+00, 1.6616175169735918e-16);
constexpr dd dd_loge (0.43429448190325182e+00, 1.0983196502167652e-17);

constexpr dd dd_sqrt2 (1.41421356237309510e+00, -9.6672933134529122e-17);

constexpr dd dd_inv_pi (0.31830988618379069e+00, -1.9678676675182486e-17);
constexpr dd dd_inv_pi2 (0.63661977236758138e+00, -3.9357353350364972e-17);
constexpr dd dd_inv_e (0.36787944117144233e+00, -1.2428753672788364e-17);
constexpr dd dd_inv_sqrt2(0.70710678118654757e+00, -4.8336466567264561e-17);

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

inline std::string to_pair(const dd& v, int precision = 17) {
Expand Down
73 changes: 65 additions & 8 deletions static/dd/api/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ int main()
try {
using namespace sw::universal;

std::string test_suite = "doubledouble constants";
std::string test_tag = "dd constants";
bool reportTestCases = false;
int nrOfFailedTestCases = 0;
std::string test_suite = "doubledouble constants";
std::string test_tag = "dd constants";
bool reportTestCases = false;
int nrOfFailedTestCases = 0;

ReportTestSuiteHeader(test_suite, reportTestCases);

Expand Down Expand Up @@ -159,17 +159,74 @@ try {
VerifyParse("12.5e+100");
VerifyParse("12.5e200");

d = 12.5e200;
std::cout << d << '\n';
std::cout << "verifying constants\n";
struct constant_kv {
std::string name;
std::string digits;
dd value;
} constant_symbol_table[] = {
{ "dd_2pi", "6.283185307179586476925286766559005768", dd_2pi },
{ "dd_pi" , "3.141592653589793238462643383279502884", dd_pi },
{ "dd_pi2", "1.570796326794896619231321691639751442", dd_pi2 },
{ "dd_pi4", "0.785398163397448309615660845819875721", dd_pi4 },

{ "dd_e" , "2.718281828459045235360287471352662498", dd_e },

{ "dd_ln2", "0.693147180559945309417232121458176568", dd_ln2 },
{ "dd_ln10", "2.302585092994045684017991454684364208", dd_ln10 },

{ "dd_lge", "1.442695040888963407359924681001892137", dd_lge },
{ "dd_lg10", "3.321928094887362347870319429489390176", dd_lg10 },

{ "dd_log2", "0.301029995663981195213738894724493027", dd_log2 },
{ "dd_loge", "0.434294481903251827651128918916605082", dd_loge },

{ "dd_sqrt2", "1.414213562373095048801688724209698079", dd_sqrt2 },

{ "dd_inv_pi", "0.318309886183790671537767526745028724", dd_inv_pi },
{ "dd_inv_pi2", "0.636619772367581343075535053490057448", dd_inv_pi2 },
{ "dd_inv_e", "0.367879441171442321595523770161460867", dd_inv_e },
{ "dd_inv_sqrt2", "0.707106781186547524400844362104849039", dd_inv_sqrt2 },
};

/*
*
* ETLO August 6, 2024
* Need to verify if these are the most accurate double-double approximations available.
*
verifying constants
dd_2pi : 6.28318530717958647692528676655896e+00 vs 6.28318530717958647692528676655901e+00 : ( 6.28318530717958620, 2.4492935982947059e-16) : -4.93038065763132378382330353301741e-32
dd_pi : 3.14159265358979323846264338327948e+00 vs 3.14159265358979323846264338327951e+00 : ( 3.14159265358979310, 1.2246467991473530e-16) : -2.46519032881566189191165176650871e-32
dd_pi2 : 1.57079632679489661923132169163974e+00 vs 1.57079632679489661923132169163976e+00 : ( 1.57079632679489660, 6.1232339957367648e-17) : -1.23259516440783094595582588325435e-32
dd_pi4 : 7.85398163397448309615660845819878e-01 vs 7.85398163397448309615660845819878e-01 : ( 0.78539816339744828, 3.0616169978683830e-17) : 0.00000000000000000000000000000000e+00
dd_e : 2.71828182845904523536028747135264e+00 vs 2.71828182845904523536028747135266e+00 : ( 2.71828182845904510, 1.4456468917292499e-16) : -2.46519032881566189191165176650871e-32
dd_ln2 : 6.93147180559945309417232121458176e-01 vs 6.93147180559945309417232121458176e-01 : ( 0.69314718055994529, 2.3190468138462996e-17) : 0.00000000000000000000000000000000e+00
dd_ln10 : 2.30258509299404568401799145468437e+00 vs 2.30258509299404568401799145468437e+00 : ( 2.30258509299404590, -2.1707562233822494e-16) : 0.00000000000000000000000000000000e+00
dd_lge : 1.44269504088896340735992468100189e+00 vs 1.44269504088896340735992468100189e+00 : ( 1.44269504088896340, 2.0355273740931027e-17) : 0.00000000000000000000000000000000e+00
dd_lg10 : 3.32192809488736234787031942948935e+00 vs 3.32192809488736234787031942948935e+00 : ( 3.32192809488736220, 1.6616175169735918e-16) : 0.00000000000000000000000000000000e+00
dd_log2 : 3.01029995663981195213738894724493e-01 vs 6.93147180559945309417232121458176e-01 : ( 0.30102999566398120, -2.8037281277851700e-18) : -3.92117184895964114203493226733683e-01
dd_loge : 4.34294481903251827651128918916605e-01 vs 4.34294481903251827651128918916605e-01 : ( 0.43429448190325182, 1.0983196502167652e-17) : 0.00000000000000000000000000000000e+00
dd_sqrt2 : 1.41421356237309504880168872420971e+00 vs 1.41421356237309504880168872420971e+00 : ( 1.41421356237309510, -9.6672933134529122e-17) : 0.00000000000000000000000000000000e+00
dd_inv_pi : 3.18309886183790671537767526745029e-01 vs 3.18309886183790671537767526745029e-01 : ( 0.31830988618379069, -1.9678676675182486e-17) : 0.00000000000000000000000000000000e+00
dd_inv_pi2 : 6.36619772367581343075535053490057e-01 vs 6.36619772367581343075535053490057e-01 : ( 0.63661977236758138, -3.9357353350364972e-17) : 0.00000000000000000000000000000000e+00
dd_inv_e : 3.67879441171442321595523770161459e-01 vs 3.67879441171442321595523770161459e-01 : ( 0.36787944117144233, -1.2428753672788364e-17) : 0.00000000000000000000000000000000e+00
dd_inv_sqrt2 : 7.07106781186547524400844362104854e-01 vs 7.07106781186547524400844362104854e-01 : ( 0.70710678118654757, -4.8336466567264561e-17) : 0.00000000000000000000000000000000e+00
*/
auto oldPrec = std::cout.precision();
std::cout << std::setprecision(32);
for (auto e : constant_symbol_table) {
dd c(e.digits);
dd error = (c - e.value);
std::cout << std::left << std::setw(15) << e.name << " : " << c << " vs " << e.value << " : " << to_pair(c) << " : " << error << '\n';
}
std::cout << std::setprecision(oldPrec);

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS; // ignore failures
#else // !MANUAL_TESTING

#if REGRESSION_LEVEL_1



#endif

#if REGRESSION_LEVEL_2
Expand Down

0 comments on commit 4aa841a

Please sign in to comment.