[libcxx-commits] [libcxx] [libc++] Implement std::gcd using the binary version (PR #77747)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat May 4 14:26:08 PDT 2024


serge-sans-paille wrote:

> I have no more performance concerns and LGTM % two hanging comments.
> 
> Please add to test values numbers around limits instead of only limits:
> 
> ```c++
>       std::numeric_limits<Input>::min(),
>       std::numeric_limits<Input>::min() + 1,
>       std::numeric_limits<Input>::min() + 2,
>       std::numeric_limits<Input>::max(),
>       std::numeric_limits<Input>::max() - 1,
>       std::numeric_limits<Input>::max() - 2,
> ```

done

> could you also comment on that change:
> 
> ```diff
> -      return -static_cast<_Result>(__t);
> +      return static_cast<_Result>(-static_cast<std::make_unsigned_t<_Result>>(__t));
> ```
> 
> Why that change? When does it change the result?

I wasn't aware that gcd is UB when one of its argument absolute value cannot be represented in the result type. I dismissed this change.

https://github.com/llvm/llvm-project/pull/77747


More information about the libcxx-commits mailing list