开发者

Is "max(a,b)" missing from Android NDK

There appears to be no max() function in the Android SDK (API level 8). Am i mistaken?

Requirement:

r = max(0, r-1);

I'm reluctant to use the ternary operator because it's time-critical and I can't be sure the compiler will use registers appropriately (to avoid recalc开发者_开发问答ulating r-1).


I know this is an older post, but in NDK-r7b I was able to compile max by changing it to MAX. Hope this helps somebody-


Why not just write if (r < 1) r = 0; else r -= 1;? That performs about as few operations as necessary.

If you have atomicity requirements, I suppose one would have to think a bit harder and use temporaries.


It's in the Math package.

Try:

r = Math.max(0, r-1);


If you're in C, why not just use a macro:

#define MAX(a,b) (((a) > (b)) ? (a) : (b))

r = MAX(0,r-1);

it's probably there anyway (it's in gcc)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜