Hello!
I've occurred some interesting problem when the output precision of the numerical algorithm isn't dependent on its epsilon parameter. Please, look at my simple example where I'm trying to calculate derivative of x^3/3 function at x=1:
Code:
#include <math.h>
#include "stdio.h"
double f(double x)
{
return x*x*x/3;
}
double diff_f(double x)
{
const double eps = 1e-45;
double dx = 1e-4;
double fp_prev, fp_curr;
fp_curr = (f(x+dx) - f(x))/dx;
do{
dx /= 2;
fp_prev = fp_curr;
fp_curr = (f(x+dx) - f(x))/dx;
} while(abs(fp_curr-fp_prev) > eps);
return fp_curr;
}
int main()
{
double x = 1;
printf("f'(%.2f)-1=%e\n",x,diff_f(x)-1);
printf("Press enter...");
getchar();
return 0;
}
On the output program prints calculated value f'(x=1) minus its real value (1). And here one can assure that the output will be the same for
eps = 1e-15; and eps = 1e-25:
Code:
f'(1.00)-1=4.749745e-008
But if we use long double instead double, difference for eps=1e-14 will be ~1e-317. So it would be nice to have a possibility to change capacity of double to long double but without changing whole cpp project, it may be big enough, like ALGLIB for example. Is there some solution for this?