Generally, in C, you’d use #include <math.h> to use a round function. However, using that line causes a compiler error. Is there a built-in round() function in RobotC? If not, how can I work around it?
I don’t think ROBOTC has a round function, but one can do:
int round(float x) {
return (f>0)?(int)(f+0.5):(int)(f - 0.5);
}
Source: ROBOTC
I learned something new today: when you cast a float/double to an integer in C, it rounds towards zero, rather than flooring the number.
ROBOTC has a round function, this from (an old) RobotCIntrinsics.c
intrinsic float ceil(const float input)
intrinsic float floor(const float input)
intrinsic long round(const float input)
No need to include <math.h>