这有意义吗? [英] Does this make any sense?

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

问题描述

int a,b,c,d;

....

a = b *((double)c / d);


有人可以在声明中逐步说明发生了什么吗?


感谢您的帮助!

int a, b, c, d;
....
a = b*((double)c/d);

Can someone clarify what''s happening step by step in the statement?

Thanks for your help!

推荐答案



" tings" < TI ****** @ hotmail.com>在留言中写道

news:wm ******************* @ bgtnsc05-news.ops.worldnet.att.net ...

"tings" <ti******@hotmail.com> wrote in message
news:wm*******************@bgtnsc05-news.ops.worldnet.att.net...
int a,b,c,d;
...
a = b *((double)c / d);

有人可以澄清声明中一步一步发生了什么?

感谢您的帮助!
int a, b, c, d;
...
a = b*((double)c/d);

Can someone clarify what''s happening step by step in the statement?

Thanks for your help!




它意味着变量一个"将存储b的结果多于

的结果,c的结果

除以d是。


b,c,d将包含未知值,除非它们在某处初始化,所以

带有一段代码

你已经显示,a的结果未知



it means variable "a" will store the result of "b" mutliplied by whatever
the result of "c"
divided by "d" is.

b,c,d will contain unknown values unless they''re initialised somewhere, so
with the piece of code
you''ve shown, the result of "a" is unknown


tings< ti ****** @ hotmail.com>潦草地写道:
tings <ti******@hotmail.com> scribbled the following:
int a,b,c,d;
...
a = b *((double)c / d);
有人可以在声明中逐步说明发生了什么吗?
感谢您的帮助!
int a, b, c, d;
...
a = b*((double)c/d); Can someone clarify what''s happening step by step in the statement? Thanks for your help!




让我们一步一步走,我们吧?

它分配给a。

这个东西是两个被乘数的乘积。第一个是b。

第二个是两个股息的商数。

第一个被除数是(双)c,它是c加为双。
第二次分红是d。


换句话说,第二个被乘数是c除以d,只有c

被转换为双重防止切断当一个int潜入一个

int时会发生这种情况。


换句话说,它分配给一个新值,这个值是b

乘以c和d的商。 (双)位只有

以确保正确的数学除法而不是截止

整数除法C否则将执行。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \

\ ----------------------------- ---------------------------规则! -------- /

我希望我们认识的人会死,所以我们可以给他们留下鲜花。

- 一个6岁的孩子女孩,在墓地里看到鲜花



Let''s take it step by step, shall we?
It assigns something to a.
This something is a product of two multiplicands. The first is b.
The second is the quotient of two dividends.
The first dividend is (double)c, which is c cast to a double.
The second dividend is d.

In other words, the second multiplicand is c divided by d, only that c
is cast to a double to prevent the "cutting-off" that occurs when an
int is dived by an int.

In yet other words, it assigns to a a new value, this value being b
multiplied by the quotient of c and d. The (double) bit is only there
to ensure a proper mathematical division instead of the "cutting-off"
integer division C would otherwise perform.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery


tings写道:
int a,b,c,d;
...
a = b *((double)c / d);

有人可以在声明中逐步说明发生了什么吗?
int a, b, c, d;
...
a = b*((double)c/d);

Can someone clarify what''s happening step by step in the statement?




在这一系列陈述中发生同样的事情:


double c_dbl =(double)c;

double d_dbl =(double )d;

双商= c_dbl / d_dbl;

double b_dbl =(double)b;

double product = b_dbl * quotient;

a =(int)product;


虽然原始声明中只有一个演员,但是上面的所有

演员暗中发生。它在数学上的要点是将

truncate(bc / d)放入a。如果您的平台上的double类型比int更精确的位数(在现代英特尔®b$ b平台上都是如此),它应该成功地为所有输入值执行此操作d

!= 0.声明a = b * c / d在很多情况下会更有效地做同样的事情

,但是b和c的大值可能会溢出。

-

Derrick Coetzee

我将此新闻组发布到公共领域。我不承担所有

明示或暗示保证并承担所有责任。我不是专业人士。



The same thing that happens in this sequence of statements:

double c_dbl = (double)c;
double d_dbl = (double)d;
double quotient = c_dbl/d_dbl;
double b_dbl = (double)b;
double product = b_dbl*quotient;
a = (int)product;

Although there''s only one cast in the original statement, all of the
above casts happen implicitly. The jist of it mathematically is to put
truncate(bc/d) into a. Provided the double type on your platform has
more bits of precision than int (this is true on modern Intel
platforms), it should do this successfully for all input values where d
!= 0. The statement "a = b*c/d" would do the same thing more efficiently
in many cases, but risks overflow for large values of b and c.
--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.


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

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