i am facing the problem of displaying the sine values in integer format. I am trying to create a sine look up table. Just for testing i showing 10 values. I am getting fractional part but want to convert to integer and store in an array, but not able to convert. what is the mistake
Code:
#include <stdio.h>
#include <math.h>
int main(int argc, char const *argv[])
{
int index=0;
printf("fractional values \n");
for(index=0; index <= 10; index++)
{
printf("%f,\n", 1000.0*sinf(2*3.14159*index/1000));
}
printf("Converted to integer values \n");
for(index=0; index <= 10; index++)
{
printf("%d\n",(int)1000*sinf(2*3.14159*index/1000) );
}
return 0;
}
output is like this
Code:
fractional values
0.000000,
6.283139,
12.566029,
18.848424,
25.130074,
31.410731,
37.690152,
43.968081,
50.244275,
56.518488,
62.790463,
Converted to integer value
0
270415556
-1928745506
1438052426
-2118917277
-1456629062
-447103537
354588366
1679953399
-753718746
-427015548