Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

madman_k

swap macro done strange

This topic is 5359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i was browsing some code i somehow got (i don''t remember how, but i think it was a tutorial source) and i found this macro definition. #define SWAP(A,B) { (A) ^= (B); (B) ^= (A); (A) ^= (B); } I had never seen a swap implemented this way before and I was wondering if anyone here had. Also wondering if you think it will be more effective then a simple templated inline Swap function in terms of speed? Thanks

Share this post


Link to post
Share on other sites
Advertisement
There was a topic addressing this several days ago. Search for it.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
I''ve seen it. If I recall correctly, I found it to be slower than the "standard" swap method. If you really want to know for sure, do your own tests.

Share this post


Link to post
Share on other sites
thanks. Also, i found some other odd functions there:

#define BIG_NUM ((double)1.5 * (double)(1 << 26) * (double)(1 << 26))

inline int
Round(double a)
{
a += BIG_NUM;
return *(int*)(&a);
}

inline int
Trunc(double a)
{
a += BIG_NUM - 0.5;
return *(int*)(&a);
}

why not for trunc just do:
inline int trunc(double a)
{
return (int) a;
}

and for round:
inline int round(double a)
{
return (int) (a + .5f);
}

do you think there''s a reason behind the way he did it above?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!