Jump to content
  • Advertisement
Sign in to follow this  
mike74

weird code

This topic is 4722 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

In the midst of some sleep deprivation, I wrote some weird code: int areequal(float a, float b, float c, float d) { return (a == b == c == d); } Anyone know what this does? I thought it would return 1 if they were all equal, but it doesn't seem to. Mike C. http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
the only way to do that would be

return (a==b&&a==c&&a==d&&b==c&&b==d&&c==d)

Share this post


Link to post
Share on other sites
Quite easy -

a == b returns 0 or 1,
and since a == b == c is the same as (a == b) == c, then it checks if c is 0 or 1, based on a and b's equality.

etc.

Share this post


Link to post
Share on other sites
You could do

return (a == b && b == c && c == d);

I see it now. It was a simple question.

Thanks.

Mike C.
http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!