From bc14c8b21fe31a7bff1abf0fbb0eae2d5dd839df Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Sep 2005 18:14:53 +0000 Subject: [PATCH] added wxIsSameDouble() which wraps double comparison in a pragmas disabling icc warning about it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gdicmn.h | 9 +++++++-- include/wx/math.h | 21 +++++++++++++++++++++ src/common/variant.cpp | 13 +++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 5018eece64..6033cdf7cd 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -21,6 +21,7 @@ #include "wx/string.h" #include "wx/fontenc.h" #include "wx/hashmap.h" +#include "wx/math.h" // --------------------------------------------------------------------------- // forward declarations @@ -269,10 +270,14 @@ public: wxRealPoint operator+(const wxRealPoint& pt) const { return wxRealPoint(x + pt.x, y + pt.y); } wxRealPoint operator-(const wxRealPoint& pt) const { return wxRealPoint(x - pt.x, y - pt.y); } - bool operator==(const wxRealPoint& pt) const { return x == pt.x && y == pt.y; } - bool operator!=(const wxRealPoint& pt) const { return x != pt.x || y != pt.y; } + bool operator==(const wxRealPoint& pt) const + { + return wxIsSameDouble(x, pt.x) && wxIsSameDouble(y, pt.y); + } + bool operator!=(const wxRealPoint& pt) const { return !(*this == pt); } }; + class WXDLLEXPORT wxPoint { public: diff --git a/include/wx/math.h b/include/wx/math.h index a3a8a8f957..72628269cf 100644 --- a/include/wx/math.h +++ b/include/wx/math.h @@ -76,5 +76,26 @@ #define wxIsNaN(x) ((x) != (x)) #endif +#ifdef __cplusplus +#ifdef __INTELC__ +inline bool wxIsSameDouble(double x, double y) +{ + // VZ: this warning, given for operators==() and !=() is not wrong, as == + // shouldn't be used with doubles, but we get too many of them and + // removing these operators is probably not a good idea + #pragma warning(push) + + // floating-point equality and inequality comparisons are unreliable + #pragma warning(disable: 1572) + + return x == y; + + #pragma warning(pop) +} +#else /* !__INTELC__ */ +inline bool wxIsSameDouble(double x, double y) { return x == y; } +#endif /* __INTELC__/!__INTELC__ */ +#endif /* __cplusplus */ + #endif /* _WX_MATH_H_ */ diff --git a/src/common/variant.cpp b/src/common/variant.cpp index b9e2c48cc5..174efc4992 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -36,6 +36,7 @@ using namespace std ; #include "wx/string.h" #include "wx/tokenzr.h" +#include "wx/math.h" #include "wx/variant.h" @@ -55,7 +56,7 @@ public: wxVariantDataList(const wxList& list); ~wxVariantDataList(); - wxList& GetValue() const { return (wxList&) m_value; } + wxList& GetValue() const { return m_value; } void SetValue(const wxList& value) ; virtual void Copy(wxVariantData& data); @@ -454,7 +455,7 @@ bool wxVariantDataReal::Eq(wxVariantData& data) const wxVariantDataReal& otherData = (wxVariantDataReal&) data; - return (otherData.m_value == m_value); + return wxIsSameDouble(otherData.m_value, m_value); } #if wxUSE_STD_IOSTREAM @@ -874,7 +875,7 @@ bool wxVariantDataVoidPtr::Write(wxSTD ostream& str) const bool wxVariantDataVoidPtr::Write(wxString& str) const { - str.Printf(wxT("%ld"), (long) m_value); + str.Printf(wxT("%p"), m_value); return true; } @@ -978,7 +979,7 @@ bool wxVariantDataWxObjectPtr::Write(wxSTD ostream& str) const bool wxVariantDataWxObjectPtr::Write(wxString& str) const { - str.Printf(wxT("%s(%ld)"), GetType().c_str(), (long) m_value); + str.Printf(wxT("%s(%p)"), GetType().c_str(), m_value); return true; } @@ -1391,8 +1392,8 @@ bool wxVariant::operator== (double value) const double thisValue; if (!Convert(&thisValue)) return false; - else - return (value == thisValue); + + return wxIsSameDouble(value, thisValue); } bool wxVariant::operator!= (double value) const