- 1

Whats the point of math.abs()

Whats the point of math.abs()? example; int y=math.abs(10);//why say this when i could just say int y=10; ?

15th Apr 2017, 1:00 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
2 Réponses
+ 14
The function returns the absolute value of the received parameter. You use it when you want to convert negative values to their unsigned (positive) values.
15th Apr 2017, 1:04 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Its because you can also pass in variables. And if you want to retrieve the positive value and you cant make sure that the variable wont be negative, then you do Math.abs(variable); Of course for your given example there is no point for that
15th Apr 2017, 1:07 PM
Martin Soukup
Martin Soukup - avatar