Skip to content

Questionable operator<< error handling and missing documentation #450

Description

@eisenwave

BOOST_INT128_HOST_DEVICE constexpr int128_t operator<<(const int128_t lhs, const int128_t rhs) noexcept
{
if (rhs.high != 0 || rhs.low >= 128)
{
return 0;
}
return lhs << rhs.low;
}

Some issues with this:

  1. The behavior is to simply treat the error cases (overly large shifts and negative shifts) as resulting in zero, but it's not obvious this would happen. Mathematically, << s means $\times 2^s$, and the rest of the library treats overflow as wrapping. Why would a large shift then neither wrap the shift amount (via bitwise AND) nor wrap the resulting product of the multiplication? It just gives you zero on large shifts, which is what std::shl/Rust u32::unbounded_shl does. However, it's also not consistent about matching std::shl because negative shifts result in zero.

  2. It's not clear from the documentation that overly large shifts and negative shifts are considered undefined behavior or are guaranteed to yield zero.

Metadata

Metadata

Assignees

Labels

Boost ReviewFeedback from the review period including pre- and post- on the MLBugSomething isn't workingdocumentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions