0
How to convert negative number to positive without abs and if
6 Respuestas
+ 12
Your requirement is strange but I believe basic arithmetic works:-
☑ 0 - negative number = positive number
☑ -1 * negative number = positive number
@Sergey suggestion is same with the latter approach above.
+ 8
absolute value is the same as
sqrt(x**2)
+ 5
x=max(-x,x)
it will keep positive, and change the sign of negative, it it works as abs(). :)
+ 4
You can use number-2*number.
+ 4
And another, rather silly way, usually applied on variable, -n, where n contains a negative number ;)
+ 1
thanks for answers all