相关疑难解决方法(0)

将一个双倍圆到最近且更大的浮点数

我想使用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)

谢谢.

c c++ floating-point rounding

5
推荐指数
1
解决办法
3087
查看次数

标签 统计

c ×1

c++ ×1

floating-point ×1

rounding ×1