resolve float-equals warnings

This commit is contained in:
Crzyrndm 2018-08-18 18:12:46 +12:00
parent b2a514fdbf
commit 61e46c934a
5 changed files with 13 additions and 9 deletions

View File

@ -25,6 +25,7 @@
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/utils/optional.hpp> #include <xlnt/utils/optional.hpp>
#include "../source/detail/numeric_utils.hpp"
namespace xlnt { 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 return lhs.base_col_width == rhs.base_col_width
&& lhs.default_column_width == rhs.default_column_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; && lhs.dy_descent == rhs.dy_descent;
} }

View File

@ -33,6 +33,7 @@
#include <xlnt/utils/optional.hpp> #include <xlnt/utils/optional.hpp>
#include <detail/implementations/format_impl.hpp> #include <detail/implementations/format_impl.hpp>
#include <detail/implementations/hyperlink_impl.hpp> #include <detail/implementations/hyperlink_impl.hpp>
#include "../numeric_utils.hpp"
namespace xlnt { namespace xlnt {
namespace detail { namespace detail {
@ -73,7 +74,7 @@ inline bool operator==(const cell_impl &lhs, const cell_impl &rhs)
&& lhs.row_ == rhs.row_ && lhs.row_ == rhs.row_
&& lhs.is_merged_ == rhs.is_merged_ && lhs.is_merged_ == rhs.is_merged_
&& lhs.value_text_ == rhs.value_text_ && 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.formula_ == rhs.formula_
&& lhs.hyperlink_ == rhs.hyperlink_ && lhs.hyperlink_ == rhs.hyperlink_
&& (lhs.format_.is_set() == rhs.format_.is_set() && (!lhs.format_.is_set() || *lhs.format_.get() == *rhs.format_.get())) && (lhs.format_.is_set() == rhs.format_.is_set() && (!lhs.format_.is_set() || *lhs.format_.get() == *rhs.format_.get()))

View File

@ -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 // 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 // either or both could have been promoted by prior operations
// if a higher precision is required, the template type can be changed // if a higher precision is required, the template type can be changed
constexpr common_t epsilon = std::numeric_limits<EpsilonType>::epsilon(); constexpr common_t epsilon = static_cast<common_t>(std::numeric_limits<EpsilonType>::epsilon());
// the "epsilon" then needs to be scaled into the comparison range // 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 // 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 // in particular, this prevents a lhs of 0 from requiring an exact comparison

View File

@ -22,6 +22,7 @@
// @license: http://www.opensource.org/licenses/mit-license.php // @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file // @author: see AUTHORS file
#include <xlnt/worksheet/page_margins.hpp> #include <xlnt/worksheet/page_margins.hpp>
#include "detail/numeric_utils.hpp"
namespace xlnt { namespace xlnt {
@ -91,11 +92,11 @@ void page_margins::footer(double footer)
bool page_margins::operator==(const page_margins &rhs) const bool page_margins::operator==(const page_margins &rhs) const
{ {
return top_ == rhs.top_ return detail::float_equals(top_, rhs.top_)
&& left_ == rhs.left_ && detail::float_equals(left_,rhs.left_)
&& right_ == rhs.right_ && detail::float_equals(right_, rhs.right_)
&& header_ == rhs.header_ && detail::float_equals(header_, rhs.header_)
&& footer_ == rhs.footer_; && detail::float_equals(footer_, rhs.footer_);
} }
} // namespace xlnt } // namespace xlnt

View File

@ -22,6 +22,7 @@
// @license: http://www.opensource.org/licenses/mit-license.php // @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file // @author: see AUTHORS file
#include <xlnt/worksheet/page_setup.hpp> #include <xlnt/worksheet/page_setup.hpp>
#include "detail/numeric_utils.hpp"
namespace xlnt { namespace xlnt {
@ -114,7 +115,7 @@ bool page_setup::operator==(const page_setup &rhs) const
&& fit_to_page_ == rhs.fit_to_page_ && fit_to_page_ == rhs.fit_to_page_
&& fit_to_height_ == rhs.fit_to_height_ && fit_to_height_ == rhs.fit_to_height_
&& fit_to_width_ == rhs.fit_to_width_ && fit_to_width_ == rhs.fit_to_width_
&& scale_ == rhs.scale_; && detail::float_equals(scale_, rhs.scale_);
} }
} // namespace xlnt } // namespace xlnt