Typecasting a floating value or using the math.h floor* functions?
- by nobody
Hi,
I am coding up an implementation of Interpolation Search in C.
The question is actually rather simple, I need to use the floating operations to do linear interpolation to find the correct index which will eventually be an integer result.
In particular my probe index is:
t = i + floor((((k-low)/(high-low)) * (j-i)));
where, i,j,k,t are unsigned ints, and high,low are doubles.
Would this be equivalent to:
t = i + (unsigned int)(((k-low)/(high-low)) * (j-i));
Is there any reason I would actually want to use math.h floor* functions over just a simple (int) typecast?