gpt4 book ai didi

c++ - C++ 中的 LONG float 和 double 有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:04:16 25 4
gpt4 key购买 nike

所以我知道 float 和 double 的精度有很大的不同。我明白了。 promise 。

但是,在 C++ 中,当调用 scanf 和 printf 时,用于指定 double 的符号是“%lf”,它代表 long float,对吗?因此,虽然 float 不如 double 精确,但 LONG float(可能称为 long float,因为它可以通过具有更多项而“更长”)具有相同的精度,因此本质上是相同的东西?

澄清一下,我的意思是:

double number = 3.14159;
printf("The number is %lf", number);

所以我的问题的根源是:long float 是 double 的另一个名称吗?

最佳答案

据我所知,没有long float这样的类型。

This post为您提供有关人们为什么使用 lf 来打印 doubleprintf 的信息,如果这是您混淆的原因。

由@Jerry Coffin 提供:

"%f" is the (or at least "a") correct format for a double. There is no format for a float, because if you attempt to pass a float to printf, it'll be promoted to double before printf receives it. "%lf" is also acceptable under the current standard -- the l is specified as having no effect if followed by the f conversion specifier (among others).

所以原因是当人们这样做时:

 printf("The number is %lf", number);

相当于做:

printf("The number is %f", number); //l has no effect when printing double

关于c++ - C++ 中的 LONG float 和 double 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16863826/

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