[Kst] extragear/graphics/kst/src/libkst

Helge Deller deller at kde.org
Fri Apr 14 11:09:22 CEST 2006


SVN commit 529715 by deller:

fix endianess alignment requirements here as well.


 M  +15 -8     kstmath.h  


--- trunk/extragear/graphics/kst/src/libkst/kstmath.h #529714:529715
@@ -33,18 +33,25 @@
 
 /*
 ** For systems without NAN, this is a NAN in IEEE double format.
-** Code lifted from kde screensavers.
+** Code from KDE's kjs libarary.
 */
 #if !defined(NAN)
-static inline double nan__()
+#include <qconfig.h>
+static double nan__()
 {
-  static const unsigned int one = 1;
-  static const bool BigEndian = (*((unsigned char *) &one) == 0);
+  /* work around some strict alignment requirements
+     for double variables on some architectures (e.g. PA-RISC) */
+  typedef union { unsigned char b[8]; double d; } kjs_double_t;
+#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+  static const kjs_double_t NaN_Bytes = { { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 } };
+#elif defined(arm)
+  static const kjs_double_t NaN_Bytes = { { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 } };
+#else
+  static const kjs_double_t NaN_Bytes = { { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f } };
+#endif
 
-  static const unsigned char be_nan_bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
-  static const unsigned char le_nan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
-
-  return *( ( const double * )( BigEndian ? be_nan_bytes : le_nan_bytes ) );
+  const double NaN = NaN_Bytes.d;
+  return NaN;
 }
 #define NAN (::nan__())
 #endif


More information about the Kst mailing list