|
|
|
|
|
by kabdib
4296 days ago
|
|
The floating point version is dangerous and broken on platforms that have 64-bit ints. (Not sure what happens with ceil and negative numbers, it probably works, but I'd have to try it). And while not an issue here, since this looks like it's user-space code, it's bad to use floats in a systems programming environment (floats are often in registers that can't be modified or maybe even referenced in kernel contexts without some save/restore shenanigans). The loop version works poorly for large queue sizes, and if I saw this in production code I'd replace it immediately. I'd be okay with a division and re-multiplication (likely going to be optimized by the compiler, through it's foolish to depend on this). I don't see any problem with the mask/not/and solution. This has been a programming idiom for decades, and should be no more mysterious than (say) a doubly-linked list. |
|