Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only sign in integer value by objective c?

Tags:

objective-c

I'm wondering a way that get only sign in integer value.

How to get a sign in integer value?

Please your help..

what I want is)

int value =  100;  ====>  result :  1
int value = -100;  ====>  result : -1
int value =    0;  ====>  result :  0
like image 928
S.J. Lim Avatar asked Nov 16 '11 22:11

S.J. Lim


People also ask

How do you declare an int value in Objective-C?

int rc = 0x00; //same as int rc = 0; int is a primitive type in both Obj-C and C that specifies an integer, effectively you are initializing the variable. In the C language you must initialize variables otherwise they could be pointing at a random piece of memory.

What does @() mean in Objective-C?

It's Shorthand writing. In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals.


1 Answers

Trivial.

int signum(int n) { return (n < 0) ? -1 : (n > 0) ? +1 : 0; }
like image 94
Fred Foo Avatar answered Nov 14 '22 20:11

Fred Foo