插入语 [英] parenthesis

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

问题描述

如果我有双变量,d,u,v,w,x。标准确保



为d赋值,

d =(u + v) - (w + x);

u + v将首先添加,然后是w + x然后它们将被加在一起

并且编译器不会在
$中评估上面的表达式b $ b任何其他订单。


只是想知道,因为添加双打不是关联的。

解决方案

gc写道:

如果我有双变量,d,u,v,w,x。标准确保
在为d分配值时,
d =(u + v) - (w + x);
u + v将首先添加然后w + x




不,C标准和C ++标准都不能保证。 (w + x)可能会在(u + v)之前评估



-

Russell Hanneken rg********@pobox.com

删除''g''从我的地址给我发邮件。


gc写道:

如果我有双变量,d,u,v ,W,X。标准确保
同时为d赋值,
d =(u + v) - (w + x);
u + v将首先添加那么w + x然后它们将被加在一起
并且编译器不会以任何其他顺序评估上面的表达式。

只是想知道,因为添加双打不是关联。




减法将在最后执行,但AFAIK的添加

可以按任意顺序完成。如果你想强制一个特定的

评估订单,你可以使用一个额外的变量。


在文章< bm * *********@news-rocq.inria.fr> ;, Grumble写道:

gc写道:

如果我有双变量,d,u ,v,W,X。标准确保
同时为d赋值,
d =(u + v) - (w + x);
u + v将首先添加那么w + x然后它们将被加在一起
并且编译器不会以任何其他顺序评估上面的表达式。

只是想知道,因为添加双打不是关联。



减法将在最后执行,但AFAIK的添加
可以按任意顺序完成。如果你想强制一个特定的
评估订单,你可以使用一个额外的变量。




double t1,t2;


t1 = u + v;

t2 = w + x;


d = t1 - t2;

AFAIK ,没有什么可以阻止编译器生成在t1之前计算t2的

代码。


我不确定浮点的细节arithmetics是

这里的一个问题。


-

Andreas K?h?ri


If I have double variables, d,u,v,w,x. Soes the standard ensure that
while
assigning a value to d as,
d=(u+v)-(w+x);
u+v will be added first then w+x and then they will be added together
and that the compiler will not evaluate the above expression in
anyother order.

Just wondering, since addition of doubles is not associative.

解决方案

gc wrote:

If I have double variables, d,u,v,w,x. Soes the standard ensure that
while assigning a value to d as,
d=(u+v)-(w+x);
u+v will be added first then w+x



No, neither the C standard nor the C++ standard guarantee that. (w+x) might
be evaluated before (u+v).

--
Russell Hanneken
rg********@pobox.com
Remove the ''g'' from my address to send me mail.


gc wrote:

If I have double variables, d,u,v,w,x. Soes the standard ensure that
while
assigning a value to d as,
d=(u+v)-(w+x);
u+v will be added first then w+x and then they will be added together
and that the compiler will not evaluate the above expression in
anyother order.

Just wondering, since addition of doubles is not associative.



The subtraction will be carried out last, but AFAIK the additions
could be done in either order. If you want to force a specific
evaluation order, you could use an extra variable.


In article <bm**********@news-rocq.inria.fr>, Grumble wrote:

gc wrote:

If I have double variables, d,u,v,w,x. Soes the standard ensure that
while
assigning a value to d as,
d=(u+v)-(w+x);
u+v will be added first then w+x and then they will be added together
and that the compiler will not evaluate the above expression in
anyother order.

Just wondering, since addition of doubles is not associative.



The subtraction will be carried out last, but AFAIK the additions
could be done in either order. If you want to force a specific
evaluation order, you could use an extra variable.



double t1, t2;

t1 = u + v;
t2 = w + x;

d = t1 - t2;
AFAIK, there''s nothing stopping the compiler from generating
code that calculates t2 before t1.

I''m not sure the finer details of floating point arithmetics is
an issue here at all.

--
Andreas K?h?ri


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

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