Giter VIP home page Giter VIP logo

Comments (6)

myrrlyn avatar myrrlyn commented on June 7, 2024 1

Awesome. I've always been afraid these were subtly incorrect and I just didn't have a machine on which to test them.

from bitvec.

obeah avatar obeah commented on June 7, 2024 1

In my case (little-endian) bitvec! makes wrong initialization after 48th bit.
Probably completely different problem, just found this issue while searching for solution.

let bits = bitvec![0, 1, 0, 1, 1, 0, 1, 1, 0, 0,
                   0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
                   0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
                   0, 1, 0, 1, 1, 0, 1, 1, 0, 0,
                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

println!("{:?}", bits);
// BitVec<Lsb0, usize> [
//    0b0101101100000000110000000011000101011011000000001100000000110001,
//    0b000000,
//]

from bitvec.

myrrlyn avatar myrrlyn commented on June 7, 2024 1

Thank you @obeah for this issue report.

The behavior is now fixed on trunk. I will cherry-pick it down into a 0.17.3 patch release later today or this week.

from bitvec.

Alexhuszagh avatar Alexhuszagh commented on June 7, 2024

Some further debugging with a lot of printlns shows that it's store_le that's failing:

println!("0x1234u16.to_le_bytes()={:?}", 0x1234u16.to_le_bytes());
// 0x1234u16.to_le_bytes()=[52, 18]

let u16b = u16::from_ne_bytes(0x1234u16.to_le_bytes());
println!("u16b={:?}", u16b);
// u16b=13330

bytes[..16].store_le(u16b);
println!("bytes[..16]={:?}", bytes[..16]);
// ACTUAL:   bytes[..16]=BitSlice<Lsb0, u8> [01001000, 00101100]
// EXPECTED: bytes[..16]=BitSlice<Lsb0, u8> [00101100, 01001000]

Now, I"m not sure if this is a real issue, or faulty assumptions during unittesting, since to_le_bytes() properly switches the byteorder of the integer from big-endian to little-endian, and store_le properly switches the byteorder again, assuming it's storing a big-endian value as little-endian.

from bitvec.

Alexhuszagh avatar Alexhuszagh commented on June 7, 2024

The more I look at this, the more I believe this is simply a logic bug in the testing suite. The following works, as expected:

let u16b = u16::from_ne_bytes(0x1234u16.to_ne_bytes());
bytes[..16].store_le(u16b);
assert_eq!(bytes[..16].load_le::<u16>(), 0x1234u16);

from bitvec.

Alexhuszagh avatar Alexhuszagh commented on June 7, 2024

On big-endian, one more issue:

let bits: &BitSlice<Local, usize> = bits![1, 0, 1, 1, 0, 1, 0, 0, 1, 0];
println!("bits={:?}", bits);
// bits=BitSlice<Msb0, usize> [0000000000]

The bits macro is therefore broken on big-endian architectures.

from bitvec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.