Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Community > MacNN Lounge > converting negative to positive?

converting negative to positive?
Thread Tools
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status: Offline
Reply With Quote
May 23, 2005, 03:42 AM
 
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
Reply With Quote
May 23, 2005, 03:46 AM
 
+20



     
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status: Offline
Reply With Quote
May 23, 2005, 03:50 AM
 
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
Reply With Quote
May 23, 2005, 03:55 AM
 
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
Reply With Quote
May 23, 2005, 03:59 AM
 
Absolute value.
     
Mac Elite
Join Date: Oct 2004
Location: Neither Here Nor There
Status: Offline
Reply With Quote
May 23, 2005, 03:59 AM
 
d'oh
     
Professional Poster
Join Date: Jan 2003
Status: Offline
Reply With Quote
May 23, 2005, 04:01 AM
 
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
Reply With Quote
May 23, 2005, 04:07 AM
 
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
Reply With Quote
May 23, 2005, 04:15 AM
 
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
Reply With Quote
May 23, 2005, 04:23 AM
 
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
Reply With Quote
May 23, 2005, 04:31 AM
 
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
Reply With Quote
May 23, 2005, 04:40 AM
 
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
Reply With Quote
May 23, 2005, 04:41 AM
 
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
Reply With Quote
May 23, 2005, 04:41 AM
 
Times -1

I'm a bird. I am the 1% (of pets).
     
Baninated
Join Date: Jun 2000
Location: Cambridge, Chicago, Jerusalem (school/home/heart)
Status: Offline
Reply With Quote
May 23, 2005, 05:25 AM
 
Omg! This Belongs In The Political Forums!!!!!
     
Administrator
Join Date: Apr 2001
Location: San Antonio TX USA
Status: Offline
Reply With Quote
May 23, 2005, 06:37 AM
 
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
Reply With Quote
May 23, 2005, 01:35 PM
 
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))
     
RGB
Mac Elite
Join Date: Jan 2002
Location: College in the Land of Oz
Status: Offline
Reply With Quote
May 23, 2005, 01:40 PM
 
Originally Posted by Eriamjh
Times -1
Winner.
     
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status: Offline
Reply With Quote
May 23, 2005, 01:42 PM
 
Originally Posted by Eriamjh
Times -1
I was waiting for that... hmmm...
     
Mac Elite
Join Date: Aug 2001
Location: Near Boulder, CO
Status: Offline
Reply With Quote
May 23, 2005, 01:46 PM
 
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
Reply With Quote
May 23, 2005, 02:10 PM
 
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
Reply With Quote
May 23, 2005, 02:15 PM
 
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
Reply With Quote
May 23, 2005, 02:34 PM
 
+1.
     
Mac Elite
Join Date: Aug 2001
Location: Capitol City
Status: Offline
Reply With Quote
May 23, 2005, 02:38 PM
 
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?
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
May 23, 2005, 02:49 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2