平等... [英] Equality...

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

问题描述

来自常见问题:


"非整数结果通常不应进行相等比较。


现在,我理解为什么这最终成为现实,但那么解决方法是什么?b $ b一个人真的希望看看是否1.015 * 5 == 5.075?我不是说

我有任何想做的事情(如果我这样做,我会使用C,哈哈......),但实际上,它是

对我来说似乎是一个廉价的黑客...除非我错过了什么...


-

Christopher Benson-Manica | Jumonji giri,荣誉。

ataru(at)cyberspace.org |

解决方案

< at *** @ nospam.cyberspace.org>在消息中写道

news:bi ********** @ chessie.cirr.com ...

来自FAQ:

非整数结果通常不应该相等。

现在,我理解为什么这最终成为现实,但那么什么是解决方法呢?实际上想看看是否1.015 * 5 == 5.075?我不是说我有这样的愿望
(如果我这样做,我会使用C,哈哈......),但实际上,这对我来说似乎是一个便宜的黑客攻击。 ..除非我错过了什么......




看起来像是一个廉价的黑客?如果你想知道IEEE

双精度浮点表示是否为1.015乘以
,IEEE双精度浮点表示为5等于

IEEE双精度浮点表示5.075然后

JavaScript会告诉你,如指定的那样。结果将是

正确它可能不是一个有用的问题。


Richard。


Richard Cornford< Ri ***** @ litotes.demon.co.uk>打破了永恒的沉默并且这样说:

它可能不是一个有用的问题。




密集警报! - >它以什么方式没用?我特别想,

与问C中的问题有什么不同?


-

克里斯托弗Benson-Manica | Jumonji giri,荣誉。

ataru(at)cyberspace.org |


在*** @ nospam.cyberspace.org 写道:

密集警报! - >它以什么方式没用?


如果回答问题5.0 * 1.015 == 5.075是假,

你有多聪明?


正如Richard Cornford所说,你知道使用IEEE的结果

双精度浮点乘法在IEEE双精度浮点数表示5.0和1.015,并不是与IEEE yadda yadda表示5.075相同的b / b



然后又是什么?

我想具体来说,它与在C中提出相同的问题有何不同?



不是。在使用不精确的

表示数字(即所有语言)的任何语言中,问题都是一样的。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

Art D' 'HTML:< URL:http://www.infimum.dk/HTML/randomArtSplit.html>

''没有判断的信仰只会降低精神神圣。''

From the FAQ:

"Non-integer results should not normally be compared for equality."

Now, I understand why this ends up being true, but then what is the workaround
should one actually desire to see whether 1.015 * 5 == 5.075? I''m not saying
I have any desire to do this (I''d use C if I did, lol...), but really, it
seems like a cheap hack to me... unless I''m missing something...

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |

解决方案

<at***@nospam.cyberspace.org> wrote in message
news:bi**********@chessie.cirr.com...

From the FAQ:

"Non-integer results should not normally be compared for equality."

Now, I understand why this ends up being true, but then what is
the workaround should one actually desire to see whether
1.015 * 5 == 5.075? I''m not saying I have any desire to do this
(I''d use C if I did, lol...), but really, it seems like a cheap
hack to me... unless I''m missing something...



What seems like a cheap hack? If you want to know whether the IEEE
double precision floating point representation of 1.015 multiplied by
the IEEE double precision floating point representation of 5 equals the
IEEE double precision floating point representation of 5.075 then
JavaScript will tell you that, as specified. The result will be
"correct" it just may not be a useful question to ask.

Richard.


Richard Cornford <Ri*****@litotes.demon.co.uk> broke the eternal silence and spoke thus:

it just may not be a useful question to ask.



denseness alert! -> In what way is it not useful? I guess specifically, how
is it different from asking the same question in, say, C?

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |


at***@nospam.cyberspace.org writes:

denseness alert! -> In what way is it not useful?
If the answer to the question "5.0 * 1.015 == 5.075" is "false",
how much wiser are you?

As Richard Cornford said, you know that the result of using IEEE
double precission floating point multiplication on the IEEE double
precission floating point representations of 5.0 and 1.015, is not the
same as the IEEE yadda yadda representation of 5.075.

And then what?
I guess specifically, how is it different from asking the same
question in, say, C?



It''s not. The problem is the same in any language using inexact
representation of numbers (i.e., all languages).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''Faith without judgement merely degrades the spirit divine.''


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

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