Browse Source

Avoid gcc warnings about type-punning and "... break strict-aliasing rules".

master
Bruno Haible 17 years ago
parent
commit
137d5f385f
  1. 5
      autoconf/floatparam.c
  2. 14
      include/cln/number.h
  3. 6
      src/float/dfloat/cl_DF.h
  4. 9
      src/float/dfloat/conv/cl_DF_from_double.cc
  5. 6
      src/float/ffloat/cl_FF.h
  6. 9
      src/float/ffloat/conv/cl_FF_from_float.cc

5
autoconf/floatparam.c

@ -92,8 +92,9 @@ check(ldouble,"long_double","long double",equal_ldouble,main_ldouble)
static void flipped_double (void) static void flipped_double (void)
{ {
typedef struct { unsigned lo, hi; } dfloat; 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) { if (test.lo==0 && test.hi!=0) {
printf("#define double_wordorder_bigendian_p 0\n"); printf("#define double_wordorder_bigendian_p 0\n");
} else if (test.lo!=0 && test.hi==0) { } else if (test.lo!=0 && test.hi==0) {

14
include/cln/number.h

@ -146,34 +146,32 @@ namespace cln {
// Constructors and assignment operators from C numeric types. // Constructors and assignment operators from C numeric types.
// from `float': // 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_) \ #define CL_DEFINE_FLOAT_CONSTRUCTOR(_class_) \
inline _class_ :: _class_ (const float x) \ 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) \ inline _class_& _class_::operator= (const float x) \
{ \ { \
cl_dec_refcount(*this); \ cl_dec_refcount(*this); \
pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \
pointer = cl_float_to_FF_pointer(x); \
return *this; \ return *this; \
} }
// from `double': // 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_) \ #define CL_DEFINE_DOUBLE_CONSTRUCTOR(_class_) \
inline _class_::_class_ (const double x) \ 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) \ inline _class_& _class_::operator= (const double x) \
{ \ { \
cl_dec_refcount(*this); \ cl_dec_refcount(*this); \
pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \
pointer = cl_double_to_DF_pointer(x); \
return *this; \ return *this; \
} }

6
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: vorzeichenbehaftete Infinity
// e=2047, m/=0: NaN // 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); // cl_DF_to_double(obj,&val);
// wandelt ein Double-Float obj in ein IEEE-Double-Float val um. // wandelt ein Double-Float obj in ein IEEE-Double-Float val um.

9
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. // General includes.
#include "cl_sysdep.h" #include "cl_sysdep.h"
@ -11,8 +14,10 @@
namespace cln { 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; var dfloat val = val_.eksplicit;
#if (cl_word_size==64) #if (cl_word_size==64)
var uintL exp = (val >> DF_mant_len) & (bit(DF_exp_len)-1); // e var uintL exp = (val >> DF_mant_len) & (bit(DF_exp_len)-1); // e

6
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: vorzeichenbehaftete Infinity
// e=255, m/=0: NaN // 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); // cl_FF_to_float(obj,&val);
// wandelt ein Single-Float obj in ein IEEE-Single-Float val um. // wandelt ein Single-Float obj in ein IEEE-Single-Float val um.

9
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. // General includes.
#include "cl_sysdep.h" #include "cl_sysdep.h"
@ -10,8 +13,10 @@ namespace cln {
// Implementation. // 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 ffloat val = val_.eksplicit;
var uintL exp = (val >> FF_mant_len) & (bit(FF_exp_len)-1); // e var uintL exp = (val >> FF_mant_len) & (bit(FF_exp_len)-1); // e
if (exp == 0) // e=0 ? if (exp == 0) // e=0 ?

Loading…
Cancel
Save