Questions tagged [compare]

The analysis required to assess the differences and similarities between two or more entities.

This tag is used to classify a question as one dealing with the comparison of at least two entities. The essence of questions that are tagged should boil down to one of the following questions:

  1. How do I control when the compiler/interpreter thinks that two entities are equal? How do I control when the compiler/interpreter thinks that two entities are unequal?
  2. How do I control when the compiler/interpreter thinks that one entity is bigger than the other?
  3. How do I control when the compiler/interpreter thinks that one entity is smaller than the other?

Note that in some languages, it is possible to define asymmetric inequalities. That is, cases in which a<b does not mean that b<a. This is why in python, there exist separate functions for __gt__ (greater than) and __lt__ (less than), etc

9183 questions
91
votes
6 answers

The right way to compare a System.Double to '0' (a number, int?)

Sorry, this might be a easy stupid question, but I need to know to be sure. I have this if expression, void Foo() { System.Double something = GetSomething(); if (something == 0) //Comparison of floating point numbers with equality …
radbyx
  • 8,605
  • 18
  • 75
  • 119
90
votes
5 answers

std::string comparison (check whether string begins with another string)

I need to check whether an std:string begins with "xyz". How do I do it without searching through the whole string or creating temporary strings with substr().
jackhab
  • 15,012
  • 32
  • 92
  • 129
90
votes
10 answers

Java error: Comparison method violates its general contract

I saw many questions about this, and tried to solve the problem, but after one hour of googling and a lots of trial & error, I still can't fix it. I hope some of you catch the problem. This is what I get: java.lang.IllegalArgumentException:…
Lakatos Gyula
  • 3,529
  • 4
  • 28
  • 52
89
votes
7 answers

Query comparing dates in SQL

I have a table with dates that all happened in the month November. I wrote this query select id,numbers_from,created_date,amount_numbers,SMS_text from Test_Table where created_date <= '2013-04-12' This query should return everything that…
HelpASisterOut
  • 2,763
  • 10
  • 38
  • 74
84
votes
10 answers

Tool to compare large numbers of PDF files?

I need to compare large count of PDF files for it optical content. Because the PDF files was created on different platforms and with different versions of the software there are structural differences. For example: the chunking of text can be…
Horcrux7
  • 21,867
  • 21
  • 85
  • 134
80
votes
1 answer

Relationship and difference between HAL and HATEOAS

HATEOAS (Hypermedia as the Engine of Application State) and HAL (Hypertext Application Language) seem to be related but are not exactly the same. What is the relationship and difference between HATEOAS and HAL?
Lee Chee Kiam
  • 9,693
  • 10
  • 56
  • 76
75
votes
3 answers

How to compare LocalDate instances Java 8

I am writing an app that needs to be quite accurate in dates and I wonder how can I compare LocalDate instances.. for now I was using something like: LocalDate localdate1 = LocalDate().now(); LocalDate localdate2 =…
azalut
  • 3,466
  • 7
  • 26
  • 40
73
votes
4 answers

How do I compare two dictionaries in Swift?

Is there an easy way to compare two [String: AnyObject] dictionaries in swift, since it doesn't accept the == operator? By comparing two dictionaries, I mean checking that they have the same exact keys and for every key they have the same values.
bubakazouba
  • 1,500
  • 2
  • 19
  • 32
72
votes
9 answers

How to compare Enums in TypeScript

In TypeScript, I want to compare two variables containing enum values. Here's my minimal code example: enum E { A, B } let e1: E = E.A let e2: E = E.B if (e1 === e2) { console.log("equal") } When compiling with tsc (v 2.0.3) I get the…
John J. Camilleri
  • 3,372
  • 4
  • 28
  • 38
70
votes
5 answers

bash string compare to multiple correct values

i have the following piece of bashscript: function get_cms { echo "input cms name" read cms cms=${cms,,} if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then get_cms fi } But no matter what i…
eagle00789
  • 821
  • 1
  • 6
  • 6
69
votes
7 answers

Compare/Difference of two arrays in Bash

Is it possible to take the difference of two arrays in Bash. What is a good way to do it? Code: Array1=( "key1" "key2" "key3" "key4" "key5" "key6" "key7" "key8" "key9" "key10" ) Array2=( "key1" "key2" "key3" "key4" "key5" "key6" ) Array3…
Kiran
  • 6,858
  • 30
  • 95
  • 156
68
votes
8 answers

strcmp equivelant for integers (intcmp) in PHP

So we got this function in PHP strcmp(string $1,string $2) // returns -1,0, or 1; We Do not however, have an intcmp(); So i created one: function intcmp($a,$b) { if((int)$a == (int)$b)return 0; if((int)$a > (int)$b)return 1; …
Chase Wilson
  • 1,427
  • 1
  • 12
  • 18
68
votes
2 answers

How to check if two data frames are equal

Say I have large datasets in R and I just want to know whether two of them they are the same. I use this often when I'm experimenting different algorithms to achieve the same result. For example, say we have the following datasets: df1 <-…
Waldir Leoncio
  • 9,134
  • 14
  • 68
  • 94
66
votes
4 answers

Getting "command not found" error while comparing two strings in Bash

My whole Script is currently this: #!/bin/sh clear; blanko=""; # Dummy-Variablen variable=Testvariable; if [[$variable == $blanko]]; then echo "Nichts da!" else echo $variable fi and if i enter TestSelect.sh i…
EpsilonAlpha
  • 763
  • 1
  • 5
  • 4
65
votes
9 answers

Check if enum exists in Java

Is there anyway to check if an enum exists by comparing it to a given string? I can't seem to find any such function. I could just try to use the valueOf method and catch an exception but I'v been taught that catching runtime exceptions is not good…
Danny
  • 4,454
  • 6
  • 36
  • 55