Skip to content

Diverging from primitive behavior in overflowing shift #121

@elichai

Description

@elichai

The rust docs say the following about overflowing shift:

If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.
(Source: https://doc.rust-lang.org/std/primitive.u64.html#method.overflowing_shl)
And you can see this via the following code:

#[allow(arithmetic_overflow)]
fn main() {
    let a: u64 = 500;
    let b = a << 119;
    println!("{}", b);
}

Which prints 18014398509481984000.

On the other hand in the implementation here zeros will be returned:

return Self { limbs };

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