C近拍两个数的最小 [英] C Macro for minimum of two numbers
本文介绍了C近拍两个数的最小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想和#定义一个简单的宏返回两个数字中较小的。
I want to make a simple macro with #define for returning the smaller of two numbers.
我怎样才能做到这在C?提出一些想法,看看你是否能使其更加模糊了。
How can i do this in C ? Suggest some ideas, and see if you can make it more obfuscated too.
推荐答案
有关略有模糊,试试这个:
For slightly obfuscated, try this:
#define MIN(a,b) ((((a)-(b))&0x80000000) >> 31)? (a) : (b)
基本上,它减去它们,并着眼于符号位是1个或0。
如果在一个负数减法结果,第一个参数是小
Basically, it subtracts them, and looks at the sign-bit as a 1-or-0. If the subtraction results in a negative number, the first parameter is smaller.
这篇关于C近拍两个数的最小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文