]> www.ginac.de Git - cln.git/commitdiff
Avoid gcc warnings about type-punning and "... break strict-aliasing rules".
authorBruno Haible <bruno@clisp.org>
Tue, 22 Jan 2008 00:18:15 +0000 (00:18 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 22 Jan 2008 00:18:15 +0000 (00:18 +0000)
autoconf/floatparam.c
include/cln/number.h
src/float/dfloat/cl_DF.h
src/float/dfloat/conv/cl_DF_from_double.cc
src/float/ffloat/cl_FF.h
src/float/ffloat/conv/cl_FF_from_float.cc

index 9d96cb5144870e5144bf3d844392e3c284fa3631..a88637165a3912398d90212d479a1894d4498746 100644 (file)
@@ -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) {
index da0b2fd3e6c7a6e0f286f1d7eae3f4cd3b5068b5..f0c0c8a0cfb2aca97f8a4c1ea9eb2128a16aa3ca 100644 (file)
@@ -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;                                                   \
 }
 
index 701a0b70258401bd08614d5805755ceb3e450788..d61fd5adbf260c2c6e6172db787d5a46d1b881a9 100644 (file)
@@ -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.
index eeb5fb492f2248050b9f16052167f8236511842b..ce145e704fc8d5c19d08a2e03bb1b6bc503028e3 100644 (file)
@@ -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"
 
 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
index 4ca25cccd80beac1491c51b056163f444c88f832..1e2948f3c0a65923b850c0a9f228e7bca8f63238 100644 (file)
@@ -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.
index 479b6e249d2ec7695a5de648489e06ed63214f88..da7e9a3c2dfc727f7931ea58d4200cf502dd7e37 100644 (file)
@@ -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 ?