Skip to content

Instantly share code, notes, and snippets.

@Makistos
Created October 25, 2013 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Makistos/7153938 to your computer and use it in GitHub Desktop.
Save Makistos/7153938 to your computer and use it in GitHub Desktop.
This simple code snippet shows how interpolating can be done in C using signed integers. The for() loop determinest the range to interpolate from. In this case -100 to +100. For loop is here just to work as an example. 12th line is were the work is done. 256.0 is the top end of the range while 201.0 is the number of values in the list to be inte…
#include <stdio.h>
#include <math.h>
int main()
{
int result;
double x;
int i;
for (i=-100;i<101;i++)
{
x = (256.0/201.0*i +127);
if (x>=0) result = (x+0.5f);
else result = (x-0.5f);
printf("%d => %d\n", i, result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment