]> www.ginac.de Git - cln.git/commitdiff
Get rid of CL_REQUIRE/CL_PROVIDE(cl_F_ln2_var).
authorAlexei Sheplyakov <varg@theor.jinr.ru>
Thu, 21 Aug 2008 14:12:39 +0000 (18:12 +0400)
committerAlexei Sheplyakov <varg@theor.jinr.ru>
Wed, 27 Aug 2008 04:41:06 +0000 (08:41 +0400)
Turn cl_[SDFL]F_ln2 global variables into functions (which return a constant
reference to the static value) in order to avoid static initialization order
problems.

src/float/output/cl_F_dprint.cc
src/float/transcendental/cl_F_ln2.cc
src/float/transcendental/cl_F_ln2_f.cc
src/float/transcendental/cl_F_ln2_var.cc
src/float/transcendental/cl_F_tran.h
src/float/transcendental/cl_LF_ln2.cc

index c34ff579eb84fb263cfff6aa3457dd89bb215cfc..83f3db214f958dfd5c3f62e49fa4b37f9a2491a4 100644 (file)
@@ -28,7 +28,6 @@
 //   einen String mit seiner Dezimaldarstellung.
 // (substring string start [end]) wie subseq, jedoch für Strings schneller.
 
-CL_REQUIRE(cl_F_ln2_var)
 CL_REQUIRE(cl_F_ln10_var)
 #include <cstring>
 #include "cln/output.h"
index 22234a68644848ac558a97c1ed252b04e6917c81..863a751b3e535e3e23e2d2b673778521850b5430 100644 (file)
@@ -17,9 +17,9 @@ namespace cln {
 const cl_F cl_ln2 (const cl_F& y)
 {
        floattypecase(y
-       ,       return cl_SF_ln2;
-       ,       return cl_FF_ln2;
-       ,       return cl_DF_ln2;
+       ,       return cl_SF_ln2();
+       ,       return cl_FF_ln2();
+       ,       return cl_DF_ln2();
        ,       return cl_ln2(TheLfloat(y)->len);
        );
 }
index 9882bb3173f8ad625d617896ffd09898884c4abc..739acb46b4c3f7ed7c7705c22fd551388a6d3939 100644 (file)
@@ -16,9 +16,9 @@ namespace cln {
 const cl_F cl_ln2 (float_format_t f)
 {
        floatformatcase((uintC)f
-       ,       return cl_SF_ln2;
-       ,       return cl_FF_ln2;
-       ,       return cl_DF_ln2;
+       ,       return cl_SF_ln2();
+       ,       return cl_FF_ln2();
+       ,       return cl_DF_ln2();
        ,       return cl_ln2(len);
        );
 }
index d9f66386577cdf35f9203c4d8e95b573997df9f3..aa920d650a9550f3b57b38ffac80bcd9ca9a29f5 100644 (file)
@@ -3,8 +3,6 @@
 // General includes.
 #include "cl_sysdep.h"
 
-CL_PROVIDE(cl_F_ln2_var)
-
 // Specification.
 #include "cl_F_tran.h"
 
@@ -18,20 +16,37 @@ CL_PROVIDE(cl_F_ln2_var)
 
 namespace cln {
 
-// Mantisse von ln(2) :
-  static const uintD ln2_mantisse [64/intDsize] =
-    #include "cl_F_ln2_var.h"
 
-cl_LF cl_LF_ln2 = encode_LF_array(0,0,ln2_mantisse,64/intDsize);
+cl_LF& cl_LF_ln2()
+{
+       // Mantisse von ln(2) :
+       static const uintD ln2_mantisse [64/intDsize] =
+               #include "cl_F_ln2_var.h"
+       static cl_LF val = encode_LF_array(0,0,ln2_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_ln2 = cl_LF_to_SF(cl_LF_ln2);
-const cl_FF cl_FF_ln2 = cl_LF_to_FF(cl_LF_ln2);
-const cl_DF cl_DF_ln2 = cl_LF_to_DF(cl_LF_ln2);
+const cl_SF& cl_SF_ln2()
+{
+       static const cl_SF val = cl_LF_to_SF(cl_LF_ln2());
+       return val;
+}
+
+const cl_FF& cl_FF_ln2()
+{
+       static const cl_FF val = cl_LF_to_FF(cl_LF_ln2());
+       return val;
+}
+
+const cl_DF& cl_DF_ln2()
+{
+       static const cl_DF val = cl_LF_to_DF(cl_LF_ln2());
+       return val;
+}
 
 }  // namespace cln
 
-CL_PROVIDE_END(cl_F_ln2_var)
index 451daa6be5b8359d38d8a5ec004f298b055a5a0b..5ad4da0cdcb3161ec42f714b30cc865871ac2638 100644 (file)
@@ -84,12 +84,11 @@ extern const cl_LF lnx_ratseries (const cl_LF& x); // requires extend by 1
 extern const cl_LF cl_atanh_recip (cl_I m, uintC len);
 
 // ln(2).
-extern const cl_SF cl_SF_ln2;
-extern const cl_FF cl_FF_ln2;
-extern const cl_DF cl_DF_ln2;
-extern cl_LF cl_LF_ln2; // as long as it has ever been computed
+extern const cl_SF& cl_SF_ln2();
+extern const cl_FF& cl_FF_ln2();
+extern const cl_DF& cl_DF_ln2();
+extern cl_LF& cl_LF_ln2(); // as long as it has ever been computed
 extern const cl_LF cl_ln2 (uintC len); // computes it even further
-//CL_REQUIRE(cl_F_ln2_var)
 
 // cl_ln2(y) liefert die Zahl ln(2) im selben Float-Format wie y.
 // > y: ein Float
index a07c0e1969f7882af30f37e959fee52cd88d48a4..99dd8a0318aa3a0f5cb434e1a5023b28f57d4785 100644 (file)
@@ -76,13 +76,13 @@ static inline const cl_LF compute_ln2_p2357 (uintC len)
 
 const cl_LF cl_ln2 (uintC len)
 {
-       var uintC oldlen = TheLfloat(cl_LF_ln2)->len; // vorhandene Länge
+       var uintC oldlen = TheLfloat(cl_LF_ln2())->len; // vorhandene Länge
        if (len < oldlen)
-               return shorten(cl_LF_ln2,len);
+               return shorten(cl_LF_ln2(),len);
        if (len == oldlen)
-               return cl_LF_ln2;
+               return cl_LF_ln2();
 
-       // TheLfloat(cl_LF_ln2)->len um mindestens einen konstanten Faktor
+       // TheLfloat(cl_LF_ln2())->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
@@ -90,8 +90,8 @@ const cl_LF cl_ln2 (uintC len)
                newlen = oldlen;
 
        // gewünschte > vorhandene Länge -> muß nachberechnen:
-       cl_LF_ln2 = compute_ln2(newlen);
-       return (len < newlen ? shorten(cl_LF_ln2,len) : cl_LF_ln2);
+       cl_LF_ln2() = compute_ln2(newlen);
+       return (len < newlen ? shorten(cl_LF_ln2(),len) : cl_LF_ln2());
 }
 
 }  // namespace cln