Properly initialize math::interval<util::fixed_point>
This commit is contained in:
parent
8a739bf637
commit
7300679f56
1 changed files with 37 additions and 5 deletions
|
|
@ -9,36 +9,68 @@
|
||||||
namespace psemek::math
|
namespace psemek::math
|
||||||
{
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept has_min = requires ()
|
||||||
|
{
|
||||||
|
{ T::min() } -> std::same_as<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept has_max = requires ()
|
||||||
|
{
|
||||||
|
{ T::max() } -> std::same_as<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Can be specialized in client code
|
// Can be specialized in client code
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct limits
|
struct limits
|
||||||
{
|
{
|
||||||
static constexpr T min()
|
static constexpr T min()
|
||||||
{
|
{
|
||||||
if constexpr (std::is_floating_point_v<T>)
|
if constexpr (detail::has_min<T>)
|
||||||
|
{
|
||||||
|
return T::min();
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_floating_point_v<T>)
|
||||||
{
|
{
|
||||||
return -std::numeric_limits<T>::infinity();
|
return -std::numeric_limits<T>::infinity();
|
||||||
}
|
}
|
||||||
else
|
else if constexpr (std::is_integral_v<T>)
|
||||||
{
|
{
|
||||||
return std::numeric_limits<T>::min();
|
return std::numeric_limits<T>::min();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static_assert("unknown type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr T max()
|
static constexpr T max()
|
||||||
{
|
{
|
||||||
if constexpr (std::is_floating_point_v<T>)
|
if constexpr (detail::has_max<T>)
|
||||||
|
{
|
||||||
|
return T::max();
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_floating_point_v<T>)
|
||||||
{
|
{
|
||||||
return std::numeric_limits<T>::infinity();
|
return std::numeric_limits<T>::infinity();
|
||||||
}
|
}
|
||||||
else
|
else if constexpr (std::is_integral_v<T>)
|
||||||
{
|
{
|
||||||
return std::numeric_limits<T>::max();
|
return std::numeric_limits<T>::max();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static_assert("unknown type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct interval_iterator
|
struct interval_iterator
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue