difficulties/eq #914
Replies: 5 comments 7 replies
-
建议直接贴上“偏序”,“全序”和“NaN”的 wiki 链接。 |
Beta Was this translation helpful? Give feedback.
-
Eq 和 PartialEq, Ord 和 PartialOrd 区别其实用离散数学一个性质就可以区分开。 ** 类型T:Eq/PartialEq 的实例(instance) 是否具有自反性. ** 用你的浮点数例子就可以说明:T = f32, f32::NAN == f32::NAN不成立。 不成立的原因是因为IEEE754只规定了NAN的阶码部分全为1即可,没有规定符号位和尾数部分。 1 11111111 0000....001 != 0 111111111 00000...111 |
Beta Was this translation helpful? Give feedback.
-
至于NaN,看到一个好的解释是NaN代表“不确定、难以言说的数字”;因此对于相等这一操作,我们不能说两个不确定的数是相等的。这破坏了自反性,也就称不上离散数学中的“等价关系”,故只能是PartialEq; |
Beta Was this translation helpful? Give feedback.
-
对于石头,剪刀,布游戏有: |
Beta Was this translation helpful? Give feedback.
-
首先我们需要找到一个类型,它实现了 PartialEq 但是没有实现 Eq(你可能会想有没有反过来的情况?当然没有啦,部分相等肯定是全部相等的子集!) 浮点数实现了PartialEq 没有实现 Eq。说明有类型是PartialEq 而不是Eq, 则PartialEq 范围大,Eq 范围小, 此处“部分相等肯定是全部相等的子集” 是反过来的。 |
Beta Was this translation helpful? Give feedback.
-
difficulties/eq
https://course.rs/difficulties/eq.html
Beta Was this translation helpful? Give feedback.
All reactions