26#ifndef GUL17_NUM_UTIL_H_
27#define GUL17_NUM_UTIL_H_
55template<
typename ValueT>
56constexpr auto abs(
ValueT n)
noexcept -> std::enable_if_t<std::is_unsigned<ValueT>::value,
ValueT>
64template<
typename ValueT>
65constexpr auto abs(
ValueT n)
noexcept -> std::enable_if_t<not std::is_unsigned<ValueT>::value,
ValueT>
96 typename = std::enable_if_t<
97 std::is_arithmetic<NumT>::value
98 and std::is_arithmetic<OrderT>::value
121template<
typename NumT>
126 if (std::is_floating_point<NumT>::value)
131 if (std::is_floating_point<NumT>::value)
155template<
typename NumT,
156 typename = std::enable_if_t<std::is_floating_point<NumT>::value>>
161 auto diff = std::abs(
a -
b);
162 auto maxval = std::max(std::abs(
a), std::abs(
b));
165 if (std::isnormal(
maxval))
172 if (std::isfinite(
maxval))
173 return diff <= std::numeric_limits<NumT>::denorm_min() *
static_cast<NumT>(
ulp);
212 return std::max(
lo, std::min(
v,
hi));
237template<
class NumT,
class Compare>
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:124
bool within_ulp(NumT a, NumT b, unsigned int ulp)
Determine if two numbers are almost equal, allowing for a difference of a given number of units-in-th...
Definition num_util.h:157
bool within_orders(const NumT a, const NumT b, const OrderT orders) noexcept(false)
Determine if two numbers are almost equal, comparing only some significant digits.
Definition num_util.h:100
constexpr auto abs(ValueT n) noexcept -> std::enable_if_t< std::is_unsigned< ValueT >::value, ValueT >
Compute the absolute value of a number.
Definition num_util.h:56
constexpr const NumT & clamp(const NumT &v, const NumT &lo, const NumT &hi)
Coerce a value to be within a given range.
Definition num_util.h:211
bool within_abs(NumT a, NumT b, NumT tol) noexcept
Determine if two numbers are almost equal, allowing for an absolute difference.
Definition num_util.h:122
auto maximum(ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> DataT
Return the maximum element value in a container.
Definition statistics.h:317
Definition of macros used internally by GUL.
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:29