diff -up ./QGLViewer/vec.h.qreal ./QGLViewer/vec.h --- ./QGLViewer/vec.h.qreal 2016-10-06 16:08:49.000000000 -0400 +++ ./QGLViewer/vec.h 2018-08-12 11:13:30.254206103 -0400 @@ -168,12 +168,20 @@ public: glNormal3dv(normal); glVertex3dv(pos); \endcode */ - operator const qreal*() const { + operator const double*() const { + if (sizeof(x) == sizeof(double)) { #ifdef QGLVIEWER_UNION_NOT_SUPPORTED - return &x; + return (double*)&x; #else - return v_; + return (double*)v_; #endif + } else { + static double* const result = new double[3]; + result[0] = static_cast<double>(x); + result[1] = static_cast<double>(y); + result[2] = static_cast<double>(z); + return result; + } } /*! Non const conversion operator returning the memory address of the vector. @@ -197,11 +205,19 @@ public: \endcode \note The returned float array is a static shared by all \c Vec instances. */ operator const float*() const { - static float* const result = new float[3]; - result[0] = (float)x; - result[1] = (float)y; - result[2] = (float)z; - return result; + if (std::is_same<double, qreal>::value) { + static float* const result = new float[3]; + result[0] = static_cast<float>(x); + result[1] = static_cast<float>(y); + result[2] = static_cast<float>(z); + return result; + } else { +#ifdef QGLVIEWER_UNION_NOT_SUPPORTED + return (float*)&x; +#else + return (float*)v_; +#endif + } } //@}