Skip to content

cannot cast between signed <-> unsigned #129

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

Closed
burrbull opened this issue Sep 4, 2018 · 3 comments
Closed

cannot cast between signed <-> unsigned #129

burrbull opened this issue Sep 4, 2018 · 3 comments
Labels

Comments

@burrbull
Copy link
Contributor

burrbull commented Sep 4, 2018

Bug?

  let i = -1000i32;
  let ii =  i32x2::new(i,i);
  let uu =  u32x2::from(ii);
57 |   let uu =  u32x2::from(ii);
   |             ^^^^^^^^^^^ the trait `std::convert::From<packed_simd::Simd<[i32; 2]>>` is not implemented for `packed_simd::Simd<[u32; 2]>`
@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 4, 2018

This is intended behavior, you want let uu: u32x2 = ii.cast(); which is pretty much like as. Note that:

fn main() {
  let i = -1000i32;
  let u =  u32::from(i);
}

also produces the same error. From/Into perform lossless value preserving conversions, but the conversion you want to perform is not value preserving for all values. For primitive types, you could use TryFrom/TryInto which return an Option<u32> with Some or None depending of for the particular value provided the conversion was value-preserving, but for a negative integer conversion into an unsigned integer it will always return None since that is never value preserving. There is a section in the main documentation explaining this, but it basically means that the same rules apply for the vector types and for the primitive types: https://rust-lang-nursery.github.io/packed_simd/packed_simd/#conversions

@gnzlbg gnzlbg closed this as completed Sep 4, 2018
@gnzlbg gnzlbg added the Question label Sep 4, 2018
@burrbull
Copy link
Contributor Author

burrbull commented Sep 4, 2018

Thanks for new docs.

@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 4, 2018

The docs.rs builds are sadly broken (see #110), I'll do a release once that is fixed so that these become more easily discoverable. Right now they are linked in the readme if you need to find these again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants