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)
精彩评论