C programming: Does float always auto-convert to double when multiplying mixed data types?

后端 未结 5 2383
感动是毒
感动是毒 2021-02-20 14:17

In Steven Prata\'s book \"C Primer Plus\", there\'s a section on Type Conversions, wherein \"The basic rules are\" section has stated in rule 1:

Under K&R C,         


        
5条回答
  •  一整个雨季
    2021-02-20 15:07

    It must refer to the result of binary arithmetic operations of float * float format. In the pre-standard versions of C operands of such expressions were promoted to double and the result had double type.

    For example, here's a quote from "C Reference Manual"

    If both operands are int or char, the result is int. If both are float or double, the result is double.

    In C89/90 already this behavior was changed and float * float expressions produce float result.

    • If either operand has type long double, the other operand is converted to long double
    • Otherwise, if either operand is double, the other operand is converted to double.
    • Otherwise, if either operand is float, the other operand is converted to float.

提交回复
热议问题