24 Aug
2013
24 Aug
'13
12:32 a.m.
* J.P. Grossman <jpg@alum.mit.edu> [Aug 24. 2013 08:11]:
Assuming x is a 32-bit integer, here's one way that uses 3 instructions:
int y = x >> 31;
Here you assume that the sign bit gets spread out. IIRC the C standard does not guarantee this ("arithmetic right shift"). Cf. fxtbook, section "1.11 Avoiding branches" p.25ff for a selection of such tricks. The section contains one bad error that has not been documented in the errata. Where is it? Best, jj
int negx = (x ^ y) - y;
J.P.
On Fri, Aug 23, 2013 at 4:25 PM, Warren D Smith <warren.wds@gmail.com>wrote:
suppose my computer wants |x| but it refuses to perform an "if" statement.
What to do?
[...]