Browse Source

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.
master
Alexei Sheplyakov 16 years ago
parent
commit
03dedf345c
  1. 3
      include/cln/float.h
  2. 6
      src/float/transcendental/cl_F_eulerconst.cc
  3. 6
      src/float/transcendental/cl_F_eulerconst_def.cc
  4. 6
      src/float/transcendental/cl_F_eulerconst_f.cc
  5. 35
      src/float/transcendental/cl_F_eulerconst_var.cc
  6. 8
      src/float/transcendental/cl_F_tran.h
  7. 12
      src/float/transcendental/cl_LF_eulerconst.cc

3
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

6
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);
);
}

6
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);
);
}

6
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);
);
}

35
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)

8
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.

12
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
Loading…
Cancel
Save