C编程:是否永远漂浮自动转换到混合乘以数据类型时增加一倍? [英] C programming: Does float always auto-convert to double when multiplying mixed data types?

查看:118
本文介绍了C编程:是否永远漂浮自动转换到混合乘以数据类型时增加一倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在史蒂芬煎饼的书C的Primer Plus,还有在类型转换一节,其中基本规则部分第1条阐明:

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, but not under current C, float is automatically converted to double.

<一个href=\"http://www.9wy.net/onlinebook/CPrimerPlus5/ch05lev1sec5.html\">http://www.9wy.net/onlinebook/CPrimerPlus5/ch05lev1sec5.html

有人能解释什么而不是在当前的C 意味着什么?有没有的C版本的自动转换,并且没有版本?

Could someone explain what but not under current C means? Are there versions of C that auto-convert and versions that don't?

我想,当它评估明白,如果我有一个前pression混合了花车和双打,我可以依靠C到促进花车双打?

I'm trying understand if I have an expression that mixes floats and doubles, can I rely on C to promote floats to doubles when it's evaluated?

推荐答案

它必须参照浮浮* 格式的二进制算术运算的结果。在$ p $如前pressions的Ç操作数对标准的版本被提拔到双击,结果有双击键入

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.

例如,这里是从C参考手册

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

如果两个操作数是的 INT 字符的,其结果是 INT 的。如果两者都
  的浮动双击的,其结果是双击

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

在C89 / 90已这种行为被改变,而浮动*浮动前pressions产生浮动结果

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.

这篇关于C编程:是否永远漂浮自动转换到混合乘以数据类型时增加一倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆