长 - >双 - >长 [英] long -> double -> long

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

问题描述

long i = nnn;

long j;

double d;

d = i;

j = (长)d;


在这种情况下,i == j?


谢谢。

解决方案

2007年8月28日星期二03:09:37 -0000,Steven Woody

< na ********在comp.lang.c中@ gmail.comwrote:


long i = nnn;

long j;

双d;

d = i;

j =(长)d;



演员表是完全没必要的,完全没用。

转换是在分配时自动执行的,并且强制转换不会改变它。如果double的值超出了

范围内的无符号长度值,则行为未定义,

有或没有强制转换。
< blockquote class =post_quotes>
在这种情况下,i == j?



也许。


谢谢。



欢迎您。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http:// c -faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.club.cc.cmu .edu / ~ajo / docs / FAQ-acllc.html


文章< 11 ************* ********@z24g2000prh.googlegroups。 com>,

Steven Woody< na ******** @ gmail.comwrote:


> long i = nnn;
长j;
双d;
d = i;
j =(长)d;


>在这种情况下,i == j?



不一定。 double必须至少为64位,

包括符号和指数;你最终得到约52位

的mantisa。如果您存储的nnn
超过功率的基数(比mantisa中的#bits多1个)

(例如,2 ^(1 + 52) ),然后nnn不能完全存储,除非

最后(64-(1 +#在mantisa中))碰巧是0.


这样做在实践中出现;在SGI和Sun 64位机器上

以64位模式编译的程序有64位双精度和64位长。

((1L<< 53) )+ 1L)太大而不能存储在这样的系统中。

-

法律 - 它是商品

- Andrew Ryan(环球邮报,2005/11/26)


8月28日上午8:09,Steven Woody< narkewo ... @ gmail.comwrote:


long i = nnn;

long j;

double d ;

d = i;

j =(长)d;


在这种情况下,i == j?


谢谢。



i == j是的,这是真的。


long i = nnn;
long j;
double d;
d = i;
j = ( long )d;

in this case, i == j ?

thanks.

解决方案

On Tue, 28 Aug 2007 03:09:37 -0000, Steven Woody
<na********@gmail.comwrote in comp.lang.c:

long i = nnn;
long j;
double d;
d = i;
j = ( long )d;

The cast is completely unnecessary, and completely useless. The
conversion is performed automatically on assignment, and cast does not
change that. If the value of the double is outside the range of
values representable in an unsigned long, the behavior is undefined,
with or without the cast.

in this case, i == j ?

Maybe.

thanks.

You''re welcome.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html


In article <11*********************@z24g2000prh.googlegroups. com>,
Steven Woody <na********@gmail.comwrote:

>long i = nnn;
long j;
double d;
d = i;
j = ( long )d;

>in this case, i == j ?

Not necessarily. double pretty much has to be at least 64 bits,
including the sign and exponent; you end up with about 52 bits
of mantisa as the minimum. If the nnn that you are storing
is more than the radix to the power of (1 more than #bits in mantisa)
(e.g., 2^(1+52), then nnn cannot be stored exactly unless
the last (64-(1+#bits in mantisa)) happen to be 0.

This does come up in practice; on SGI and Sun 64 bit machines
programs compiled in 64 bit mode have 64 bit doubles and 64 bit longs.
((1L<<53)+1L) is too large to be stored in a double in such a system.
--
"law -- it''s a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)


On Aug 28, 8:09 am, Steven Woody <narkewo...@gmail.comwrote:

long i = nnn;
long j;
double d;
d = i;
j = ( long )d;

in this case, i == j ?

thanks.

i==j yes it is true.


这篇关于长 - &gt;双 - &gt;长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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