Skip to content

~(-1 << 64) is incorrect #5987

@dearblue

Description

@dearblue

Finding the 1's complement of a negative integer in the range bigint results in a non-exact value that fluctuates.

% bin/mruby -e 'p 5.times.map { ~(-1 << 64) }'
[-34994079809, -34994079889, -34994079825, -34994079809, -34994079889]

Ruby values are listed for reference.

% ruby32 -e 'p 5.times.map { ~(-1 << 64) }'
[18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615]

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