Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Setting an absolute value in Java (http://www.chiefdelphi.com/forums/showthread.php?t=130662)

Zelda (Team702) 26-09-2014 21:50

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.

Brian Selle 26-09-2014 23:02

Re: Setting an absolute value in Java
 
Math.abs(<value>)

Caleb Sykes 27-09-2014 01:36

Re: Setting an absolute value in Java
 
^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:
Code:

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



All times are GMT -5. The time now is 11:41.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi