get 2 numbers and return the second number with the sign of the first number

19 Views Asked by At

I know it's more about programming, but I can use arithmetic operators only so I think it fits the math community.

1

There are 1 best solutions below

1
On BEST ANSWER

If $x$ is not zero, its sign is $|x|/x$. Thus you'd just need to return $|xy|/x$, where $x$ is the first number, and $y$ is the second number (assuming we don't care about the second number's sign).

E.g. $x=5$ and $y=-3$ gives $|5(-3)|/5 = 3$.

If one of them is zero, I guess it would depend on the application. Do you have a positive/negative zero?