|
Re: Rounding numbers
Quote:
|
math.Round is a java comand...doesnt work in C
|
Quote:
Originally Posted by Salik Syed
[...] or just write your own function
public int round(double val)
{
if(val-(int)val>=.5)
{
return (int)val+1;
}
else {
return (int)val;
}
}
|
You should just follow his advice. If you do add a round function, remember to should add a declaration for the function to the header (.h) file [edit: or at the top of the .c file if you really want...] (sorry if this is obvious to you, but I'm not sure what kind of experience you have). I'm just curious.. why do you need to round? You should avoid using floating point numbers on a robot's processor, since it's easy to run out of memory on those things. Stick to integers if at all possible. Remember that you don't need pinpoint precision when running the robot.
__________________
Andrew Neilson - Team 772 Alumnus
University of Waterloo Computer Science, Class of 2010
Last edited by neilsonster : 15-12-2006 at 18:57.
|