Skip to main content

Questions tagged [operators]

Regarding programming languages, operators are constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. From Wikipedia: http://en.wikipedia.org/wiki/Operator_%28programming%29

0 votes
1 answer
469 views

In C/C++ and Java, why does dividing an integer by an integer return an integer, while in other languages, it returns a decimal value? [closed]

I have found another similar question, but the answer there talks mainly about C/C++, and does not mention about the division operator. So, in C/C++ and Java, dividing an integer by an integer returns ...
Arunabh's user avatar
  • 143
1 vote
3 answers
393 views

What is the problem with a range operator?

Virtually all (imperative) languages offer the operators < <= >= > for lower, lower or equal, greater or equal and greater. But why no ternary range operator like (10 < x < 100) to ...
theking2's user avatar
  • 140
2 votes
3 answers
395 views

C# Duplicated usage of an if/else condition and a ternary operator. A good practice?

I had a debate with a work mate regarding the following code as to which one of it would be the better practice: My code (in pseudo): var A = <precondition either TRUE or FALSE>; var B; if(A) { ...
Chams's user avatar
  • 29
0 votes
1 answer
243 views

Excessively verbose and cryptic comparisons in Java

I don't know if this is the right place to ask more of a "philosophical" question. The more I code in Java, the more I have to bear with Comparable<T>. And the more I bear with this ...
Thomas Herondale's user avatar
0 votes
4 answers
254 views

Language design : use equals symbol = both for affectation and comparison, like in MySQL

I'm currently designing a database query language and I came to wonder what should be the best syntax for the comparison operator. Most modern languages use ==, but amongst the database languages ...
ibi0tux's user avatar
  • 241
18 votes
3 answers
2k views

Should wrappers compare as equal using the == operator when they wrap the same object?

I'm writing a wrapper for XML elements that allows a developer to easily parse attributes from the XML. The wrapper has no state other than the object being wrapped. I am considering the following ...
John Wu's user avatar
  • 26.6k
3 votes
1 answer
198 views

Should equality operators be approximate when defining numeric types that rely on floating-point numbers?

For example, say you have a class Point which has floating point components. It's tempting to overload the equality operator so you can do something like a = Point(1.1, 2.2) b = Point(3.3, 6.6) b /= ...
Josie Thompson's user avatar
3 votes
7 answers
3k views

Why don't languages use the words "and" and "or" instead of "&&" and "||"?

When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. But now we're seeing new language features added every year ...
1.21 gigawatts's user avatar
2 votes
1 answer
252 views

Good way to do 3D vector math in language without operator overloading

I would like to make a simple web application (a static website where all computation happens on the client) that generates a mesh and displays it. I have a working prototype in Unity and now I'm ...
Toast's user avatar
  • 128
1 vote
2 answers
1k views

Solving issues in using post and pre increment operators as part of expressions

I recently had a discussion with a friend about code maintainability with regards to modifying an iterator inside of the body of a loop (C# syntax): List<int> test = new List<int>(); for (...
Taco's user avatar
  • 1,165
0 votes
2 answers
819 views

Why was the caret used for exponentiation in BASIC?

As far as I have been able to find, the first language to use ^ for exponentiation was BASIC, in 1964. Earlier languages, such as Fortran, used other symbols such as ** for exponentiation (although in ...
CoffeeTableEspresso's user avatar
3 votes
1 answer
109 views

Should I replace a constant with static methods, if that constant usually 'cooperate' with a specific operator?

For example, to convert between g and kg, I have a constant 1000: public static final float G_TO_KG=1000; . . . this.result = someResult*1000; I found G_TO_KG always bind to operator '*'. So my ...
ocomfd's user avatar
  • 5,712
2 votes
4 answers
4k views

Why does C provide both the comma operator and the semicolon to separate statements?

Both the comma operator and the semicolon can be used to separate statements. Let's consider this simple code: #include <stdio.h> void do_something(int*i) {(*i)++;} int main() { int i; ...
gaazkam's user avatar
  • 4,479
58 votes
8 answers
19k views

Is there a keyword or operator for "nor"?

Is there an operator equivalent of nor? For example, my favorite color is neither green nor blue. And the code would be equivalent to: // example one if (color!="green" && color!="blue") { ...
1.21 gigawatts's user avatar
62 votes
3 answers
11k views

&& and || are not logical but conditional operators?

I am a bit confused by the MSDN C# documentation which states that & and | are logical operators and that && and || are conditional operators. I keep calling &&, || and ! logical ...
John V's user avatar
  • 4,936

15 30 50 per page
1
2 3 4 5 6