我想使用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;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.