how to get sign of a number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

how to get sign of a number

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$positive = ($number >= 0);
:?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

feyd wrote:

Code: Select all

$positive = ($number >= 0);
:?
What about 0? 0 isn't positive...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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:
Post Reply