Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Moose

Moose Avatar

****
Senior Member

449


August 2005
Returns the opposite of any number, can be a floating number too. :P

Math.toOpposite = function(){
if(!arguments[0]){
return false;
}
var lenum = arguments[0].toString();
if(!lenum.match(/\d/)){
return false;
}
if(lenum.match(/^-/)){
lenum = parseFloat(lenum);
lenum = this.abs(lenum);
} else {
lenum = '-'+lenum;
lenum = parseFloat(lenum);
}
return lenum;
}


Used like:
Math.toOpposite(number)

Enjoy. :P

Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
Greg says:
If you think about machine code it's a bunch of 1s and 0s
Chris 3.0 [New features? Yes.] says:
Anything is possible.
Greg says:
Yeah try to code Metallica
Chris 3.0 [New features? Yes.] says:
:P Yeah, I'll get right on that... right after I learn to fly.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I still say its better for Binary usage. :P

Moose

Moose Avatar

****
Senior Member

449


August 2005
Then use parseInt with a base of 2 on a binary number and then use the method. :P
Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
Greg says:
If you think about machine code it's a bunch of 1s and 0s
Chris 3.0 [New features? Yes.] says:
Anything is possible.
Greg says:
Yeah try to code Metallica
Chris 3.0 [New features? Yes.] says:
:P Yeah, I'll get right on that... right after I learn to fly.

Nate

Nate Avatar

**
Official Member

85


July 2007
The opposite as in 10 to -10?

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Pretty much Nate.

Also, Moose, what about negative binary numbers? Does this work with them?

Mithras

Mithras Avatar

****
Studio Member

600


July 2006
Can't you just multiply the number by -1?


Support Rob Scuderi, the #1 Penguins Defender!

lucifer said:
"Behold: me! I have authority in this building."

.XeroCint

.XeroCint Avatar
OmniXST

***
Dedicated Member

129


September 2006
cant u just use one microsoft's best apps? 'The Calculater'!



12,308

Mithras

Mithras Avatar

****
Studio Member

600


July 2006
Why?

First of all, this is in a code, and secondly, you just need to add (or remove) a negative sign on the front of the number :P


Support Rob Scuderi, the #1 Penguins Defender!

lucifer said:
"Behold: me! I have authority in this building."

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I asked the same thing at one point Mithras, but I understand that Moose knows what he's doing.... I think....

newBookmarkLockedFalling