summaryrefslogtreecommitdiffhomepage
path: root/options/value-traits.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/value-traits.hpp')
-rw-r--r--options/value-traits.hpp29
1 files changed, 7 insertions, 22 deletions
diff --git a/options/value-traits.hpp b/options/value-traits.hpp
index f5b74f73..aeb34cfa 100644
--- a/options/value-traits.hpp
+++ b/options/value-traits.hpp
@@ -3,12 +3,11 @@
#include "slider.hpp"
#include "export.hpp"
-#include <QString>
-
#include <cmath>
-#include <cinttypes>
#include <type_traits>
+#include <QString>
+
namespace options::detail {
template<typename t, typename Enable = void>
@@ -46,8 +45,7 @@ struct default_value_traits
return self::qvariant_from_storage(self::storage_from_value(val));
}
- static constexpr inline
- value_type pass_value(const value_type& x)
+ static constexpr value_type pass_value(const value_type& x)
{
if constexpr(std::is_same_v<value_type, stored_type>)
return x;
@@ -79,26 +77,13 @@ struct value_traits : default_value_traits<t> {};
template<>
struct value_traits<double> : default_value_traits<double>
{
- static bool is_equal(value_type x, value_type y)
- {
- if (x == y)
- return true;
- else
- {
- using I = std::int64_t;
- constexpr int K = 1000;
-
- value_type x_, y_;
-
- return I(std::modf(x, &x_) * K) == I(std::modf(y, &y_) * K) &&
- I(x_) == I(y_);
- }
- }
+ static bool is_equal(value_type x, value_type y) { return std::fabs(x - y) < 1e-6; }
};
-template<> struct value_traits<float> : value_traits<float, double>
+template<>
+struct value_traits<float> : default_value_traits<float>
{
- static constexpr inline value_type pass_value(const value_type& x) { return x; }
+ static bool is_equal(value_type x, value_type y) { return std::fabs(x - y) < 1e-6f; }
};
template<>