I'm not really sure what to search for on this.
If I have a variable A = 10. And another variable B. If B is negative I want to make A = -10. If B is positive I want A = 10.
Here is how I have been doing this quite often:
A = A * abs(B) / B
The obvious issue here is that if B is zero I get a divide by zero error.
Is there a better (preferably mathematical) way to accomplish this without the complexity of conditional statements?
Backstory. I am working with students in a graphical robotics programming language called Lego EV3. The algorithm above looks like this:
Using a conditional statement it looks like this:
Quite the waste of space, especially when you are working on 13" laptop screens. And confusing.