Why is logical array fasle?
3 ビュー (過去 30 日間)
回答 (3 件)
Scott MacKenzie 2021 年 6 月 15 日
The result is false because k1 DOES NOT EQUAL g
Note that both k1 and g are scalars, not vectors. Therefore, the result of k1==g is a logical scalar which is false or 0.
Kunal Kandhari 2021 年 6 月 15 日
It is because most decimal fractions are not exactly representable in binary form, just like 1/3 is not representable exactly in a finite number of decimal digits.
if you print 55 decimal places of both the variables you will get something like this:
NEVER compare two floating point doubles for exact equality. Well, there are some notable exceptions. So unless you know the exceptions, then assume never applies.
You can see a very detailed description of the same here: