Using code, I need to select one of 3 values. d1, d2 and d3.
I need the value of the variable that has the smallest absolute value.
(3, -5, 10) = 3
(-10, -2, 5) = -2
If I had if statements and an abs() function I would do something like this:
- Code: Select all
a1 = abs(d1);
a2 = abs(d2);
a3 = abs(d3);
if(a1 < a2 && a1 < a3) value = d1;
if(a2 < a1 && a2 < a3) value = d2;
if(a3 < a1 && a3 < a2) value = d3;
How would I do that in SM code?
Or would it be easier to use components?
edit: Renamed Thread from "Selecting a value depending on absolute value?"