N
Noob
Hello,
Considering a properly initialized unsigned int variable v,
are -v and ~(v-1) equivalent for any value of v, even on
the DS9k?
(let <-> mean "are equivalent for any value of v")
According to C89 3.3.3.3
~v <-> UINT_MAX - v
Thus
~(v-1) <-> UINT_MAX - (v-1)
~(v-1) <-> UINT_MAX - v + 1
~(v-1) <-> (UINT_MAX + 1) - v
Adding (UINT_MAX + 1) to an unsigned int variable is a NOP,
thus ~(v-1) <-> -v
I think this is true always, I don't think the "usual arithmetic
conversions" come in play in problematic ways?
Regards.
Considering a properly initialized unsigned int variable v,
are -v and ~(v-1) equivalent for any value of v, even on
the DS9k?
(let <-> mean "are equivalent for any value of v")
According to C89 3.3.3.3
~v <-> UINT_MAX - v
Thus
~(v-1) <-> UINT_MAX - (v-1)
~(v-1) <-> UINT_MAX - v + 1
~(v-1) <-> (UINT_MAX + 1) - v
Adding (UINT_MAX + 1) to an unsigned int variable is a NOP,
thus ~(v-1) <-> -v
I think this is true always, I don't think the "usual arithmetic
conversions" come in play in problematic ways?
Regards.