diff --git a/autoconf/floatparam.c b/autoconf/floatparam.c index 9d96cb5..a886371 100644 --- a/autoconf/floatparam.c +++ b/autoconf/floatparam.c @@ -92,8 +92,9 @@ check(ldouble,"long_double","long double",equal_ldouble,main_ldouble) static void flipped_double (void) { typedef struct { unsigned lo, hi; } dfloat; - double x = 2; - dfloat test = *(dfloat*)&x; + union { dfloat eksplicit; double machine_double; } x; + x.machine_double = 2; + dfloat test = x.eksplicit; if (test.lo==0 && test.hi!=0) { printf("#define double_wordorder_bigendian_p 0\n"); } else if (test.lo!=0 && test.hi==0) { diff --git a/include/cln/number.h b/include/cln/number.h index da0b2fd..f0c0c8a 100644 --- a/include/cln/number.h +++ b/include/cln/number.h @@ -146,34 +146,32 @@ namespace cln { // Constructors and assignment operators from C numeric types. // from `float': -union ffloatjanus; -extern cl_private_thing cl_float_to_FF_pointer (const union ffloatjanus& val); +extern cl_private_thing cl_float_to_FF_pointer (const float val); #define CL_DEFINE_FLOAT_CONSTRUCTOR(_class_) \ inline _class_ :: _class_ (const float x) \ { \ - pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \ + pointer = cl_float_to_FF_pointer(x); \ } \ inline _class_& _class_::operator= (const float x) \ { \ cl_dec_refcount(*this); \ - pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \ + pointer = cl_float_to_FF_pointer(x); \ return *this; \ } // from `double': -union dfloatjanus; -extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const union dfloatjanus& val); +extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const double val); #define CL_DEFINE_DOUBLE_CONSTRUCTOR(_class_) \ inline _class_::_class_ (const double x) \ { \ - pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \ + pointer = cl_double_to_DF_pointer(x); \ } \ inline _class_& _class_::operator= (const double x) \ { \ cl_dec_refcount(*this); \ - pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \ + pointer = cl_double_to_DF_pointer(x); \ return *this; \ } diff --git a/src/float/dfloat/cl_DF.h b/src/float/dfloat/cl_DF.h index 701a0b7..d61fd5a 100644 --- a/src/float/dfloat/cl_DF.h +++ b/src/float/dfloat/cl_DF.h @@ -309,10 +309,8 @@ extern const cl_DF cl_RA_to_DF (const cl_RA& x); // e=2047, m=0: vorzeichenbehaftete Infinity // e=2047, m/=0: NaN -// cl_double_to_DF(val) wandelt ein IEEE-Double-Float val in ein Double-Float um. -extern cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val); -inline const cl_DF cl_double_to_DF (const dfloatjanus& val) - { return cl_double_to_DF_pointer(val); } +// cl_double_to_DF_pointer(val) wandelt ein IEEE-Double-Float val in ein Double-Float um. +extern cl_heap_dfloat* cl_double_to_DF_pointer (const double val); // cl_DF_to_double(obj,&val); // wandelt ein Double-Float obj in ein IEEE-Double-Float val um. diff --git a/src/float/dfloat/conv/cl_DF_from_double.cc b/src/float/dfloat/conv/cl_DF_from_double.cc index eeb5fb4..ce145e7 100644 --- a/src/float/dfloat/conv/cl_DF_from_double.cc +++ b/src/float/dfloat/conv/cl_DF_from_double.cc @@ -1,4 +1,7 @@ -// cl_double_to_FF(). +// cl_double_to_DF_pointer(). + +// Ensure that union dfloatjanus has a 'double' alternative. +#define FAST_DOUBLE // General includes. #include "cl_sysdep.h" @@ -11,8 +14,10 @@ namespace cln { -cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_) +cl_heap_dfloat* cl_double_to_DF_pointer (const double x) { + var union dfloatjanus val_; + val_.machine_double = x; var dfloat val = val_.eksplicit; #if (cl_word_size==64) var uintL exp = (val >> DF_mant_len) & (bit(DF_exp_len)-1); // e diff --git a/src/float/ffloat/cl_FF.h b/src/float/ffloat/cl_FF.h index 4ca25cc..1e2948f 100644 --- a/src/float/ffloat/cl_FF.h +++ b/src/float/ffloat/cl_FF.h @@ -237,10 +237,8 @@ extern const cl_FF cl_RA_to_FF (const cl_RA& x); // e=255, m=0: vorzeichenbehaftete Infinity // e=255, m/=0: NaN -// cl_float_to_FF(val) wandelt ein IEEE-Single-Float val in ein Single-Float um. -extern cl_private_thing cl_float_to_FF_pointer (const ffloatjanus& val); -inline const cl_FF cl_float_to_FF (const ffloatjanus& val) - { return cl_float_to_FF_pointer(val); } +// cl_float_to_FF_pointer(val) wandelt ein IEEE-Single-Float val in ein Single-Float um. +extern cl_private_thing cl_float_to_FF_pointer (const float val); // cl_FF_to_float(obj,&val); // wandelt ein Single-Float obj in ein IEEE-Single-Float val um. diff --git a/src/float/ffloat/conv/cl_FF_from_float.cc b/src/float/ffloat/conv/cl_FF_from_float.cc index 479b6e2..da7e9a3 100644 --- a/src/float/ffloat/conv/cl_FF_from_float.cc +++ b/src/float/ffloat/conv/cl_FF_from_float.cc @@ -1,4 +1,7 @@ -// cl_float_to_FF(). +// cl_float_to_FF_pointer(). + +// Ensure that union ffloatjanus has a 'float' alternative. +#define FAST_FLOAT // General includes. #include "cl_sysdep.h" @@ -10,8 +13,10 @@ namespace cln { // Implementation. -cl_private_thing cl_float_to_FF_pointer (const ffloatjanus& val_) +cl_private_thing cl_float_to_FF_pointer (const float x) { + var union ffloatjanus val_; + val_.machine_float = x; var ffloat val = val_.eksplicit; var uintL exp = (val >> FF_mant_len) & (bit(FF_exp_len)-1); // e if (exp == 0) // e=0 ?