diff --git a/base/common/wide_integer_impl.h b/base/common/wide_integer_impl.h index 4b4d81ff4e3..f2d94bcd80c 100644 --- a/base/common/wide_integer_impl.h +++ b/base/common/wide_integer_impl.h @@ -261,15 +261,16 @@ struct integer::_impl const long double rhs_max_int_count = rhs_long_double / max_int; - // Won't fit only if long double can hold values >= 2^(64 * 3). - const uint64_t rhs_max_int_count_max_int_count = rhs_max_int_count / max_int; - + // We can't just get the number of iterations like rhs_max_int_count / max_int as it may not fit it int64_t. long double rhs_max_int_count_acc = rhs_max_int_count; self = 0; - for (uint64_t i = 0; i < rhs_max_int_count_max_int_count; ++i) + while (rhs_max_int_count_acc > max_int_long_double) + { self += max_int; + rhs_max_int_count_acc -= max_int_long_double; + } self *= max_int;