diff --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h index 1f80229a9eff40c..ea17178c6afb6a9 100644 --- a/libc/src/__support/str_to_integer.h +++ b/libc/src/__support/str_to_integer.h @@ -11,6 +11,8 @@ #include "src/__support/CPP/limits.h" #include "src/__support/CPP/type_traits.h" +#include "src/__support/CPP/type_traits/make_unsigned.h" +#include "src/__support/big_int.h" #include "src/__support/common.h" #include "src/__support/ctype_utils.h" #include "src/__support/macros/config.h" @@ -77,9 +79,7 @@ template LIBC_INLINE StrToNumResult strtointeger(const char *__restrict src, int base, const size_t src_len = cpp::numeric_limits::max()) { - using ResultType = typename cpp::conditional_t<(cpp::is_same_v || - cpp::is_same_v), - UInt128, unsigned long long>; + using ResultType = make_integral_or_big_int_unsigned_t; ResultType result = 0; @@ -137,13 +137,13 @@ strtointeger(const char *__restrict src, int base, result = abs_max; error_val = ERANGE; } else { - result = result * base; + result = static_cast(result * base); } if (result > abs_max - cur_digit) { result = abs_max; error_val = ERANGE; } else { - result = result + cur_digit; + result = static_cast(result + cur_digit); } } @@ -156,12 +156,7 @@ strtointeger(const char *__restrict src, int base, return {cpp::numeric_limits::min(), str_len, error_val}; } - return { - is_positive - ? static_cast(result) - : static_cast( - -static_cast>(result)), - str_len, error_val}; + return {static_cast(is_positive ? result : -result), str_len, error_val}; } } // namespace internal