Skip to content

Wrapping shift confusion #1151

@andrewwhitehead

Description

@andrewwhitehead

Currently, num_traits::WrappingShl and WrappingShr are implemented for numeric types. So are the ShlVartime/ShrVartime traits which also have corresponding wrapping shift methods (but vartime).

The method description in num_traits matches the one for u32::wrapping_shl and related standard-library methods, which "masks off" the high bits of the shift. This means that N.wrapping_shl(N::BITS) == N.wrapping_shl(0) == N. This does not correspond with the behaviour in the library, which returns N::ZERO when the shift exceeds the maximum size (for types other than Limb). The standard library calls this unbounded_shl/unbounded_shr (new as of Rust 1.87).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions