Questions tagged [comparison-operators]
Comparison operators, as their name implies, allow to compare two values and usually return Boolean value (true or false).
comparison-operators
773
questions
-5
votes
1
answer
64
views
Comparison Operators result in Python
Why in Python print(bool(7>8)==False==True) results False, logically it should be True?
as bool(7>8) is False, therefore
False==False==True -> True==True -> True (NOT False)
as the ...
3
votes
2
answers
82
views
Impact of comparison function on upper_bound and lower_bound
I would like to understand the impact of the comparison function (< or <=) on both lower_bound and upper_bound functions.
Consider this program:
#include <iostream>
#include <vector>
...
0
votes
1
answer
102
views
Overloaded functions have similar conversions [duplicate]
My program will not compile, and give the error overloaded functions have similar conversions. What does this mean and how do I fix it?
struct DynamicInt {
bool operator==(const DynamicInt&);
}...
18
votes
1
answer
1k
views
C++20 std::vector comparison weird behaviour
Overloading the operator bool() for a custom class T breaks std::vector<T> comparison operators.
The following code tried on the first online compiler google suggest me prints
v1 > v2: 0
v1 &...
0
votes
0
answers
22
views
x86 - compare numbers and push the result onto the stack
I would like to know, how to compare two numbers and push the result (true, false or 1, 0) onto the stack. I know about the cmp instruction, but it only sets the flags. I need something that will ...
1
vote
0
answers
40
views
Comparing numeric values not as expected (VBScript) [duplicate]
I stumbled upon a strange behavior of VBScript when comparing numerical values. I expect it's a rounding issue but I can't figure out how I can improve the code to behave as expected.
Dim angle
angle ...
0
votes
3
answers
45
views
Python comparison operator not giving proper answer in if-else statements
# Program1: Take two numbers as input from User and print which one is greater or are they equal.
num1 = input("Enter the first number: ")
num2 = input("Enter the second number: ")...
3
votes
2
answers
123
views
Do tuples conform to Comparable?
Tuples in Swift seem to conform to Comparable inasmuch as I get these results:
print ( (3,0) < (2,10000) ) // false
print ( (0,0,5) < (0,0,7) ) // true
It seems to do a left-right member-by-...
0
votes
2
answers
76
views
Is grouping values with ( value1 || value2) for comparisons valid in JavaScript or TypeScript and if so, why not?
I am wondering if grouping values with || while comparing a single variable value is considered valid in the latest JavaScript or TypeScript and if not, does anyone know a reason for this to not ...
1
vote
0
answers
26
views
Chained comparisons not always executing functional calls (side-effects) [duplicate]
I was testing out comparison chaining and I noticed that in certain patterns the some of the function calls are not executed.
If I plan on using the function calls to do things what would be the best ...
-3
votes
2
answers
97
views
Why is the expected output not displayed [duplicate]
why there is no output for this?
#include <stdio.h>
int main() {
int i;
int array[4] = {10, 25, 36, 42};
// int size=sizeof(array) / sizeof(int);
for (i = -1; i < sizeof(...
-1
votes
2
answers
161
views
Why is "-1 < strlen(s)" equal to 0?
char* s =(char*) "sss";
int j = -1;
printf("%d", j < strlen(s));
It's mainly about the difference between j < 3 and j < strlen(s).
In the above code, the printf() ...
1
vote
0
answers
31
views
If statement checking for class inputs [duplicate]
I'm currently still learning, but am working on a small and simple script.
I'm attempting to check the user inputs to ensure they match the desired values of the defined variables. The script works ...
-2
votes
1
answer
63
views
How compare if a variable (x) is greater than another variable (y) by a certain value. For example, if x > y by 2, print("Hooray!")
So I'm trying to make a rock, paper, scissors game and I'm trying to make it so that if the user (or computer) either gets 3 points OR the user's (or computer's) score is greater by 2 (like a best 2 ...
2
votes
1
answer
74
views
Different result from std::vector erase when comparing in if than comparing to stored value
For some reason, I get different result when comparing the return value from vector::erase inside a if statement or if I store the value first and then compare. But it seems to only happen with g++.
...