Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math opposite sign function? [closed]

Tags:

function

math

Does such function exist? I created my own but would like to use an official one:

private function opposite(number:Number):Number {     if (number < 0)     {         number = Math.abs(number);     }     else     {         number = -(number);     }     return number; } 

So, -5 becomes 5 and 3 becomes -3.

Edit: Forgive me for being stupid. I'm human. :)

like image 869
Tom Avatar asked Jun 29 '09 17:06

Tom


People also ask

What does opposite signs mean in math?

A number with opposite signs is equidistant from 0 on the number line in opposite directions. The opposite of the opposite of a number is the number itself.

What is the opposite of negative 5?

The opposite of 5 is -5.

How do you find the sign of a number in Python?

sign() in Python. numpy. sign(array [, out]) function is used to indicate the sign of a number element-wise. For integer inputs, if array value is greater than 0 it returns 1, if array value is less than 0 it returns -1, and if array value 0 it returns 0.


1 Answers

yes it does...

return num*-1; 

or simply

return -num; 
like image 65
John T Avatar answered Nov 02 '22 23:11

John T