23#ifndef GUL17_NUM_UTIL_H_
24#define GUL17_NUM_UTIL_H_
52template<
typename ValueT>
53constexpr auto abs(
ValueT n)
noexcept -> std::enable_if_t<std::is_unsigned<ValueT>::value,
ValueT>
61template<
typename ValueT>
62constexpr auto abs(
ValueT n)
noexcept -> std::enable_if_t<not std::is_unsigned<ValueT>::value,
ValueT>
93 typename = std::enable_if_t<
94 std::is_arithmetic<NumT>::value
95 and std::is_arithmetic<OrderT>::value
118template<
typename NumT>
123 if (std::is_floating_point<NumT>::value)
128 if (std::is_floating_point<NumT>::value)
152template<
typename NumT,
153 typename = std::enable_if_t<std::is_floating_point<NumT>::value>>
158 auto diff = std::abs(
a -
b);
159 auto maxval = std::max(std::abs(
a), std::abs(
b));
162 if (std::isnormal(
maxval))
169 if (std::isfinite(
maxval))
170 return diff <= std::numeric_limits<NumT>::denorm_min() *
static_cast<NumT>(
ulp);
209 return std::max(
lo, std::min(
v,
hi));
234template<
class NumT,
class Compare>
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:121
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:154
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:97
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:53
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:208
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:119
auto maximum(ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> DataT
Return the maximum element value in a container.
Definition statistics.h:314
Definition of macros used internally by GUL.
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:26