.. _libcudacxx-extended-api-math-uabs: ``cuda::uabs`` ==================================== Defined in the ```` header. .. code:: cuda namespace cuda { template [[nodiscard]] __host__ __device__ constexpr cuda::std::make_unsigned_t uabs(T value) noexcept; } // namespace cuda The function computes the absolute value of the input value. The result is returned as an unsigned integer type of the same size as the input value. In comparison to the standard ``abs`` function, the ``uabs`` eliminates the undefined behaviour when a signed ``T_MIN`` is passed as an input. **Parameters** - ``value``: The input value. **Return value** - The unsigned absolute value of the input value. **Constraints** - ``T`` is an integer type. Example ------- .. code:: cuda #include #include #include __global__ void uabs_kernel() { using cuda::std::numeric_limits; assert(cuda::uabs(20) == 20u); assert(cuda::uabs(-32) == 32u); assert(cuda::uabs(numeric_limits::max()) == static_cast(numeric_limits::max())); assert(cuda::uabs(numeric_limits::min()) == static_cast(numeric_limits::max()) + 1); } int main() { uabs_kernel<<<1, 1>>>(); cudaDeviceSynchronize(); return 0; } `See it on Godbolt 🔗 `__