Questions tagged [operators]
Operators are symbols that occur in nearly all programming and coding languages, used for performing calculations, comparisons, and assignments of data. Use this tag for any questions relating to operators, in any language, including things such as syntax, behaviour and use.
operators
7,827
questions
0
votes
1
answer
19
views
Why does the PHP spread operator in an Elasticsearch query return different results than hardcoding parts of the query?
I've got a problem that I'm not entirely sure I understand. I've got the following Elasticsearch query, written in PHP, with fuzziness matching hardcoded; this results in about an expected 1,500 ...
0
votes
0
answers
53
views
What does a caret and an equal sign (^=) do in Python? [duplicate]
I was looking at the solution to a Python problem, and in it was
int ^= num
I don't understand what it means.
When I searched for it, I got a bunch of posts explaining what the caret sign does on its ...
0
votes
1
answer
59
views
How to Implement operator-> for a Custom UniquePtr Class in C++? [duplicate]
I am trying to write my own implementation of unique_ptr in C++, and here is my UniquePtr header file:
#include <iostream>
template <typename T>
class UniquePtr
{
T* ptr;
public:
...
1
vote
1
answer
80
views
How does the arrow operator in haskell make sense in functions that take more than one parameter?
FYI: Second day into Haskell
MRE (what the function does, does not matter):
foo :: Int -> Int -> Int
foo x y
| x == y = x + y
| x < y = x
| x > y = y
This is what ...
0
votes
1
answer
61
views
How to parse search engine keywords input
I'm implementing a tool that lets users search for terms in texts. I'm currently focused on handling more complex input from the search.
The operators I am looking to support are :
| = OR
& = AND
...
2
votes
1
answer
75
views
How do I parse Python-style chaining operators in Haskell using parsec?
In the project I'm currently working on, I construct the expression parser in parsec. The code is something like:
opTable :: [[Operator Parser Expr]]
opTable =
[
-- ...
[ InfixL $ ...
2
votes
1
answer
46
views
Understanding Array comparison while using custom data types with numpy
i have a question regarding comparison with numpy arrays while using cusom data types.
Here is my code:
import numpy as np
class Expr:
def __add__(self, other):
return Add(self, other)
...
-1
votes
1
answer
54
views
friend operator << and >> in base class without child class but still called
Why is the operators << and >> called in base class if they are defined as 'friend' when calling << and >> in child class?
Code:
#include <iostream>
#include <memory&...
0
votes
1
answer
77
views
Use defined operators from base class in inherited class
Assume I have a base class
class Vector
{
public:
Vector(const std::vector<float> &elements);
static Vector add(const Vector &v1, const Vector &v2);
Vector Vector::...
1
vote
1
answer
21
views
ComputeError with polars dataframe while trying to pass a column expressions in a simple shift() operation
Sorry, I'm starting out in Polars. Is there a way to achieve the same functionality of the shift(n) function where n is a dataframe variable.
When I try:
df = pl.DataFrame({
"a": [1, 2, ...
0
votes
0
answers
22
views
How do I define a custom method for @ operator? [duplicate]
Numpy uses the @ operator for matrix multiplication between two arrays.
I have my own class for which I want to define a method using the @ operator.
How should this be done? I define my own __add__, ...
0
votes
1
answer
42
views
How to getline from txt file and check if it is correct with what the user inputed
I am creating a bank application.
So far, I can create an account. After that, it encrypts the data like password and SSN. After that, it takes me to the login function where I have to enter my user ...
0
votes
1
answer
36
views
How to use otel collector to collect some CRD resources?
Does there are any solutions that I can use to collect resources for Operators, Helm Charts, CRD hierarchies and CD configurations via otel collector? All of them are not build-in resources for ...
0
votes
0
answers
27
views
Airfllow: Having a Custom Sensor Operator inside of python operator
I have a dag task called check_file that is responsible to check the file in remote location.
check_file = PythonOperator(
task_id='check_file',
python_callable=check_file,
...
0
votes
1
answer
37
views
Remove boilerplate code when writing operator overloads
When I made my vector3 struct I noticed the operator functions were almost identical to eachother
vector3 vector3::operator+(float scalar) const {
return vector3(x + scalar, y + scalar, z + ...
2
votes
0
answers
70
views
How to cast to derived class type without dereferencing the base class pointer?
Background
Hello, I am trying to create a way of type checking on casting between derived class types. To do so I want to inform the user when they cast to a type that might cause data loss. Having ...
0
votes
0
answers
15
views
How to build a polymorphic cluster based on a virtual one within the class hierarchy operator method + and demonstrate the mechanism of late binding?
In the base class I defined this operator (I declared it as virtual in the header file):
String String::operator+(String& other) {
int newLength = getTrueSize() + other.getTrueSize() + 1;
...
0
votes
0
answers
91
views
OpenShift Operators clash over InstallModeType
OpenShift V4.12, have four operators installed in namespace openshift-operators, however they clash over there required InstallModeType. When the default global operator-group within the namespace is ...
1
vote
2
answers
61
views
The "-" Operator in SQL where condition
I am encountering a rather peculiar syntax in MySQL, specifically the presence of a '-' symbol within the WHERE condition in the following query.
SELECT
users.id
FROM
users
WHERE
users....
0
votes
0
answers
17
views
Can anyone tell me that how html operators will work in ckeditor?
& , < and > operators are not working. When i have entered these operators cursor moves at start of line bydefault.
I have replaced these operators with others also but didn't work and also ...
-1
votes
2
answers
151
views
Is Observable's "viewof" really an operator? [closed]
I'm confused by Observable's use of the word "operator" in their documentation, and wondering whether they have misused it, or I'm simply not understanding.
Observable has a special viewof ...
-1
votes
1
answer
99
views
groovy find operator produce java.io.NotSerializableException: java.util.regex.Matcher
Im working in a pipeline with groovy and I found this problem with find operator where all solutions didn't work.
after this code:
stage('Get build artifacts') {
def buildNumber = (params....
0
votes
0
answers
34
views
How to numerically solve the diffferential equation giving the ground states of a Bose-Einstein condensate?
I am trying to solve the differential equation giving the ground states of a Bose-Einstein Condensate in 2D. I need to solve it in C/C++.
I have an equation that is as follows : (vn+1-vn)/dTau = 1/2* ...
0
votes
0
answers
45
views
Prefix type operators in Scala?
Scala allows writing infix operators for types, just as for expressions:
type ->[P,Q] = P => Q
Making X -> Y equivalent to writing ->[X,Y].
I would like to have a unary prefix operator, ...
0
votes
3
answers
79
views
How to return integer part using backslash when dividing two decimals in Visual Basic
I am trying to divide two decimals and want to get the exact integer part of the result only using a\b. Consider the following example:
Dim a, b As Integer
a = 200
b = 2
...
0
votes
0
answers
19
views
Why A = B = C not the same as A = B AND B = C AND C = A in MySQL Case When Statement? [duplicate]
Here is a table Numbers:
+--+--+--+
|A |B |C |
+--+--+--+
|1 |1 |1 |
|1 |2 |1 |
|2 |2 |2 |
|3 |2 |1 |
|3 |3 |3 |
+--+--+--+
Now executing the query:
SELECT CASE WHEN (A = B = C) THEN "Equal"...
1
vote
1
answer
20
views
Why my OR operator doesn't work on XPATH? [duplicate]
I've tried both
//th[text()="Seller Finanacing Available"]/following-sibling::td[text()="Yes" OR text()=""]
and
//th[text()="Seller Finanacing Available"]/...
-2
votes
1
answer
56
views
Why is my or operator not working in my while loop [duplicate]
Im trying to use an or operator the the parameters of my while loop and its not working.
import javax.swing.JOptionPane;
public class Checkpoint203P5 {
public static void main(String[] args){
...
0
votes
1
answer
68
views
Does C++ guarantee shortcutting for compile time constants?
I have a compile-time condition, using std::conditional<cond, TypeA, TypeB>. In my case, the condition is a disjunction, along the lines of SimpleCondition<T>::value || ComplexCondition&...
2
votes
1
answer
62
views
Why does calling a static method with only one colon not cause a parse error? [duplicate]
When calling the following code, I was surprised that a parse error was not thrown or other error given as this code does not look right.
The colon in PHP has several uses, however, I've gone off the ...
1
vote
1
answer
85
views
I'm trying to test if a variable does not equal multiple values but I don't want very long code
I'm trying to make a for loop that ignores lower case vowels. There are 5 in total and I don't want to write 5 'and' statements, because what if I have 10 values I don't want to equal? I would have to ...
-1
votes
1
answer
51
views
Why does Python return 0 for this & operation?
I'm learning Python and messing around with operations when I tried
>>> 14 & 16
0
>>> 0b1110 & 0b10000
0
In my head it would look like this:
>>> 0b1110 & ...
0
votes
0
answers
78
views
Inaccurate results using mod operator in python [duplicate]
I'm having trouble in a condition i want in a if statement. I want to check if a variable(float type), like 0.9, is multiple of 0.1.
I had this code:
(t * dt) % 0.1 == 0
I've tried the modulo ...
2
votes
1
answer
51
views
Attaching infix operators
Benefit of attaching objects (you can skip this)
In a sourced script, it can be convenient to define our helper funcs like this:
f <- function() print('hi')
e <- new.env()
assign("f", ...
0
votes
1
answer
40
views
When to use append() and when the += operator in Python?
This is my first question on Stack Overflow.
I want to add a new dictionary at the end of an existing list with multiple dictionaries (see example below):
travel_log = [
{
"country": &...
0
votes
0
answers
38
views
Python example f"{heading:=^30}"
I ran across this in a basic Python tutorial (https://docs.python.org/3.10/tutorial/controlflow.html). The example is:
>>> heading = "Centered string"
>>> f"{heading:=...
0
votes
2
answers
55
views
Python script: upper bound of range not being included
I wrote this script:
inpf = input('input file name:')
lb = input('lower bound:')
ub = input('upper bound:')
with open(inpf, 'r') as f:
contents = f.readlines()
for i in contents:
if lb ...
0
votes
1
answer
59
views
One liner for operation with two different operators
I have a bitflag enum EFlags. Given a condition I want to either remove a flag or add a flag. I have defined the operator |= to add a flag and &= to remove a flag. For example, let us say the ...
-1
votes
1
answer
85
views
Number raised to 2, 3, and 4 [duplicate]
I have written the following simple C++ program to output the powers of a number input by the user to indices 2, 3, and 4:
int a = 0;
cin >> a;
int a2 = a * a;
cout << "\n" &...
-1
votes
1
answer
82
views
PHP - Why does division operation causes loop to skip rows of data
Completely stumped by this one. I have some code that pulls rows from a database and attempts to process them as part of a PHP while() loop. Here's the basic code:
$i = 1;
while (list($thisScoreID, $...
1
vote
4
answers
156
views
Cannot use spread inside conditional operator [duplicate]
Suppose the following:
const arr = [1, 2, 3];
const insertValues = [-1, 0];
const condition = true;
arr.splice(0, 0, condition ? ...insertValues : insertValues);
This throws a syntax error:
...
0
votes
0
answers
80
views
What is the <:0:> operator in c++? [duplicate]
I recently found a strange operator in the c++ codebase of my company. There it is:
// make the output visible on the console
std::cout.rdbuf()<:0:>.pubsync();
What does the "<:...
0
votes
1
answer
70
views
Concatenate String and Is Operator
I do not understand why this code does throw a nullref.
I think it has something to do with the priority of the 'plus' operator and the 'is' operator but I am really not sure why.
return "...
-1
votes
1
answer
42
views
Combining python "in" and "==" operator has confusing behavior [duplicate]
A buddy of mine is learning python and I saw an odd thing he did with his code:
if ch in input[index] == test[index])
Obviously there's some context missing for that fragment, but interestingly, that ...
1
vote
2
answers
125
views
Freemarker equivalent of typescript optional chaining "?"
Typescript has a nice operator ? (called optional chaining) that check empty attributes in chains of dots.
Example
x?.y?.w?.z
means (more or less)
if (x !== undefined && x !== null &&
...
-2
votes
2
answers
134
views
Make easely a sub array from an array
Check this c/c++ code, but just pay atention to the use of "&" operator and the array operations into the function. Its ok to pass an array like that?, will be any invalid access problem ...
0
votes
1
answer
55
views
Using assignment operators in Dart
void main()
{
var a=10;
var b=2;
var toplam=a+=b;
var fark=a-=b;
var carpim=a*=b;
var bolme=a/=b;
print("$toplam");
print("$fark");
print("$carpim");
...
1
vote
0
answers
44
views
Operator Associativity Test vs Operand Evaluation Order
I am trying to write a simple code structure that verifies whether the && operator in a language (not a specific language, so I can't get help of truthy/falsy values) is left-associative or ...
1
vote
1
answer
56
views
Dictionary subscript or operator which adds a specified "default" value if key doesn't exist is Swift?
I need to write something like the following:
var dict = [SomeEnum: SomeObject]()
var someValue: SomeObject! = dict[.case1]
if someValue == nil {
someValue = someDefaultValue
dict[.case1] = ...
0
votes
1
answer
42
views
Reading the values out of an expression string, while keeping the formula intact
I have some code with mathematical operations, and I'm trying to make them easier to read and debug. But a very particular case is becoming complex, here's an example:
public int val1=1;
public int ...