From 03dedf345c6da66b5340cf70d671dbf71ac893c9 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Thu, 21 Aug 2008 20:27:17 +0400 Subject: [PATCH] Get rid of CL_REQUIRE/CL_PROVIDE(cl_F_eulerconst_var). Turn cl_[SDFL]F_eulerconst 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_eulerconst.cc | 6 ++-- .../transcendental/cl_F_eulerconst_def.cc | 6 ++-- src/float/transcendental/cl_F_eulerconst_f.cc | 6 ++-- .../transcendental/cl_F_eulerconst_var.cc | 35 +++++++++++++------ src/float/transcendental/cl_F_tran.h | 8 ++--- src/float/transcendental/cl_LF_eulerconst.cc | 12 +++---- 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/cln/float.h b/include/cln/float.h index 4f25dc0..701811a 100644 --- a/include/cln/float.h +++ b/include/cln/float.h @@ -679,9 +679,6 @@ extern const cl_F eulerconst (float_format_t f); // eulerconst() liefert die Eulersche Konstante im Default-Float-Format. extern const cl_F eulerconst (void); -//CL_REQUIRE(cl_F_eulerconst_var) - - // catalanconst(y) liefert die Catalansche Konstante // im selben Float-Format wie y. // > y: ein Float diff --git a/src/float/transcendental/cl_F_eulerconst.cc b/src/float/transcendental/cl_F_eulerconst.cc index 8650ed8..1d393f8 100644 --- a/src/float/transcendental/cl_F_eulerconst.cc +++ b/src/float/transcendental/cl_F_eulerconst.cc @@ -18,9 +18,9 @@ namespace cln { const cl_F eulerconst (const cl_F& y) { floattypecase(y - , return cl_SF_eulerconst; - , return cl_FF_eulerconst; - , return cl_DF_eulerconst; + , return cl_SF_eulerconst(); + , return cl_FF_eulerconst(); + , return cl_DF_eulerconst(); , return eulerconst(TheLfloat(y)->len); ); } diff --git a/src/float/transcendental/cl_F_eulerconst_def.cc b/src/float/transcendental/cl_F_eulerconst_def.cc index 9a149a8..777924f 100644 --- a/src/float/transcendental/cl_F_eulerconst_def.cc +++ b/src/float/transcendental/cl_F_eulerconst_def.cc @@ -17,9 +17,9 @@ namespace cln { const cl_F eulerconst (void) { floatformatcase(default_float_format - , return cl_SF_eulerconst; - , return cl_FF_eulerconst; - , return cl_DF_eulerconst; + , return cl_SF_eulerconst(); + , return cl_FF_eulerconst(); + , return cl_DF_eulerconst(); , return eulerconst(len); ); } diff --git a/src/float/transcendental/cl_F_eulerconst_f.cc b/src/float/transcendental/cl_F_eulerconst_f.cc index e97e2cb..e4e445c 100644 --- a/src/float/transcendental/cl_F_eulerconst_f.cc +++ b/src/float/transcendental/cl_F_eulerconst_f.cc @@ -17,9 +17,9 @@ namespace cln { const cl_F eulerconst (float_format_t f) { floatformatcase((uintC)f - , return cl_SF_eulerconst; - , return cl_FF_eulerconst; - , return cl_DF_eulerconst; + , return cl_SF_eulerconst(); + , return cl_FF_eulerconst(); + , return cl_DF_eulerconst(); , return eulerconst(len); ); } diff --git a/src/float/transcendental/cl_F_eulerconst_var.cc b/src/float/transcendental/cl_F_eulerconst_var.cc index 153a4a1..b633955 100644 --- a/src/float/transcendental/cl_F_eulerconst_var.cc +++ b/src/float/transcendental/cl_F_eulerconst_var.cc @@ -3,8 +3,6 @@ // General includes. #include "cl_sysdep.h" -CL_PROVIDE(cl_F_eulerconst_var) - // Specification. #include "cl_F_tran.h" @@ -18,20 +16,35 @@ CL_PROVIDE(cl_F_eulerconst_var) namespace cln { -// Mantisse der Eulerschen Konstante : - static const uintD eulerconst_mantisse [64/intDsize] = - #include "cl_F_eulerconst_var.h" - -cl_LF cl_LF_eulerconst = encode_LF_array(0,0,eulerconst_mantisse,64/intDsize); +cl_LF& cl_LF_eulerconst() +{ + // Mantisse der Eulerschen Konstante : + static const uintD eulerconst_mantisse [64/intDsize] = + #include "cl_F_eulerconst_var.h" + static cl_LF val = encode_LF_array(0,0,eulerconst_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_eulerconst = cl_LF_to_SF(cl_LF_eulerconst); -const cl_FF cl_FF_eulerconst = cl_LF_to_FF(cl_LF_eulerconst); -const cl_DF cl_DF_eulerconst = cl_LF_to_DF(cl_LF_eulerconst); +const cl_SF& cl_SF_eulerconst() +{ + static const cl_SF val = cl_LF_to_SF(cl_LF_eulerconst()); + return val; +} +const cl_FF& cl_FF_eulerconst() +{ + static const cl_FF val = cl_LF_to_FF(cl_LF_eulerconst()); + return val; +} + +const cl_DF& cl_DF_eulerconst() +{ + static const cl_DF val = cl_LF_to_DF(cl_LF_eulerconst()); + return val; +} } // namespace cln -CL_PROVIDE_END(cl_F_eulerconst_var) diff --git a/src/float/transcendental/cl_F_tran.h b/src/float/transcendental/cl_F_tran.h index 06395bc..10d7af3 100644 --- a/src/float/transcendental/cl_F_tran.h +++ b/src/float/transcendental/cl_F_tran.h @@ -126,10 +126,10 @@ extern const cl_LF expx_naive (const cl_LF& x); // requires cl_F_extendsqrtx extern const cl_LF expx_ratseries (const cl_LF& x); // requires extend by 1 // Eulersche Konstante. -extern const cl_SF cl_SF_eulerconst; -extern const cl_FF cl_FF_eulerconst; -extern const cl_DF cl_DF_eulerconst; -extern cl_LF cl_LF_eulerconst; // as long as it has ever been computed +extern const cl_SF& cl_SF_eulerconst(); +extern const cl_FF& cl_FF_eulerconst(); +extern const cl_DF& cl_DF_eulerconst(); +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. diff --git a/src/float/transcendental/cl_LF_eulerconst.cc b/src/float/transcendental/cl_LF_eulerconst.cc index 0cc8bbf..998b4b5 100644 --- a/src/float/transcendental/cl_LF_eulerconst.cc +++ b/src/float/transcendental/cl_LF_eulerconst.cc @@ -507,13 +507,13 @@ const cl_LF compute_eulerconst (uintC len) const cl_LF eulerconst (uintC len) { - var uintC oldlen = TheLfloat(cl_LF_eulerconst)->len; // vorhandene Länge + var uintC oldlen = TheLfloat(cl_LF_eulerconst())->len; // vorhandene Länge if (len < oldlen) - return shorten(cl_LF_eulerconst,len); + return shorten(cl_LF_eulerconst(),len); if (len == oldlen) - return cl_LF_eulerconst; + return cl_LF_eulerconst(); - // TheLfloat(cl_LF_eulerconst)->len um mindestens einen konstanten Faktor + // TheLfloat(cl_LF_eulerconst())->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 @@ -521,8 +521,8 @@ const cl_LF eulerconst (uintC len) newlen = oldlen; // gewünschte > vorhandene Länge -> muß nachberechnen: - cl_LF_eulerconst = compute_eulerconst(newlen); - return (len < newlen ? shorten(cl_LF_eulerconst,len) : cl_LF_eulerconst); + cl_LF_eulerconst() = compute_eulerconst(newlen); + return (len < newlen ? shorten(cl_LF_eulerconst(),len) : cl_LF_eulerconst()); } } // namespace cln