This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。                                                                                                                        7年前关闭。                                我正在执行此脑麻木任务,其中我必须简化如下的ooooooong表达式:coef = ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) >> 16) * (int)((short)(1024 << 1))) + ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) & 0x0000FFFF) * (int)((short)(1024 << 1))) >> 16)); }那里一定有一个工具可以接受上面的表达,仔细咀嚼,吐出一个更干净,更简单的表达吗?请帮助我-我的大脑麻木了!!! 最佳答案 将其细分(让编译器担心对其进行优化)例如,您可以将inv_nrg >> 16分配给变量inv_nrg_high。 inv_nrg & 0x0000ffff与inv_nrg_low相同一些数字常量也可以简化-(1024 因为永远不等于1,所以(16 == 1? stuff1 : stuff2 )中也可以用stuff2替换一些“死”表达式。我将让您完成实际删除所有多余括号并替换变量的驴工作。这是完全可能的,并且我已经尝试了大部分方法,只是想看看它的作用[对我来说毫无意义,但没关系]。编辑:花了几分钟,我想到了这个:int inv_nrg_high = inv_nrg >> 16;int inv_nrg_low = inv_nrg & 0xFFFF;int nl_sh_p1_sh = ((nl >> 15) + 1) >> 1;int x = ((inv_nrg_high * nl)) + ((inv_nrg_low * nl)) >> 16;int y = (x + inv_nrg * nl_sh_p1_sh);coef = ((y >> 16) * 2048) + ((y & 0x0000FFFF) * 2048) >> 16);[我不是100%确信它是正确的,但距离还不算太远。[看起来像是C预处理器发出的东西,可能是一些复杂的定点数学之类的结果]关于c - 简化looooong表达式。有任何工具吗? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14589552/
10-16 19:04