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

include/cln/float.h
src/float/transcendental/cl_F_pi.cc
src/float/transcendental/cl_F_pi_def.cc
src/float/transcendental/cl_F_pi_f.cc
src/float/transcendental/cl_F_pi_var.cc
src/float/transcendental/cl_F_tran.h
src/float/transcendental/cl_LF_pi.cc

index e262ca067ae2bf3ecdb0c907e036307bbfc10c65..48a83b8abe8ad1a43ce6b2ff4b79140c66c19438 100644 (file)
@@ -602,8 +602,6 @@ extern const cl_F pi (float_format_t f);
 // pi() liefert die Zahl pi im Default-Float-Format.
 extern const cl_F pi (void);
 
-//CL_REQUIRE(cl_F_pi_var)
-
 
 // sin(x) liefert den Sinus (sin x) eines Float x.
 extern const cl_F sin (const cl_F& x);
index 217d2c8f1fd6329172c91af075a7a9761f99bb1f..7d2f8ced0abd4d1ce7aa5c7731c244e559fe9192 100644 (file)
@@ -18,9 +18,9 @@ namespace cln {
 const cl_F pi (const cl_F& y)
 {
        floattypecase(y
-       ,       return cl_SF_pi;
-       ,       return cl_FF_pi;
-       ,       return cl_DF_pi;
+       ,       return cl_SF_pi();
+       ,       return cl_FF_pi();
+       ,       return cl_DF_pi();
        ,       return pi(TheLfloat(y)->len);
        );
 }
index 73e1e344e94c093711eabcec311826489b57bfcb..d2f65684f20f84107a7639e941dc0ba2090c4f59 100644 (file)
@@ -17,9 +17,9 @@ namespace cln {
 const cl_F pi (void)
 {
        floatformatcase(default_float_format
-       ,       return cl_SF_pi;
-       ,       return cl_FF_pi;
-       ,       return cl_DF_pi;
+       ,       return cl_SF_pi();
+       ,       return cl_FF_pi();
+       ,       return cl_DF_pi();
        ,       return pi(len);
        );
 }
index d6ea053ff9e8875706bdfce5f03f2ebfda369468..a94d8f2c1c8b89b9d99009c8ace95656cdaecd93 100644 (file)
@@ -17,9 +17,9 @@ namespace cln {
 const cl_F pi (float_format_t f)
 {
        floatformatcase((uintC)f
-       ,       return cl_SF_pi;
-       ,       return cl_FF_pi;
-       ,       return cl_DF_pi;
+       ,       return cl_SF_pi();
+       ,       return cl_FF_pi();
+       ,       return cl_DF_pi();
        ,       return pi(len);
        );
 }
index bbcb8ea0d7b8504b31a0bfa9eafdd7f8dd355032..567a94a76e5c7bf4634538aae3f60459e93cbb49 100644 (file)
@@ -1,9 +1,8 @@
-// cl_SF_pi, cl_FF_pi, cl_DF_pi, cl_LF_pi.
+// cl_SF_pi(), cl_FF_pi(), cl_DF_pi(), cl_LF_pi().
 
 // General includes.
 #include "cl_sysdep.h"
 
-CL_PROVIDE(cl_F_pi_var)
 
 // Specification.
 #include "cl_F_tran.h"
@@ -18,20 +17,36 @@ CL_PROVIDE(cl_F_pi_var)
 
 namespace cln {
 
-// Mantisse von pi :
-  static const uintD pi_mantisse [2048/intDsize] =
-    #include "cl_F_pi_var.h"
-
-cl_LF cl_LF_pi = encode_LF_array(0,2,pi_mantisse,2048/intDsize);
+cl_LF& cl_LF_pi()
+{
+       // Mantisse von pi :
+       static const uintD pi_mantisse [2048/intDsize] =
+               #include "cl_F_pi_var.h"
+       static cl_LF val = encode_LF_array(0,2,pi_mantisse,2048/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_pi = cl_LF_to_SF(cl_LF_pi);
-const cl_FF cl_FF_pi = cl_LF_to_FF(cl_LF_pi);
-const cl_DF cl_DF_pi = cl_LF_to_DF(cl_LF_pi);
+const cl_SF& cl_SF_pi()
+{
+       static const cl_SF val = cl_LF_to_SF(cl_LF_pi());
+       return val;
+}
+
+const cl_DF& cl_DF_pi()
+{
+       static const cl_DF val = cl_LF_to_DF(cl_LF_pi());
+       return val;
+}
+
+const cl_FF& cl_FF_pi()
+{
+       static const cl_FF val = cl_LF_to_FF(cl_LF_pi());
+       return val;
+}
 
 }  // namespace cln
 
-CL_PROVIDE_END(cl_F_pi_var)
index daa5a954f276ca71c0fe3ee904070a51cece91fd..451daa6be5b8359d38d8a5ec004f298b055a5a0b 100644 (file)
@@ -9,12 +9,11 @@
 namespace cln {
 
 // pi.
-extern const cl_SF cl_SF_pi;
-extern const cl_FF cl_FF_pi;
-extern const cl_DF cl_DF_pi;
-extern cl_LF cl_LF_pi; // as long as it has ever been computed
+extern const cl_SF& cl_SF_pi();
+extern const cl_FF& cl_FF_pi();
+extern const cl_DF& cl_DF_pi();
+extern cl_LF& cl_LF_pi(); // as long as it has ever been computed
 extern const cl_LF pi (uintC len); // computes it even further
-//CL_REQUIRE(cl_F_pi_var)
 
 // cl_exp_aux(p,lq,len) liefert die Zahl exp(p/2^lq) mit len Digits.
 // 0 < |p| < 2^lq.
index 248e75eeece2013ca1ff954958a54c0354ee7ed7..78f625c318018e84a09255bc23ab743b06783dcd 100644 (file)
@@ -260,13 +260,13 @@ const cl_LF compute_pi_ramanujan_163_fast (uintC len)
 
 const cl_LF pi (uintC len)
 {
-       var uintC oldlen = TheLfloat(cl_LF_pi)->len; // vorhandene Länge
+       var uintC oldlen = TheLfloat(cl_LF_pi())->len; // vorhandene Länge
        if (len < oldlen)
-               return shorten(cl_LF_pi,len);
+               return shorten(cl_LF_pi(),len);
        if (len == oldlen)
-               return cl_LF_pi;
+               return cl_LF_pi();
 
-       // TheLfloat(cl_LF_pi)->len um mindestens einen konstanten Faktor
+       // TheLfloat(cl_LF_pi())->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
@@ -274,8 +274,8 @@ const cl_LF pi (uintC len)
                newlen = oldlen;
 
        // gewünschte > vorhandene Länge -> muß nachberechnen:
-       cl_LF_pi = compute_pi_ramanujan_163_fast(newlen);
-       return (len < newlen ? shorten(cl_LF_pi,len) : cl_LF_pi);
+       cl_LF_pi() = compute_pi_ramanujan_163_fast(newlen);
+       return (len < newlen ? shorten(cl_LF_pi(),len) : cl_LF_pi());
 }
 
 }  // namespace cln