Trying to find out what the (float) in this function means:
static float avgEndpoints (int i, int stride, float *fa)
{
return ((float) (fa[i-stride] +
fa[i+stride]) * .5f);
}
The reason I’m confused is the function already returns floating point (or appears to), so what is the (float) doing there?
I’m attempting to port this program to another language and learn a bit of c/c++ at the same time.
Thanks
The
(float)is a cast, which in this example casts the expression(fa[i-stride] + fa[i+stride])to floating point.In this case the cast is redundant and not required (as the expression will be a float anyway due to the
*.5f)