gpt4 book ai didi

c++ - 如何更准确地打印出双数?

转载 作者:行者123 更新时间:2023-11-28 06:22:10 27 4
gpt4 key购买 nike

<分区>

我想用我的二分法打印出一个双数。我不太清楚怎么办。我可以返回小数点后最多 4 位精度的 double ,但这是我采用的默认值。我如何更准确地打印出来。随心所欲地随时打印。

void bisection(double start, double end, double tol, double (f)(double) ){

double x = (end + start)/2;
double num = f(x);
if( std::abs(num) < tol) {
// return x;
printf("Our approximation is: %20.10f", x);

}

if( num == 0){
return x;
}

if( num < 0){
std::cout << "f(x) is less than 0" << std::endl;
std::cout << "f(x) = " << num << std::endl;
start = x;
bisection(start,end,tol, f );
}
else if(num > 0){
std:: cout << "f(x) is greater than 0" << std::endl;
std::cout << "f(x) = " << num << std::endl;
end = x;
bisection(start,end,tol, f );
}
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com