Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

SWAP

Name: Anonymous 2011-10-17 15:25


#define SWAP(a, b) ((&(a) == &(b)) || \
                    (((a) -= (b)), ((b) += (a)), ((a) = (b) - (a))))


ENTERPRISE SWAPPING

inb4 overflow

Name: Anonymous 2011-10-17 17:08

overflow wraps around anyway

Name: Anonymous 2011-10-17 17:37


#define SWAP(a,b,c)  c = a;\
                     a = b;\
                     a = c

Name: Anonymous 2011-10-17 17:43

>>3
This is a masterpiece.

Name: Anonymous 2011-10-17 17:49

>>1
floating point precision

Name: Anonymous 2011-10-17 18:31

>>3
What a bloat

Name: Anonymous 2011-10-17 20:02

Jesus, that's clever, >>1.
Show more of your work!

|10/10|

Name: Anonymous 2011-10-17 20:31

>>7
Let x,y,m be integers

Maximum Function:
m = x ^ ((x ^ y) & -(x < y));
where r ends up as the maximum of x and y

Minimum Function:
m = y ^ ((x ^ y) & -(x < y));
where r ends up as the minimum of x and y

Name: swagger 2011-10-17 21:05

#define SWAG(a, b) ((&(a) == &(b)) || \
                    (((a) -= (b)), ((b) += (a)), ((a) = (b) - (a))))

Name: Anonymous 2011-10-17 21:10

>>9
not enough!
#define SWAG(a, b) do((&(a) == &(b)) || \
                    (((a) -= (b)), ((b) += (a)), ((a) = (b) - (a))))while(0)

Name: Anonymous 2011-10-17 21:23

>>10
guess I got my swagger back

Name: Anonymous 2011-10-17 22:17

That's really clever, and it's cool to see, but xor swap is probably faster, seeing how the xor operation is simpler to do than addition (at least I as a human being could do an xor a lot faster than an addition. I don't know about how intense modern architectures are...)


#define eXchange(a, b) do{(&(a) == &(b)) ||    \
                           ((a) ^= (b),        \
                            (b) ^= (a),        \
                            (a) ^= (b))}while(0)

Name: Anonymous 2011-10-17 23:32

>>11
TRUTH
NEW WATCH ALERT

Name: Anonymous 2011-10-17 23:54


 mov eax, [a]
 xchg eax, [b]

Don't change these.
Name: Email:
Entire Thread Thread List