Browse Source

Get rid of CL_REQUIRE/CL_PROVIDE(cl_F_exp1_var).

Turn cl_[SDFL]F_exp1 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
7eda668b0c
  1. 2
      include/cln/float.h
  2. 6
      src/float/transcendental/cl_F_exp1.cc
  3. 6
      src/float/transcendental/cl_F_exp1_def.cc
  4. 6
      src/float/transcendental/cl_F_exp1_f.cc
  5. 36
      src/float/transcendental/cl_F_exp1_var.cc
  6. 8
      src/float/transcendental/cl_F_tran.h
  7. 12
      src/float/transcendental/cl_LF_exp1.cc

2
include/cln/float.h

@ -636,8 +636,6 @@ extern const cl_F exp1 (float_format_t f);
// exp1() liefert die Zahl e = exp(1) im Default-Float-Format.
extern const cl_F exp1 (void);
//CL_REQUIRE(cl_F_exp1_var)
// ln(x) liefert zu einem Float x>0 die Zahl ln(x).
extern const cl_F ln (const cl_F& x);

6
src/float/transcendental/cl_F_exp1.cc

@ -18,9 +18,9 @@ namespace cln {
const cl_F exp1 (const cl_F& y)
{
floattypecase(y
, return cl_SF_exp1;
, return cl_FF_exp1;
, return cl_DF_exp1;
, return cl_SF_exp1();
, return cl_FF_exp1();
, return cl_DF_exp1();
, return exp1(TheLfloat(y)->len);
);
}

6
src/float/transcendental/cl_F_exp1_def.cc

@ -17,9 +17,9 @@ namespace cln {
const cl_F exp1 (void)
{
floatformatcase(default_float_format
, return cl_SF_exp1;
, return cl_FF_exp1;
, return cl_DF_exp1;
, return cl_SF_exp1();
, return cl_FF_exp1();
, return cl_DF_exp1();
, return exp1(len);
);
}

6
src/float/transcendental/cl_F_exp1_f.cc

@ -17,9 +17,9 @@ namespace cln {
const cl_F exp1 (float_format_t f)
{
floatformatcase((uintC)f
, return cl_SF_exp1;
, return cl_FF_exp1;
, return cl_DF_exp1;
, return cl_SF_exp1();
, return cl_FF_exp1();
, return cl_DF_exp1();
, return exp1(len);
);
}

36
src/float/transcendental/cl_F_exp1_var.cc

@ -3,8 +3,6 @@
// General includes.
#include "cl_sysdep.h"
CL_PROVIDE(cl_F_exp1_var)
// Specification.
#include "cl_F_tran.h"
@ -18,20 +16,36 @@ CL_PROVIDE(cl_F_exp1_var)
namespace cln {
// Mantisse von exp(1) :
static const uintD exp1_mantisse [64/intDsize] =
#include "cl_F_exp1_var.h"
cl_LF cl_LF_exp1 = encode_LF_array(0,2,exp1_mantisse,64/intDsize);
cl_LF& cl_LF_exp1()
{
// Mantisse von exp(1) :
static const uintD exp1_mantisse [64/intDsize] =
#include "cl_F_exp1_var.h"
static cl_LF val = encode_LF_array(0,2,exp1_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_exp1 = cl_LF_to_SF(cl_LF_exp1);
const cl_FF cl_FF_exp1 = cl_LF_to_FF(cl_LF_exp1);
const cl_DF cl_DF_exp1 = cl_LF_to_DF(cl_LF_exp1);
const cl_SF& cl_SF_exp1()
{
static const cl_SF val = cl_LF_to_SF(cl_LF_exp1());
return val;
}
const cl_FF& cl_FF_exp1()
{
static const cl_FF val = cl_LF_to_FF(cl_LF_exp1());
return val;
}
const cl_DF& cl_DF_exp1()
{
static const cl_DF val = cl_LF_to_DF(cl_LF_exp1());
return val;
}
} // namespace cln
CL_PROVIDE_END(cl_F_exp1_var)

8
src/float/transcendental/cl_F_tran.h

@ -114,10 +114,10 @@ extern const cl_F cl_ln10 (const cl_F& y);
extern const cl_F cl_ln10 (float_format_t f);
// e = exp(1).
extern const cl_SF cl_SF_exp1;
extern const cl_FF cl_FF_exp1;
extern const cl_DF cl_DF_exp1;
extern cl_LF cl_LF_exp1; // as long as it has ever been computed
extern const cl_SF& cl_SF_exp1();
extern const cl_FF& cl_FF_exp1();
extern const cl_DF& cl_DF_exp1();
extern cl_LF& cl_LF_exp1(); // as long as it has ever been computed
extern const cl_LF exp1 (uintC len); // computes it even further
// expx(x) liefert zu einem Float x (betragsmäßig <1) exp(x) als Float.

12
src/float/transcendental/cl_LF_exp1.cc

@ -78,13 +78,13 @@ const cl_LF compute_exp1 (uintC len)
const cl_LF exp1 (uintC len)
{
var uintC oldlen = TheLfloat(cl_LF_exp1)->len; // vorhandene Länge
var uintC oldlen = TheLfloat(cl_LF_exp1())->len; // vorhandene Länge
if (len < oldlen)
return shorten(cl_LF_exp1,len);
return shorten(cl_LF_exp1(),len);
if (len == oldlen)
return cl_LF_exp1;
return cl_LF_exp1();
// TheLfloat(cl_LF_exp1)->len um mindestens einen konstanten Faktor
// TheLfloat(cl_LF_exp1())->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
@ -92,8 +92,8 @@ const cl_LF exp1 (uintC len)
newlen = oldlen;
// gewünschte > vorhandene Länge -> muß nachberechnen:
cl_LF_exp1 = compute_exp1(newlen); // (exp 1)
return (len < newlen ? shorten(cl_LF_exp1,len) : cl_LF_exp1);
cl_LF_exp1() = compute_exp1(newlen); // (exp 1)
return (len < newlen ? shorten(cl_LF_exp1(),len) : cl_LF_exp1());
}
} // namespace cln
Loading…
Cancel
Save