[英]Adding 2 floats in C
If I have 2 floats and add them together, is the result a float?如果我有 2 个浮点数并将它们加在一起,结果是浮点数吗? Or is a double?
或者是双? Or is it compiler defined behavior?
还是编译器定义的行为?
9.0f + 8.0f <--- is the result float, double or compiler defined behavior? 9.0f + 8.0f <--- 结果是浮点型、双精度型还是编译器定义的行为?
A citation of the correct place in the C specifications would be helpful, if possible.如果可能的话,引用 C 规范中的正确位置会有所帮助。
9.0f + 8.0f
is the result a
float
?结果是
float
吗?
Yes, the type is float
.是的,类型是
float
。
First, if the corresponding real type of either operand is
long double
, the other operand is converted, without change of type domain, to a type whose corresponding real type islong double
.首先,如果任一操作数的对应实数类型为
long double
,则另一个操作数将在不更改类型域的情况下转换为其对应实数类型为long double
的类型。
Otherwise, if the corresponding real type of either operand is
double
, the other operand is converted, without change of type domain, to a type whose corresponding real type isdouble
.否则,如果任一操作数的对应实数类型为
double
,则另一个操作数将在不更改类型域的情况下转换为其对应实数类型为double
的类型。
Otherwise, if the corresponding real type of either operand is
float
, the other operand is converted, without change of type domain, to a type whose corresponding real type isfloat
.否则,如果任一操作数的对应实数类型为
float
,则另一个操作数将在不更改类型域的情况下转换为其对应实数类型为float
的类型。
C23x dr § 6.3.1.8 1 C23x dr § 6.3.1.8 1
Although the type is float
, depending on FLT_EVAL_METHOD
, the sum may have been calculated using float
, double
or long double
math.尽管类型是
float
,但取决于FLT_EVAL_METHOD
,总和可能是使用float
、 double
或long double
数学计算的。 This potentially has arithmetic impact on a larger/different valued expression.这可能会对更大/不同值的表达式产生算术影响。 This part is "compiler implementation defined behavior".
这部分是“编译器实现定义的行为”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.