[英]How does C++11 type inference decide between floats or doubles?
Consider this example of type inference: 考虑这个类型推断的例子:
auto var = 1.0 ;
Does this evaluate to a float or double under C++11 type inference?, can this behaviour be controlled? 这是否在C ++ 11类型推断下评估为float还是double?,是否可以控制此行为?
It will be evaluated as a double
and yes, you can control it. 它将被评估为double
,是的,您可以控制它。
In the standard ISO-14882:2011 , 2.14.4 Floating literals , point 1: 在标准ISO-14882: 2011,2.14.4浮动文字中 ,第1点:
The type of a floating literal is double unless explicitly specified by a suffix. 除非后缀明确指定,否则浮动文字的类型为double。 The suffixes f and F specify float, the suffixes l and L specify long double. 后缀f和F指定float,后缀l和L指定long double。 If the scaled value is not in the range of representable values for its type, the program is ill-formed. 如果缩放值不在其类型的可表示值范围内,则程序格式不正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.