C表现 [英] C performance

查看:82
本文介绍了C表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

(对不起,如果这个问题很愚蠢或被问过很多次)

我在常见问题解答中找不到任何东西。


假设


浮动a,b,c;

c = a + b;


我的问题是:

将a和b在加入之前转换为double?

MTIA


- < br $>
Grigoris Lionis

博士生

控制系统实验室,机械工程。部门

雅典国立技术大学

9 Heroon Polytechniou Str。,Zografou

雅典15700,希腊


解决方案

不,但添加的结果将在添加之后。


" greg" < GL ********* @ mail.ntua.gr>在消息中写道

news:c8 ********** @ ulysses.noc.ntua.gr ...

大家好,
(对不起,如果这个问题很愚蠢或被问过很多次)
我在FAQ中找不到任何东西。

假设

浮动a,b, c;
c = a + b;

我的问题是:
在添加之前a和b会被转换成双倍吗?
MTIA

-
Grigoris Lionis
博士生
Control Systems Lab,Mechanical Eng。部门
雅典国立技术大学
9 Heroon Polytechniou Str。,Zografou
雅典15700,希腊



"格雷格" < GL ********* @ mail.ntua.gr>写道:

大家好,
(对不起,如果这个问题很愚蠢或被问过很多次)
我在常见问题解答中找不到。
<假设

浮动a,b,c;
c = a + b;


您使用的是a和b的值,但尚未分配

值。这是不允许的。

我的问题是:
在添加之前a和b会被转换为double吗?




No.添加发生在float中,然后结果隐含地将
转换为double。


如果你想让加法发生在double中,那么你必须转换

至少其中一个先加倍。以下任何一种都可以:

c =(double)a + b;

c = a +(double)b;

c =(double )a +(双)b;


但不是:

c =(double)(a + b);

因为与原版具有相同的效果:添加在

float中完成,然后显式转换为double。


-

Simon。


" Ralmin" <是ne ** @ ralminNOSPAM.cc>在消息中写道

news:da ****************************** @ news.teranew s。 com ...

" greg" < GL ********* @ mail.ntua.gr>写道:



[snip]

float a,b,c;
c = a + b;
[snip]会在添加之前将a和b转换为double吗?



否。添加发生在float中,然后结果被隐式转换加倍。




再回到漂浮状态?


Alex


Hi All,
(sorry if this question is silly or asked a lot of times)
I could not find something in the FAQ though.

Suppose

float a,b,c;
c=a+b;

my question is :
will a and b be converted to double before adding?
MTIA

--
Grigoris Lionis
PhD Student
Control Systems Lab, Mechanical Eng. Dept.
National Technical University of Athens
9 Heroon Polytechniou Str., Zografou
Athens 15700, Greece


解决方案

No, but the result of the addition will be after adding.

"greg" <gl*********@mail.ntua.gr> wrote in message
news:c8**********@ulysses.noc.ntua.gr...

Hi All,
(sorry if this question is silly or asked a lot of times)
I could not find something in the FAQ though.

Suppose

float a,b,c;
c=a+b;

my question is :
will a and b be converted to double before adding?
MTIA

--
Grigoris Lionis
PhD Student
Control Systems Lab, Mechanical Eng. Dept.
National Technical University of Athens
9 Heroon Polytechniou Str., Zografou
Athens 15700, Greece



"greg" <gl*********@mail.ntua.gr> wrote:

Hi All,
(sorry if this question is silly or asked a lot of times)
I could not find something in the FAQ though.

Suppose

float a,b,c;
c=a+b;
You are using the value of a and b, but they have not yet been assigned a
value. This is not allowed.
my question is :
will a and b be converted to double before adding?



No. The addition takes place in float, and then the result is implicitly
converted to double.

If you wanted to make the addition happen in double, then you must convert
at least one of them to double first. Any of the following would do:
c = (double)a + b;
c = a + (double)b;
c = (double)a + (double)b;

But not:
c = (double)(a + b);
because that has the same effect as the original: the addition is done in
float and then explicitly converted to double.

--
Simon.


"Ralmin" <ne**@ralminNOSPAM.cc> wrote in message
news:da******************************@news.teranew s.com...

"greg" <gl*********@mail.ntua.gr> wrote:


[snip]

float a,b,c;
c=a+b; [snip] will a and b be converted to double before adding?



No. The addition takes place in float, and then the result is implicitly
converted to double.



And then back to float?

Alex


这篇关于C表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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