mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fuzzy floating point comparison with optional
This commit is contained in:
parent
3db87244f1
commit
19aad52500
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <xlnt/xlnt_config.hpp>
|
#include <xlnt/xlnt_config.hpp>
|
||||||
#include <xlnt/utils/exceptions.hpp>
|
#include <xlnt/utils/exceptions.hpp>
|
||||||
|
#include <detail/numeric_utils.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
@ -49,6 +50,23 @@ class optional
|
||||||
using set_move_noexcept_t = typename std::conditional<std::is_nothrow_move_constructible<T>{} && std::is_nothrow_move_assignable<T>{}, std::true_type, std::false_type>::type;
|
using set_move_noexcept_t = typename std::conditional<std::is_nothrow_move_constructible<T>{} && std::is_nothrow_move_assignable<T>{}, std::true_type, std::false_type>::type;
|
||||||
using clear_noexcept_t = typename std::conditional<std::is_nothrow_destructible<T>{}, std::true_type, std::false_type>::type;
|
using clear_noexcept_t = typename std::conditional<std::is_nothrow_destructible<T>{}, std::true_type, std::false_type>::type;
|
||||||
#endif
|
#endif
|
||||||
|
/// <summary>
|
||||||
|
/// Default equality operation, just uses operator==
|
||||||
|
/// </summary>
|
||||||
|
template <typename T, typename std::enable_if<!std::is_floating_point_v<T>>::type * = nullptr>
|
||||||
|
constexpr bool compare_equal(const T &lhs, const T &rhs) const
|
||||||
|
{
|
||||||
|
return lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// equality operation for floating point numbers. Provides "fuzzy" equality
|
||||||
|
/// </summary>
|
||||||
|
template <typename T, typename std::enable_if<std::is_floating_point_v<T>>::type * = nullptr>
|
||||||
|
constexpr bool compare_equal(const T &lhs, const T &rhs) const
|
||||||
|
{
|
||||||
|
return detail::float_equals(lhs, rhs);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -281,7 +299,8 @@ public:
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return value_ref() == other.value_ref();
|
// equality is overloaded to provide fuzzy equality when T is a fp number
|
||||||
|
return compare_equal(value_ref(), other.value_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user