SELECT CONVERT(date,'2019-02-01') AS [date],
CONVERT(datetime,'2019-02-01') AS [datetime],
CONVERT(datetime2(0),'2019-02-01') AS [datetime2],
CONVERT(datetimeoffset,'2019-02-01') AS [datetimeoffset];
每当我出于某种原因调用另一个使用(x1 + i * h)作为其参数之一的函数时,它都会收到0.00000000000000001的附加值。例如,如果我将其发送为0.26,它将收到0.26000000000000001,最终导致程序崩溃。
这是程序的C部分:
for(i=0; x1 + i*h <= x2; i++)
这是组装零件:
#include <stdio.h>
#include <math.h>
extern double find_delta1(double(*f)(double), double x0, double eps);
extern double find_delta2(double(*f)(double), double x1, double x2, double h, double eps);
double mysqr(double x)
{
return x*x;
} // mysqr
int main()
{
double x1 = -0.5, x2 = 1.0, x, eps = 0.001, h = 0.01;
x = (x1 + x2) / 2.0;
printf("\nfind_delta1(mysqr,%lf, %lf) = %lf\n", x, eps, find_delta1(mysqr, x, eps));
printf("\nfind_delta2(mysqr, %lf, %lf,%lf, %lf) = %lf\n", x, x2, h, eps, find_delta2(mysqr, x, x2, h, eps));
return 0;
} // main
在LOOP2的第二次迭代中,会出现问题,因为第一次* H = 0,因此没有改变被施加到X1。
如果有人可以告诉我我在做什么错,我将非常感激。