Skip to content

Commit fafd45e

Browse files
committed
review #553
1 parent 8a05e8f commit fafd45e

File tree

2 files changed

+15
-52
lines changed

2 files changed

+15
-52
lines changed

src/base/anim/interpolated.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ template <typename Type> class Weighted
3434
return value == other.value && weight == other.weight;
3535
}
3636

37-
template <typename Comparator =
38-
std::conditional_t<std::floating_point<Type>,
39-
decltype(Math::Floating::less),
40-
std::less<Type>>>
4137
bool operator<(const Weighted<Type> &other) const
4238
{
43-
return Comparator{}(value, other.value);
39+
using Less = std::conditional_t<std::floating_point<Type>,
40+
decltype(Math::Floating::less),
41+
std::less<Type>>;
42+
return Less{}(value, other.value);
4443
}
4544

4645
[[nodiscard]] bool hasValue() const { return weight > 0.0; }
@@ -224,28 +223,26 @@ template <typename Type> class Interpolated
224223
return res;
225224
}
226225

227-
template <typename T = Type,
228-
typename Cmp = std::conditional_t<std::floating_point<T>,
229-
decltype(Math::Floating::less),
230-
std::less<T>>>
231-
[[nodiscard]] T min() const
226+
template <typename T = Type> [[nodiscard]] T min() const
232227
{
228+
using Less = std::conditional_t<std::floating_point<T>,
229+
decltype(Math::Floating::less),
230+
std::less<T>>;
233231
return !has_second ? this->values[0].value
234232
: std::min(this->values[0].value,
235233
this->values[1].value,
236-
Cmp{});
234+
Less{});
237235
}
238236

239-
template <typename T = Type,
240-
typename Cmp = std::conditional_t<std::floating_point<T>,
241-
decltype(Math::Floating::less),
242-
std::less<T>>>
243-
[[nodiscard]] T max() const
237+
template <typename T = Type> [[nodiscard]] T max() const
244238
{
239+
using Less = std::conditional_t<std::floating_point<T>,
240+
decltype(Math::Floating::less),
241+
std::less<T>>;
245242
return !has_second ? this->values[0].value
246243
: std::max(this->values[0].value,
247244
this->values[1].value,
248-
Cmp{});
245+
Less{});
249246
}
250247
};
251248

src/base/math/floating.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#ifndef MATH_FLOATING
22
#define MATH_FLOATING
33

4-
#include <bit>
54
#include <compare>
65
#include <concepts>
7-
#include <cstdint>
86
#include <limits>
97

108
namespace Math::Floating
@@ -18,43 +16,11 @@ constexpr auto inline less = [](auto a, auto b)
1816
return std::is_lt(std::strong_order(a, b));
1917
};
2018

21-
template <std::floating_point F,
22-
std::size_t v =
23-
std::numeric_limits<F>::is_iec559
24-
&&std::numeric_limits<F>::radix
25-
== 2
26-
&& std::numeric_limits<unsigned char>::digits == 8
27-
? sizeof(F)
28-
: std::size_t{}>
29-
constexpr auto inline can_be_used_as_short_check =
30-
std::bool_constant<false>{};
31-
32-
template <std::floating_point F>
33-
constexpr auto inline can_be_used_as_short_check<F, 4> =
34-
std::integral_constant<std::uint32_t,
35-
std::bit_cast<std::uint32_t>(F{0.0}) == std::uint32_t{}
36-
&& std::bit_cast<std::uint32_t>(F{-0.0})
37-
+ std::bit_cast<std::uint32_t>(F{-0.0})
38-
== std::uint32_t{}>{};
39-
40-
template <std::floating_point F>
41-
constexpr auto inline can_be_used_as_short_check<F, 8> =
42-
std::integral_constant<std::uint64_t,
43-
std::bit_cast<std::uint64_t>(F{0.0}) == std::uint64_t{}
44-
&& std::bit_cast<std::uint64_t>(F{-0.0})
45-
+ std::bit_cast<std::uint64_t>(F{-0.0})
46-
== std::uint64_t{}>{};
47-
4819
constexpr auto inline is_zero = [](auto value)
4920
{
5021
using F = decltype(value);
5122
static_assert(std::floating_point<F>);
52-
if constexpr (auto v = can_be_used_as_short_check<F>; v()) {
53-
const auto val =
54-
std::bit_cast<typename decltype(v)::value_type>(value);
55-
return val + val == 0;
56-
}
57-
else if constexpr (std::numeric_limits<F>::is_iec559) {
23+
if constexpr (std::numeric_limits<F>::is_iec559) {
5824
return value == F{};
5925
}
6026
else {

0 commit comments

Comments
 (0)