Skip to content

Mod operator with negative number and big number is off by one #3931

@batessr

Description

@batessr

I am trying to use Truffle Ruby with a project that uses the Jose gem. It gets an error when loading. I have isolated the problem with the mod operator with a negative number and a large number:

Given the following expression:

a = -390081 % ((2**448)-(2**224)-1)

In MRI Ruby and JRuby 10:
a will be:

726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498017975358

In Truffle Ruby:
a will be one less:

726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498017975357

Test code:

a = -390081 % ((2**448)-(2**224)-1)
puts "a #{a}"
puts "MRI Ruby value match #{a==726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498017975358}"

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