Hello,
I'm looking for an efficient way of generating a function that returns the sign of an integer (+1 if x>0, -1 if x<0, and 0 if x==0).
The function below seems to work OK (I'm using Keil uVision) but I cannot help feeling that there is an even quicker way.
__asm static int Sign(int x){ CMP r0, #0 IT NE MOVNE r0, #1 IT MI MOVMI r0, #-1 BX LR}
__asm static int Sign(int x)
{
CMP r0, #0
IT NE
MOVNE r0, #1
IT MI
MOVMI r0, #-1
BX LR
}
Any suggestions?