Typecasting a floating value or using the math.h floor* functions?
Posted
by nobody
on Stack Overflow
See other posts from Stack Overflow
or by nobody
Published on 2010-04-04T06:44:30Z
Indexed on
2010/04/04
6:53 UTC
Read the original article
Hit count: 283
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?
© Stack Overflow or respective owner