Page 1 of 1

how to get sign of a number

Posted: Wed Jul 05, 2006 12:10 pm
by itsmani1
there is a number and i want to know weather its a +ve number or a -ve number how can i find this?

thanks
dizyn

Posted: Wed Jul 05, 2006 12:38 pm
by feyd

Code: Select all

$positive = ($number >= 0);
:?

Posted: Wed Jul 05, 2006 4:11 pm
by Oren
feyd wrote:

Code: Select all

$positive = ($number >= 0);
:?
What about 0? 0 isn't positive...

Posted: Wed Jul 05, 2006 4:25 pm
by feyd
Nor is it negative. So? I'd let itsmani1 choose whether he wants zero to be considered negative or positive or something else.

Posted: Wed Jul 05, 2006 4:40 pm
by Oren
feyd wrote:Nor is it negative. So? I'd let itsmani1 choose whether he wants zero to be considered negative or positive or something else.
I understand what you are saying here... But I don't agree with:
feyd wrote:whether he wants zero to be considered negative or positive or something else.
since it's not open for a discussion... 0 is not positive nor negative.

I still agree with what you are saying in general since there are some cases where you only want to make sure that the number is not negative for example.

Posted: Wed Jul 05, 2006 4:49 pm
by RobertGonzalez
I think the concept Feyd offered is a useful point. Whether the OP wants to check for zero as a value is beside the point. Not to mention that zero, though it is not a negative value, can be associated with positive values as a default non-negative.

But more importantly, Feyd offered a sugestion to get the OP pointed in the proper direction, in my opinion.

Posted: Wed Jul 05, 2006 4:59 pm
by Oren
Everah wrote:I think the concept Feyd offered is a useful point. Whether the OP wants to check for zero as a value is beside the point. Not to mention that zero, though it is not a negative value, can be associated with positive values as a default non-negative.

But more importantly, Feyd offered a sugestion to get the OP pointed in the proper direction, in my opinion.
Again, I agree with you except to this part: "zero, though it is not a negative value, can be associated with positive values as a default non-negative.".
It's right that a non-negative number is a number which is >= 0, that's true, but it still doesn't make zero positive.
Again, I get what you are trying to say guys and I do agree, I'm just a meticulous person... Sorry for that
:wink: