xieite::abs()

Defined in fragment xieite:abs
(header-only: <xieite/math/abs.hpp>)


Computes the absolute of a value.
If the value is an integer, returns the corresponding unsigned integer type.
Otherwise, uses std::abs for floating-point types.


Declaration

template<xieite::is_arith T>
[[nodiscard]] constexpr xieite::try_unsigned<T> abs(T value) noexcept;


Example

import std;
import xieite;

int main() {
	std::int8_t x = std::numeric_limits<std::int8_t>::min();

	xieite::dump(x);
	xieite::dump(xieite::abs(x));
}
Output:
-128
128
View in Compiler Explorer