floating-point - float 的 PI 和精度

标签 floating-point precision floating-accuracy

Pi 的单/双/扩展精度浮点表示精确到小数点后多少位?

最佳答案

#include <stdio.h>

#define E_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062

int main(int argc, char** argv)
{
    long double pild = E_PI;
    double pid = pild;
    float pif = pid;
    printf("%s\n%1.80f\n%1.80f\n%1.80Lf\n",
    "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899",
    pif, pid, pild);
    return 0;
}

结果:

[quassnoi #] gcc --version
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)

[quassnoi #] ./test

3.14159265358979323846264338327950288419716939937510582097494459230781640628620899

3.14159274101257324218750000000000000000000000000000000000000000000000000000000000
        ^
3.14159265358979311599796346854418516159057617187500000000000000000000000000000000
                 ^
3.14159265358979311599796346854418516159057617187500000000000000000000000000000000
                 ^
  0000000001111111
  1234567890123456

关于floating-point - float 的 PI 和精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/507819/

相关文章:

assembly - float 如何存储在 CPU 中?

mysql - 如何将十进制计算结果存储在mysql中并像在内存中一样将其检索回来

keras - keras Metrices 中的 binary_accuracy,将一个样本预测为正例和负例的阈值是多少

Java-使用 float -构造函数错误

floating-point - Inno Setup - 将整数 652 转换为 float 得到 6.52?

oracle - 从数据库读取整数返回 float

ruby-on-rails - rspec 没有说预期的 : 15. 35,使用 == 得到 : 15. 35,这对我来说没有意义?

c++ - 单/ double SpMV 在 CPU 上的性能

c++ - 如何将浮点值移位到可以精确表示的特定小数位数的最接近的值?

c++ - 计算机如何将 float 转换为十进制字符串?