 |
 |
converting negative to positive?
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status:
Offline
|
|
What's the formula for converting a negative to a positive.
Eg how to I convert -10 to 10?
I know its something stupidly simple but I had a beer for lunch and its wiped my memory.
Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2004
Location: Neither Here Nor There
Status:
Offline
|
|
+20

|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status:
Offline
|
|
Originally Posted by Albert Pujols
+20
Not really what I was after, it had to work for all numbers, not just -10
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2004
Location: Neither Here Nor There
Status:
Offline
|
|
um, I don't know what you want...but
x+(-3.141)=3.141 Just add x to the negative number you have and you have your positive?
My bad if I'm wrong, I have to "wake up" for school in an hour.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2003
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2004
Location: Neither Here Nor There
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2003
Status:
Offline
|
|
Originally Posted by Albert Pujols
um, I don't know what you want...but
x+(-3.141)=3.141 Just add x to the negative number you have and you have your positive?.
What the?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2004
Location: Neither Here Nor There
Status:
Offline
|
|
Originally Posted by f1000
What the?
haha..it made sense to me at the time
x-10=10
x=20
-10+20=10
|-10|=10
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status:
Offline
|
|
I figured it out (please don't laugh)
Assuming x is a negative number
x=(x-x-x)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2004
Location: Neither Here Nor There
Status:
Offline
|
|
oh...math is gay. What has math done for me..nothing.
edit: that formula isn't exactly right but whatever.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2000
Location: Los Angeles
Status:
Offline
|
|
Haha, I thought this thread would contain up-beat, cheery advice and other life-affirming platitudes.
|

"The natural progress of things is for liberty to yield and government to gain ground." TJ
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
Absolute value. Most programming languages and spreadsheets have an abs() function for this purpose.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
The standard C libraries have this function, but here's a quick implementation for integers:
Code:
int abs(int number){
if (number <= 0) {
return number * -1;
}
else {
return number;
}
}
(Last edited by Millennium; May 23, 2005 at 04:54 AM.
(Reason:Changed from Python to C; stupid tabs...))
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Oct 2001
Location: BFE
Status:
Offline
|
|
|
|

I'm a bird. I am the 1% (of pets).
|
| |
|
|
|
 |
|
 |
|
Baninated
Join Date: Jun 2000
Location: Cambridge, Chicago, Jerusalem (school/home/heart)
Status:
Offline
|
|
Omg! This Belongs In The Political Forums!!!!!
|
|
|
| |
|
|
|
 |
|
 |
|
Administrator 
Join Date: Apr 2001
Location: San Antonio TX USA
Status:
Offline
|
|
The "mathematical formula" for absolue value is almost identical to the code Millenium posted...or actually the code is almost identical to the formula.
Anyway, absolute value is "displacement from zero," so it MUST be positive. That yields the following:
If X < 0 then |X| = X * -1. Otherwise |X| = X.
It really is that simple.
P.S., the symbol for absolute value is "|X|" We started using it here without pointing that out.
|
|
Glenn -----
OTR/L, MOT, Tx
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2003
Status:
Offline
|
|
In the old C days, I believe abs() used to be implemented as a macro, though such an optimization is probably not that important anymore:
#define abs(a) (((a) < 0) ? -(a) : (a))
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2002
Location: College in the Land of Oz
Status:
Offline
|
|
Originally Posted by Eriamjh
Times -1
Winner.
|
|
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status:
Offline
|
|
Originally Posted by Eriamjh
Times -1
I was waiting for that... hmmm...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Aug 2001
Location: Near Boulder, CO
Status:
Offline
|
|
Originally Posted by Eriamjh
Times -1
That is the simplest way to do it, but it also works the other way too...
Zach
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
Originally Posted by Eriamjh
Times -1
Not quite; you only multiply by -1 if the number is already negative. If it's positive, you just leave the number as it is.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status:
Offline
|
|
Originally Posted by Millennium
Not quite; you only multiply by -1 if the number is already negative. If it's positive, you just leave the number as it is.
but that wasn't the question...
What's the formula for converting a negative to a positive.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2002
Location: USA
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Aug 2001
Location: Capitol City
Status:
Offline
|
|
This thread cracks me up. I didn't know there was some magical number for converting a negative number to its positive self!
y = -x
Was this really a serious question?
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
Took long enough to come to -1. Geez. But yeah, I was thinking "well you can only -1 it if it's less than 0" but Mill posted an abs() function so it's all good.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|