Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shr mismatches primitives integers for negative values #27

Open
huonw opened this issue Oct 22, 2015 · 1 comment
Open

Shr mismatches primitives integers for negative values #27

huonw opened this issue Oct 22, 2015 · 1 comment

Comments

@huonw
Copy link
Contributor

huonw commented Oct 22, 2015

>>'ing a primitive integer (or a GMP Mpz) will round to negative infinity, while ramp currently rounds to zero (same as division). Maybe this should be changed?

extern crate ramp;
extern crate gmp;
use ramp::Int;

fn main() {
    let x = -1;
    let shift = 1;

    let r = Int::from(x);
    let g = gmp::mpz::Mpz::from(x);
    let div = 1i32 << shift;
    println!("ramp {} {}\ngmp  {} {}\ni32  {} {}",
             &r >> shift,
             r / div,
             &g >> shift,
             g / div as u64,
             x >> shift,
             x / div);
}
ramp 0 0
gmp  -1 0
i32  -1 0
@Aatch
Copy link
Owner

Aatch commented Oct 22, 2015

Well right now it says that the bit-shift operators correspond to a multiplication or division by a power-of-two, so the results Ramp gets are correct. That said, I am using the same "pretend it's two's complement" thing for BitOr and BitAnd, so using for the shl/shr isn't too weird.

huonw added a commit to huonw/ramp that referenced this issue Oct 22, 2015
This compares pretty much every operation Ramp exposes against the
result of the same computation performed with GMP.

Several bugs/issues were found, and the corresponding tests are
currently commented out: Aatch#24, Aatch#25, Aatch#26, Aatch#27.
huonw added a commit to huonw/ramp that referenced this issue Oct 22, 2015
This compares pretty much every operation Ramp exposes against the
result of the same computation performed with GMP.

Several bugs/issues were found, and the corresponding tests are
currently commented out: Aatch#24, Aatch#25, Aatch#26, Aatch#27, Aatch#30.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants