From caa1a38330b4ca2b35469e98ccbc0113cb855441 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Thu, 21 Aug 2008 20:44:33 +0400 Subject: [PATCH] Get rid of CL_REQUIRE/CL_PROVIDE(cl_F_catalanconst_var). Turn cl_[SDFL]F_catalanconst global variables into functions (which return a reference to the static value) in order to avoid static initialization order problems. --- include/cln/float.h | 3 -- src/float/transcendental/cl_F_catalanconst.cc | 6 ++-- .../transcendental/cl_F_catalanconst_def.cc | 6 ++-- .../transcendental/cl_F_catalanconst_f.cc | 6 ++-- .../transcendental/cl_F_catalanconst_var.cc | 36 +++++++++++++------ src/float/transcendental/cl_F_tran.h | 8 ++--- .../transcendental/cl_LF_catalanconst.cc | 12 +++---- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/include/cln/float.h b/include/cln/float.h index 701811a..5032cbe 100644 --- a/include/cln/float.h +++ b/include/cln/float.h @@ -691,9 +691,6 @@ extern const cl_F catalanconst (float_format_t f); // catalanconst() liefert die Catalansche Konstante im Default-Float-Format. extern const cl_F catalanconst (void); -//CL_REQUIRE(cl_F_catalanconst_var) - - // zeta(s) returns the Riemann zeta function at s>1. extern const cl_F zeta (int s, const cl_F& y); extern const cl_F zeta (int s, float_format_t f); diff --git a/src/float/transcendental/cl_F_catalanconst.cc b/src/float/transcendental/cl_F_catalanconst.cc index 72b0adf..63ff307 100644 --- a/src/float/transcendental/cl_F_catalanconst.cc +++ b/src/float/transcendental/cl_F_catalanconst.cc @@ -18,9 +18,9 @@ namespace cln { const cl_F catalanconst (const cl_F& y) { floattypecase(y - , return cl_SF_catalanconst; - , return cl_FF_catalanconst; - , return cl_DF_catalanconst; + , return cl_SF_catalanconst(); + , return cl_FF_catalanconst(); + , return cl_DF_catalanconst(); , return catalanconst(TheLfloat(y)->len); ); } diff --git a/src/float/transcendental/cl_F_catalanconst_def.cc b/src/float/transcendental/cl_F_catalanconst_def.cc index 5b07c25..6e45a3b 100644 --- a/src/float/transcendental/cl_F_catalanconst_def.cc +++ b/src/float/transcendental/cl_F_catalanconst_def.cc @@ -17,9 +17,9 @@ namespace cln { const cl_F catalanconst (void) { floatformatcase(default_float_format - , return cl_SF_catalanconst; - , return cl_FF_catalanconst; - , return cl_DF_catalanconst; + , return cl_SF_catalanconst(); + , return cl_FF_catalanconst(); + , return cl_DF_catalanconst(); , return catalanconst(len); ); } diff --git a/src/float/transcendental/cl_F_catalanconst_f.cc b/src/float/transcendental/cl_F_catalanconst_f.cc index bbdc176..c23811d 100644 --- a/src/float/transcendental/cl_F_catalanconst_f.cc +++ b/src/float/transcendental/cl_F_catalanconst_f.cc @@ -17,9 +17,9 @@ namespace cln { const cl_F catalanconst (float_format_t f) { floatformatcase((uintC)f - , return cl_SF_catalanconst; - , return cl_FF_catalanconst; - , return cl_DF_catalanconst; + , return cl_SF_catalanconst(); + , return cl_FF_catalanconst(); + , return cl_DF_catalanconst(); , return catalanconst(len); ); } diff --git a/src/float/transcendental/cl_F_catalanconst_var.cc b/src/float/transcendental/cl_F_catalanconst_var.cc index b4799d2..829f269 100644 --- a/src/float/transcendental/cl_F_catalanconst_var.cc +++ b/src/float/transcendental/cl_F_catalanconst_var.cc @@ -3,8 +3,6 @@ // General includes. #include "cl_sysdep.h" -CL_PROVIDE(cl_F_catalanconst_var) - // Specification. #include "cl_F_tran.h" @@ -18,20 +16,36 @@ CL_PROVIDE(cl_F_catalanconst_var) namespace cln { -// Mantisse der Catalanschen Konstante : - static const uintD catalanconst_mantisse [64/intDsize] = - #include "cl_F_catalanconst_var.h" - -cl_LF cl_LF_catalanconst = encode_LF_array(0,0,catalanconst_mantisse,64/intDsize); +cl_LF& cl_LF_catalanconst() +{ + // Mantisse der Catalanschen Konstante : + static const uintD catalanconst_mantisse [64/intDsize] = + #include "cl_F_catalanconst_var.h" + static cl_LF val = encode_LF_array(0,0,catalanconst_mantisse,64/intDsize); + return val; +} // Problem: If someone changes free_hook, the destructor of this // will call the new hook, passing it some pointer obtained by the old // malloc_hook. ?? -const cl_SF cl_SF_catalanconst = cl_LF_to_SF(cl_LF_catalanconst); -const cl_FF cl_FF_catalanconst = cl_LF_to_FF(cl_LF_catalanconst); -const cl_DF cl_DF_catalanconst = cl_LF_to_DF(cl_LF_catalanconst); +const cl_SF& cl_SF_catalanconst() +{ + static const cl_SF val = cl_LF_to_SF(cl_LF_catalanconst()); + return val; +} + +const cl_DF& cl_DF_catalanconst() +{ + static const cl_DF val = cl_LF_to_DF(cl_LF_catalanconst()); + return val; +} + +const cl_FF& cl_FF_catalanconst() +{ + static const cl_FF val = cl_LF_to_FF(cl_LF_catalanconst()); + return val; +} } // namespace cln -CL_PROVIDE_END(cl_F_catalanconst_var) diff --git a/src/float/transcendental/cl_F_tran.h b/src/float/transcendental/cl_F_tran.h index 10d7af3..0899d57 100644 --- a/src/float/transcendental/cl_F_tran.h +++ b/src/float/transcendental/cl_F_tran.h @@ -133,10 +133,10 @@ extern cl_LF& cl_LF_eulerconst(); // as long as it has ever been computed extern const cl_LF eulerconst (uintC len); // computes it even further // Catalansche Konstante. -extern const cl_SF cl_SF_catalanconst; -extern const cl_FF cl_FF_catalanconst; -extern const cl_DF cl_DF_catalanconst; -extern cl_LF cl_LF_catalanconst; // as long as it has ever been computed +extern const cl_SF& cl_SF_catalanconst(); +extern const cl_FF& cl_FF_catalanconst(); +extern const cl_DF& cl_DF_catalanconst(); +extern cl_LF& cl_LF_catalanconst(); // as long as it has ever been computed extern const cl_LF catalanconst (uintC len); // computes it even further // Zeta-Funktion für s>1 ganzzahlig. diff --git a/src/float/transcendental/cl_LF_catalanconst.cc b/src/float/transcendental/cl_LF_catalanconst.cc index 40db8e9..9e742c2 100644 --- a/src/float/transcendental/cl_LF_catalanconst.cc +++ b/src/float/transcendental/cl_LF_catalanconst.cc @@ -300,13 +300,13 @@ const cl_LF compute_catalanconst (uintC len) const cl_LF catalanconst (uintC len) { - var uintC oldlen = TheLfloat(cl_LF_catalanconst)->len; // vorhandene Länge + var uintC oldlen = TheLfloat(cl_LF_catalanconst())->len; // vorhandene Länge if (len < oldlen) - return shorten(cl_LF_catalanconst,len); + return shorten(cl_LF_catalanconst(),len); if (len == oldlen) - return cl_LF_catalanconst; + return cl_LF_catalanconst(); - // TheLfloat(cl_LF_catalanconst)->len um mindestens einen konstanten Faktor + // TheLfloat(cl_LF_catalanconst())->len um mindestens einen konstanten Faktor // > 1 wachsen lassen, damit es nicht zu häufig nachberechnet wird: var uintC newlen = len; oldlen += floor(oldlen,2); // oldlen * 3/2 @@ -314,8 +314,8 @@ const cl_LF catalanconst (uintC len) newlen = oldlen; // gewünschte > vorhandene Länge -> muß nachberechnen: - cl_LF_catalanconst = compute_catalanconst(newlen); - return (len < newlen ? shorten(cl_LF_catalanconst,len) : cl_LF_catalanconst); + cl_LF_catalanconst() = compute_catalanconst(newlen); + return (len < newlen ? shorten(cl_LF_catalanconst(),len) : cl_LF_catalanconst()); } } // namespace cln