xte::abs()

Defined in header <xte/math/abs.hpp>

Computes the absolute value of a number. For signed integers, casts to unsigned.


Definition

inline constexpr auto abs = [][[nodiscard]](xte::is_number auto x) static noexcept -> xte::try_unsigned<decltype(x)> { /* ... */ };



Example

static_assert(xte::abs(INT_MIN) == (INT_MAX + 1u));
static_assert(xte::approx_equal(xte::abs(-5.0), 5.0));
[View in Compiler Explorer]