Jump to content
  • Advertisement
Sign in to follow this  
mezonx

integer interpolation

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Is it possible to fast lineary interpolate between two integers without using floating point computations, I mean only adding, substracting and multiplying of integers? I googled a little and found that there was an Application Note from Intel about bilerp using MMX but I can't find it on their site. Maybe you have some links about similar techniques (simple fractal linear interpolation algorithm) Thanks

Share this post


Link to post
Share on other sites
Advertisement
Apologies if I misinterpreted your request, but:

inline int interpolate(int a, int b, int percentage) {
return (a*percentage)/100+(b*(100-percentage)/100);
}


would seem like a sensible solution - no floats in there. Of course it depends entirely on what you're using it for.

Share this post


Link to post
Share on other sites
Oops, you have a good point there:
Revised version (position is between 0 and 256):

inline int interpolate(int a, int b, int position) {
return (a * position) >> 8 + (b * (256-position)) >> 8;
}

Share this post


Link to post
Share on other sites
I think this idea with binary fixpoint and shifting will do. There may be some problems with position range but nothing I can't handle.
thanks a lot!

Share this post


Link to post
Share on other sites
Beleive it or not, in the age of the pentium 4 and athlon64, divides aren't so costly that you need to be conscious about them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!