equality

Float comparison (equality) in CoreGraphics

一笑奈何 提交于 2019-12-19 03:01:05
问题 Apple CoreGraphics.framework , CGGeometry.h : CG_INLINE bool __CGSizeEqualToSize(CGSize size1, CGSize size2) { return size1.width == size2.width && size1.height == size2.height; } #define CGSizeEqualToSize __CGSizeEqualToSize Why do they (Apple) compare floats with == ? I can't believe this is a mistake. So can you explain me? (I've expected something like fabs(size1.width - size2.width) < 0.001 ). 回答1: Floating point comparisons are native width on all OSX and iOS architectures. For float ,

Why hashCode() returns the same value for a object in all consecutive executions?

半腔热情 提交于 2019-12-18 19:06:54
问题 I am trying some code around object equality in java. As I have read somewhere hashCode() is a number which is generated by applying the hash function. Hash Function can be different for each object but can also be same. At the object level, it returns the memory address of the object. Now, I have sample program, which I run 10 times, consecutively. Every time i run the program I get the same value as hash code. If hashCode() function returns the memory location for the object, how come the

When would JavaScript == make more sense than ===?

假如想象 提交于 2019-12-18 14:18:38
问题 As Which equals operator (== vs ===) should be used in JavaScript comparisons? indicates they are basically identical except ' === ' also ensures type equality and hence ' == ' might perform type conversion. In Douglas Crockford's JavaScript: The Good Parts , it is advised to always avoid ' == '. However, I'm wondering what the original thought of designing two set of equality operators was. Have you seen any situation that using ' == ' actually is more suitable than using ' === '? 回答1:

Does a Python object which doesn't override comparison operators equals itself?

偶尔善良 提交于 2019-12-18 13:15:24
问题 class A(object): def __init__(self, value): self.value = value x = A(1) y = A(2) q = [x, y] q.remove(y) I want to remove from the list a specific object which was added before to it and to which I still have a reference. I do not want an equality test. I want an identity test. This code seems to work in both CPython and IronPython, but does the language guarantee this behavior or is it just a fluke? The list.remove method documentation is this: same as del s[s.index(x)] , which implies that

== vs Equals in C#

风流意气都作罢 提交于 2019-12-18 13:05:00
问题 What is the difference between the evaluation of == and Equals in C#? For Ex, if(x==x++)//Always returns true but if(x.Equals(x++))//Always returns false Edited: int x=0; int y=0; if(x.Equals(y++))// Returns True 回答1: According to the specification, this is expected behavior. The behavior of the first is governed by section 7.3 of the spec: Operands in an expression are evaluated from left to right. For example, in F(i) + G(i++) * H(i) , method F is called using the old value of i, then

Is string interning done at compile time in Java? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-18 12:16:37
问题 This question already has answers here : When are Java Strings interned? (2 answers) Closed 4 years ago . I am really confused with how string interning works in Java. When I write: String a = "ABC"; String b = "ABC"; if (a==b) System.out.println("Equal"); Does the compiler store the string literal "ABC" into the string constant pool at compile time? That sounds illogical, because I thought the string constant pool was created by the JVM at runtime, and I don't see how that is possible if it

is StringComparison.Ordinal the same as InvariantCulture for testing equality?

主宰稳场 提交于 2019-12-18 12:14:15
问题 From their brief summary descriptions, it sounds like the string comparison rules StringComparison.Ordinal and StringComparison.InvariantCulture are meant to differ in how they do sorting of strings. Is that all ? i.e., does that mean we can use either string comparison rule when doing an equality comparison? string.Equals(a, b, StringComparison....) And for extra credit: does it make a difference to the answer if we compare OrdinalIgnoreCase and InvariantCultureIgnoreCase ? How? Please

Why is == faster than eql?

扶醉桌前 提交于 2019-12-18 11:26:34
问题 I read in the documentation for the String class that eql? is a strict equality operator, without type conversion, and == is a equality operator which tries to convert second its argument to a String, and, the C source code for this methods confirms that: The eql? source code: static VALUE rb_str_eql(VALUE str1, VALUE str2) { if (str1 == str2) return Qtrue; if (TYPE(str2) != T_STRING) return Qfalse; return str_eql(str1, str2); } The == source code: VALUE rb_str_equal(VALUE str1, VALUE str2) {

Equality Test for Derived Classes in C++ [duplicate]

泄露秘密 提交于 2019-12-18 10:45:01
问题 This question already has answers here : Closed 10 years ago . Possible Duplicate: What’s the right way to overload operator== for a class hierarchy? In C++, how can derived classes override the base class equality test in a meaningful way? For example, say I have a base class A. Classes B and C derive from A. Now given two pointers to two A objects, can I test if they are equal (including any subclass data)? class A { public: int data; }; class B : public A { public: float more_data; bool

Compare if two dataframe objects in R are equal?

筅森魡賤 提交于 2019-12-18 10:26:42
问题 How do I check if two objects, e.g. dataframes, are value equal in R? By value equal, I mean the value of each row of each column of one dataframe is equal to the value of the corresponding row and column in the second dataframe. 回答1: It is not clear what it means to test if two data frames are "value equal" but to test if the values are the same, here is an example of two non-identical dataframes with equal values: a <- data.frame(x = 1:10) b <- data.frame(y = 1:10) To test if all values are