为什么std :: numeric_limits< float> :: min()在用不同的函数进行流输出时的行为有所不同? [英] why does std::numeric_limits<float>::min() differ in behavior when streamed to output with different functions?
问题描述
std :: numeric_limits< float> :: min()
当我调用std :: cout时,得到1.17549e-38的输出值
相反,当我使用
printf(%f,std :: numeric_limits< float> ;: :分钟());
我得到的值是0.000000。
注意当我评估( std :: numeric_limits< float> min()== std :: numeric_limits< float> min()
)时, code> true (这是直观和合乎逻辑的)
所以,任何人都可以向我解释这种差异
cppreference for numeric_limits :
$ std :: numeric_limits< float> :: min( )返回 FLT_MIN
。
$ b
使用%f 显示的返回值(实际上不是
0
) / code>实际上被格式化为固定的小数位数。 '%f'
格式以固定格式打印6个小数位。
您可以使用:
%e =给出科学记数法
%g =处理大浮点数
I got a weird behaviour with
std::numeric_limits<float>::min()
when I call std::cout I get an output value of 1.17549e-38
in contrast when I use
printf("%f", std::numeric_limits<float>::min());
I get a value of 0.000000.
note that when I evaluate (std::numeric_limits<float>::min() == std::numeric_limits<float>::min()
) I get true
(which is intuitive and logical)
so, can any one explain to me this difference in output?
cppreference for numeric_limits:
std::numeric_limits<float>::min()
returns FLT_MIN
.
The returned value (which is not 0
in reality) displayed using %f
is actually formatted to fixed number of decimal places. The '%f'
format prints 6 decimal places in fixed format.
You can use :
%e=gives the scientific notation
%g=handles large floating numbers
这篇关于为什么std :: numeric_limits< float> :: min()在用不同的函数进行流输出时的行为有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!