From 67eaa4fddd56140fb0909f1075cb76e5b22badac Mon Sep 17 00:00:00 2001 From: Zlodiy Date: Thu, 5 Jun 2014 12:12:46 +1100 Subject: [PATCH 1/5] Alternative solution using union --- pyc_numeric.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyc_numeric.h b/pyc_numeric.h index 366d9ab..14260c0 100644 --- a/pyc_numeric.h +++ b/pyc_numeric.h @@ -80,20 +80,24 @@ private: class PycCFloat : public PycObject { public: PycCFloat(int type = TYPE_BINARY_FLOAT) - : PycObject(type), m_value(0.0) { } + : PycObject(type), m_value.d(0.0) { } bool isEqual(PycRef obj) const { return (type() == obj->type()) && - (m_value == obj.cast()->m_value); + (m_value.d == obj.cast()->m_value.d); } void load(class PycData* stream, class PycModule* mod); - double value() const { return m_value; } + double value() const { return m_value.d; } private: - double m_value; + union + { + Pyc_INT64 i64; + double d; + } m_value; }; class PycCComplex : public PycCFloat { From 5cd3bb862666f3ef5035489815f0c2df99e056e7 Mon Sep 17 00:00:00 2001 From: Zlodiy Date: Thu, 5 Jun 2014 12:17:06 +1100 Subject: [PATCH 2/5] Alternative solution using union --- pyc_numeric.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pyc_numeric.h b/pyc_numeric.h index 14260c0..10f0b9e 100644 --- a/pyc_numeric.h +++ b/pyc_numeric.h @@ -80,24 +80,24 @@ private: class PycCFloat : public PycObject { public: PycCFloat(int type = TYPE_BINARY_FLOAT) - : PycObject(type), m_value.d(0.0) { } + : PycObject(type), m_value(0.0) { } bool isEqual(PycRef obj) const { return (type() == obj->type()) && - (m_value.d == obj.cast()->m_value.d); + (m_value.d == obj.cast()->m_value); } void load(class PycData* stream, class PycModule* mod); - double value() const { return m_value.d; } + double value() const { return m_value; } private: union { - Pyc_INT64 i64; - double d; - } m_value; + Pyc_INT64 m_value_i64; + double m_value; + } }; class PycCComplex : public PycCFloat { @@ -116,7 +116,11 @@ public: double imag() const { return m_imag; } private: - double m_imag; + union + { + Pyc_INT64 m_imag_i64; + double m_imag; + } }; #endif From eb11934f6a8ba1b073e7cc10b78b0c37a950e9c1 Mon Sep 17 00:00:00 2001 From: Zlodiy Date: Thu, 5 Jun 2014 12:19:19 +1100 Subject: [PATCH 3/5] Alternative solution using union --- pyc_numeric.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyc_numeric.cpp b/pyc_numeric.cpp index 25a6419..6db2ed8 100644 --- a/pyc_numeric.cpp +++ b/pyc_numeric.cpp @@ -153,7 +153,7 @@ bool PycComplex::isEqual(PycRef obj) const /* PycCFloat */ void PycCFloat::load(PycData* stream, PycModule*) { - m_value = (double)stream->get64(); + m_value_i64 = stream->get64(); } @@ -161,5 +161,5 @@ void PycCFloat::load(PycData* stream, PycModule*) void PycCComplex::load(PycData* stream, PycModule* mod) { PycCFloat::load(stream, mod); - m_imag = (double)stream->get64(); + m_imag_i64 = stream->get64(); } From f3100a8bd19379758f31c6bd1aeaf337d8ed7739 Mon Sep 17 00:00:00 2001 From: Zlodiy Date: Thu, 5 Jun 2014 12:26:16 +1100 Subject: [PATCH 4/5] Alternative solution using union --- pyc_numeric.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyc_numeric.h b/pyc_numeric.h index 10f0b9e..ad03bc8 100644 --- a/pyc_numeric.h +++ b/pyc_numeric.h @@ -85,7 +85,7 @@ public: bool isEqual(PycRef obj) const { return (type() == obj->type()) && - (m_value.d == obj.cast()->m_value); + (m_value == obj.cast()->m_value); } void load(class PycData* stream, class PycModule* mod); From cbfd5e980ef1fc5f3c01ebcba2fd9ca7ca190d0f Mon Sep 17 00:00:00 2001 From: Zlodiy Date: Thu, 5 Jun 2014 15:11:06 +1100 Subject: [PATCH 5/5] Alternative solution using union --- pyc_numeric.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyc_numeric.h b/pyc_numeric.h index ad03bc8..96f289c 100644 --- a/pyc_numeric.h +++ b/pyc_numeric.h @@ -2,6 +2,7 @@ #define _PYC_NUMERIC_H #include "pyc_object.h" +#include "data.h" #include #include @@ -97,7 +98,7 @@ private: { Pyc_INT64 m_value_i64; double m_value; - } + }; }; class PycCComplex : public PycCFloat { @@ -120,7 +121,7 @@ private: { Pyc_INT64 m_imag_i64; double m_imag; - } + }; }; #endif