3 ms·
- let shift = if (i / 32) % 2 == 0 { 32 } else { 0 }; + let shift = ((i >> 5) & 1) << 5; Uh, that’s just `let shift = i & 32;`, right? Much easier to read, t
by chrismorgan 2y ago
- let shift = if (i / 32) % 2 == 0 { 32 } else { 0 };
+ let shift = ((i >> 5) & 1) << 5;
Uh, that’s just `let shift = i & 32;`, right? Much easier to read, too, in my opinion.
(Edit: fixed from i % 32 to i & 32.)
- NovaX 2y agoI believe it is (!i & 32) because the bitwise version is an incorrect rewrite. [1] https://news.ycombinator.com/item?id=41830016 https://news.ycombinator.com/item?id=41830016
- urcyanide 2y agoSorry for the confusing example. The bitwise one is correct since I store the binary in u64 with a different endian from the C++ version. (this happens because the C++ version is using a numpy script to do the preprocessing) My bad, I should explain it in a better way. Will update the post.
- urcyanide 2y agoNot really, i \in (0..dim).step_by(32), shift \in {0, 32}, but for `i % 32` it's 0..32
- chrismorgan 2y agoSorry, I wrote `i % 32` by accident, I meant `i & 32`.
- durumu 2y agoI think it's i & 32. Agreed on that being more readable.
- urcyanide 2y agoYes, i&32 is more readable.