How can I manually calculate the high part for a signed multiplication in C++? Like Getting the high part of 64 bit integer multiplication (unsigned only), but how do I calculate carry/borrow?
I do not mean that cast in a larger type (thats simple), but really manual calculation, so it works also with int128_t. My goal is to write a template function that always returns the correct high-part for signed and unsigned arguments (u/int8..128_t):
template <typename Type>
constexpr Type mulh(const Type& op1, const Type& op2) noexcept
{
if constexpr (std::is_signed_v<Type>) return ???;
else return see link;
}