Questions tagged [equality]

Equality is a relationship between two or more items or variables or objects that exists if (1) the items are the same item, variable, or object or (2) the items are different items, variables or objects but they have the same value. This tag should generally be used with programming language specific tags as well as other contextual tags such as database system. The post should include as much context about the equality test as is possible.

This tag is typically used for questions concerning how to determine if two objects or variables are either the same object or different objects with the same value. Questions almost always require a programming language tag and other tags for context.

Programming languages represent variables, objects, or other storage containers using different underlying mechanisms for the storage of the values of variables and objects. A test for equality is to compare some characteristic of two variables or objects to determine if the characteristic is the same.

This characteristic is typically either (1) the storage identifier such as a reference handle, memory address, etc. when checking if the two are the same object or (2) the characteristic is the value of the objects retrieved using a storage identifier when checking if the value of the two are the same value.

Different programming languages and different operating environments have differences in how equality is tested and what operators are used to express a test for equality. In some cases various conversions from underlying storage representations may be involved in testing for equality.

See What is the difference between equality and equivalence? as well as Equivalence relation and natural ordering on a class in Java

2095 questions
1
vote
2 answers

JavaScript implicit conversions in equality with a string

How does JavaScript behave for the comparisons true == "true" and (0 == "0")?
faya
  • 5,535
  • 11
  • 37
  • 49
1
vote
1 answer

Is it safe comparing tSQL's dates for equality?

Say, if 'dtIn' is of type DATETIME2, is it safe to do the following comparison using SQL Server 2008? --my concern is about equality part, -- or will it pick ALL 2012-09-09 22:30:00 dates? SELECT * FROM tbl WHERE [dtIn] <= '2012-09-09…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
1
vote
3 answers

PHP equality - where am I going wrong?

This is driving me nuts. Two integers should be equal. Result in both PHP 5.2 and…
James Newell
  • 652
  • 8
  • 12
1
vote
4 answers

Is Java hashCode() method a reliable measure of object equality?

I am currently working on comparing two complex objects of the same type, with multiple fields consisting of data structures of custom object types. Assuming that none of the custom objects has overriden the hashCode() method, if I compare the…
LucasSeveryn
  • 5,984
  • 8
  • 38
  • 65
1
vote
2 answers

Why must two equal objects have same hash value?

NSObject Protocol Reference says "If two objects are equal, they must have the same hash value." Why must? What could be the problem with two equal objects not having same hash value?
Aleksa
  • 529
  • 4
  • 16
1
vote
3 answers

I wanna have an Extension method "Equals" between 2 byte arrays

I am doing some byte[] comparisons. I tried == but this is just like the base Equals, which: byte[] a = {1,2,3}; byte[] b = {1,2,3}; bool equals = a == b; //false equals = a.Equals(b); //false I tried to add an extension method, but since the…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
1
vote
2 answers

What is going on with Asserts Equality here?

Found this website to presumably test wannabe developers... http://www.devchallenge.co.uk/challenge-2 The question is this... Based on the given code, which of the following tests will return a ‘true’ answer and pass, and which will return a…
El Ronnoco
  • 11,753
  • 5
  • 38
  • 65
0
votes
3 answers

Best way to compare sha1 hashes for equality

I want to compare two sha1 hashes for equality. What could be the most efficient way to do this? Currently, I am trying using memcmp. Thanks.
polapts
  • 5,493
  • 10
  • 37
  • 49
0
votes
3 answers

differences between int32.Equals int? == int? for linq

I know the title is not very clear but here is the problem. I am trying to develop simple web page with asp.net mvc and I have category controller and try to explain situation at the below code block. // // GET: /Category/ public…
Onur Topal
  • 3,042
  • 1
  • 24
  • 41
0
votes
3 answers

equality of Addresses fails even if all fields are identical

I created an Address class like below,Then I wanted to check equality of two Addresses.If all the fields are identical,the two Addresses are considered identical. So,I implemented the hashCode and equals methods. public class Address{ public…
Damon Julian
  • 3,829
  • 4
  • 29
  • 34
0
votes
2 answers

Variable value shown in console is inconsistent with equality test

given the following: where data is a string received as an AJAX value and data has a value of 'good': console.log data # good console.log typeof data # string console.log typeof 'data' # string if data is 'good' console.log 'test' #…
Victor S
  • 5,098
  • 5
  • 44
  • 62
0
votes
5 answers

If and equality statements

I'm trying to solve the problem here but I don't know why my code isn't working. Any help is appreciated. EDIT: Edited to make correction mentioned below, but there is still an extra "15" (in bold) on the second line of the output and I don't…
Stu
  • 2,679
  • 4
  • 26
  • 25
0
votes
3 answers

finding 3 or more equal objects within an array?

I stumbled upon a problem, maybe someone can give me pointers on how to solve it? So, lets assume i have an array of objects (we can assume they're lists within a list), so something like that: { {1,2}, {2}, {1,2}, {3,4,5}, {1,2} } The elements…
user1039063
  • 213
  • 3
  • 11
0
votes
1 answer

String comparision returning False even if they are the same in python , inside a html file in DJANGO

so there is this IF statement inside a html file , which is failing to return a TRUE when both the strings are the same , i dont know why , i copy pasted the same strings from database to another python compiler and it said TRUE but it is only…
0
votes
1 answer

testing equality of Eq (not Expr) in SymPy

YourHomicidalApe asked a question which is essentially this: Given two strings that represent equations that are converted to SymPy Eq instances, how would you tell if they represent the same equations? (The "same" meaning that algebraic…
smichr
  • 16,948
  • 2
  • 27
  • 34