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

Tests fail for i32 when value is -1 #2

Open
archseer opened this issue Jan 21, 2019 · 2 comments
Open

Tests fail for i32 when value is -1 #2

archseer opened this issue Jan 21, 2019 · 2 comments

Comments

@archseer
Copy link

archseer commented Jan 21, 2019

Hi! I'm currently working on integrating this with https://github.com/archSeer/enigma/

Tests seem to fail on debug_assert!(b.tag() == u32::from(tag), "{} == {}", b.tag(), tag);, because tag() returns 15. I added this quickcheck test to the test suite that seems to always reproduce it:

fn nanbox_i32(tag: u8, v: i32) -> TestResult {
    if tag == 0 || tag >= 8 {
        return TestResult::discard();
    }
    unsafe {
        TestResult::from_bool(NanBox::new(tag, v).tag() == tag as u32)
    }
}

I'm currently looking into this -- it seems like one of the bit shifts might be off

@Marwes
Copy link
Owner

Marwes commented Jan 21, 2019

I want to remember that someone pointed out that I got sign extension wrong somewhere. So that might be the cause. Haven't remembered to look into it though.

@archseer
Copy link
Author

archseer commented Jan 21, 2019

I think I figured it out: when directly resizing i32 into u64, rust will sign extend it; whereas converting to u32 first, then u64 will work fine:

fn main(){
        println!("{:#066b}", -1 as i32);
        println!("{:#066b}", -1 as i32 as u32 as u64);

}
0b1111111111111111111111111111111111111111111111111111111111111111
0b0000000000000000000000000000000011111111111111111111111111111111

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