▲ | Joker_vD 7 hours ago | |||||||
> So if value was used as signed integer, that's a sign-preserving /2 Only if you define your integer division as rounding towards minus infinity which almost none of the languages do (they usually round towards zero). See e.g. [0] for the additional instructions needed to correct the result. Now, I personally think this is a mistake and my PLs always round integers down instead of towards zero, but others may disagree. | ||||||||
▲ | Findecanor 7 hours ago | parent [-] | |||||||
It's a bit inconsistent that most ISAs out there have division that rounds towards zero but only right shift that rounds down. PowerPC is the only production-ISA I've found that has an arithmetic right-shift instruction designed for rounding towards zero. It sets the Carry flag if a 1 is shifted out and the result is negative. Then only an "add with carry" instruction is needed to adjust the result. | ||||||||
|