From 61e46c934a101f4199073aa487e97d5644235d09 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sat, 18 Aug 2018 18:12:46 +1200 Subject: [PATCH] resolve float-equals warnings --- include/xlnt/worksheet/sheet_format_properties.hpp | 3 ++- source/detail/implementations/cell_impl.hpp | 3 ++- source/detail/numeric_utils.hpp | 2 +- source/worksheet/page_margins.cpp | 11 ++++++----- source/worksheet/page_setup.cpp | 3 ++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/xlnt/worksheet/sheet_format_properties.hpp b/include/xlnt/worksheet/sheet_format_properties.hpp index 52e4ceb1..dd63685d 100644 --- a/include/xlnt/worksheet/sheet_format_properties.hpp +++ b/include/xlnt/worksheet/sheet_format_properties.hpp @@ -25,6 +25,7 @@ #include #include +#include "../source/detail/numeric_utils.hpp" namespace xlnt { @@ -59,7 +60,7 @@ inline bool operator==(const sheet_format_properties &lhs, const sheet_format_pr { return lhs.base_col_width == rhs.base_col_width && lhs.default_column_width == rhs.default_column_width - && lhs.default_row_height == rhs.default_row_height + && detail::float_equals(lhs.default_row_height, rhs.default_row_height) && lhs.dy_descent == rhs.dy_descent; } diff --git a/source/detail/implementations/cell_impl.hpp b/source/detail/implementations/cell_impl.hpp index 64756770..59916331 100644 --- a/source/detail/implementations/cell_impl.hpp +++ b/source/detail/implementations/cell_impl.hpp @@ -33,6 +33,7 @@ #include #include #include +#include "../numeric_utils.hpp" namespace xlnt { namespace detail { @@ -73,7 +74,7 @@ inline bool operator==(const cell_impl &lhs, const cell_impl &rhs) && lhs.row_ == rhs.row_ && lhs.is_merged_ == rhs.is_merged_ && lhs.value_text_ == rhs.value_text_ - && lhs.value_numeric_ == rhs.value_numeric_ + && float_equals(lhs.value_numeric_, rhs.value_numeric_) && lhs.formula_ == rhs.formula_ && lhs.hyperlink_ == rhs.hyperlink_ && (lhs.format_.is_set() == rhs.format_.is_set() && (!lhs.format_.is_set() || *lhs.format_.get() == *rhs.format_.get())) diff --git a/source/detail/numeric_utils.hpp b/source/detail/numeric_utils.hpp index 0b6458e6..554c3b13 100644 --- a/source/detail/numeric_utils.hpp +++ b/source/detail/numeric_utils.hpp @@ -102,7 +102,7 @@ float_equals(const LNumber &lhs, const RNumber &rhs, // epsilon type defaults to float because even if both args are a higher precision type // either or both could have been promoted by prior operations // if a higher precision is required, the template type can be changed - constexpr common_t epsilon = std::numeric_limits::epsilon(); + constexpr common_t epsilon = static_cast(std::numeric_limits::epsilon()); // the "epsilon" then needs to be scaled into the comparison range // epsilon for numeric_limits is valid when abs(x) <1.0, scaling only needs to be upwards // in particular, this prevents a lhs of 0 from requiring an exact comparison diff --git a/source/worksheet/page_margins.cpp b/source/worksheet/page_margins.cpp index 77faec5b..fc1c69c2 100644 --- a/source/worksheet/page_margins.cpp +++ b/source/worksheet/page_margins.cpp @@ -22,6 +22,7 @@ // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #include +#include "detail/numeric_utils.hpp" namespace xlnt { @@ -91,11 +92,11 @@ void page_margins::footer(double footer) bool page_margins::operator==(const page_margins &rhs) const { - return top_ == rhs.top_ - && left_ == rhs.left_ - && right_ == rhs.right_ - && header_ == rhs.header_ - && footer_ == rhs.footer_; + return detail::float_equals(top_, rhs.top_) + && detail::float_equals(left_,rhs.left_) + && detail::float_equals(right_, rhs.right_) + && detail::float_equals(header_, rhs.header_) + && detail::float_equals(footer_, rhs.footer_); } } // namespace xlnt diff --git a/source/worksheet/page_setup.cpp b/source/worksheet/page_setup.cpp index c832d5f4..087d980c 100644 --- a/source/worksheet/page_setup.cpp +++ b/source/worksheet/page_setup.cpp @@ -22,6 +22,7 @@ // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #include +#include "detail/numeric_utils.hpp" namespace xlnt { @@ -114,7 +115,7 @@ bool page_setup::operator==(const page_setup &rhs) const && fit_to_page_ == rhs.fit_to_page_ && fit_to_height_ == rhs.fit_to_height_ && fit_to_width_ == rhs.fit_to_width_ - && scale_ == rhs.scale_; + && detail::float_equals(scale_, rhs.scale_); } } // namespace xlnt