I try to solve a math problem and my output sensitivity has a little different such as 0.07. And then I compare pow()
and powf()
in my code and I see this sensitivity. The code as follows:
int main()
{
int terms, sign=-1;
double x, operation=0.0;
printf("Please enter the number of terms : ");
scanf_s("%d", &terms);
while (terms <= 0)
{
printf("Please re-enter the number of terms :");
scanf_s("%d", &terms);
}
printf("Please enter a value for x :");
scanf_s("%lf", &x);
for (int i = 1; i <= terms; i++)
{
sign = sign * (-1);
operation = operation + sign * powf(x + i / 10.0, (2 * i) - 1) / (2 * i);
}
printf("The result is : %.2lf\n", operation);
system("pause");
return 0;
}
Sample:
terms : 10
x : 1.1
output : `-59783.61` with `powf`
output : `-59783.67` with `pow`
What is the difference between to these functions?