Setting an absolute value in Java

Hey everyone, I have a question that I’ve had for quite a while that no one seems to know the answer too. I’m a semi-new programmer for my team, I’ve been coding for them for about a year or so. I recently took charge of the programming subteam and have switched the team over to Java from C++. Now recently I was reprogramming our robot from Arial Assist and realized I have no idea how to set an absolute value in Java! In C++ I used to be able to use the fabs command, but it doesn’t seem to work the same in Java.

If anyone knows the answer to my question please let me know. We are using Talons if that is of any use knowing. Thank you for taking the time to help another team out! I’ll be FOREVER grateful.

Math.abs(<value>)

^Math.abs() is the way to go.

Just as a thought experiment though, you should be able to make your own abs() function in just a few lines of code. Something like:


double abs(double val) 
{
     if(val < 0)
          return -val;
     else
          return val;
}