absUnsign

fnauto absUnsign(T)(T x) if (isIntegral!T)

Returns the absolute value of an integral type as an unsigned type.

This function converts a signed or unsigned integral value to its absolute value represented as an unsigned type. For signed types, negative values are converted to positive. For unsigned types, the value is returned as-is.

This is a module-level free function for compatibility with std.bigint.

Parameters

xThe integral value to convert

Returns

The absolute value of x as an unsigned type

Example:

assert(absUnsign(5) == 5);
assert(absUnsign(-5) == 5);
assert(absUnsign(int.min) == cast(uint)int.min);