我想使用 c/c++ 将大双数 (>1e6) 舍入到最接近但更大的浮点数。我试过这个,但我不确定它总是正确的,也许有一种最快的方法可以做到这一点:
int main() {
// x is the double we want to round
double x = 100000000005.0;
double y = log10(x) - 7.0;
float a = pow(10.0, y);
float b = (float)x;
//c the closest round up float
float c = a + b;
printf("%.12f %.12f %.12f\n", c, b, x);
return 0;
}
谢谢你。