An arithmetic expression is an expression that results in a numeric value. There are two kinds of numeric values, integers (whole numbers), and real or floating point numbers (numbers containing a decimal point).
Questions tagged [arithmetic-expressions]
677 questions
6
votes
2 answers
bash arithmetic expressions with variables
I am having troubles with the arithmetic expressions in a bash file (a unix file .sh).
I have the variable "total", which consists of a few numbers separated by spaces, and I want to calculate the sum of them (in the variable…

sheldonzy
- 5,505
- 9
- 48
- 86
6
votes
0 answers
"≥" or "≤" symbol in ggplot2 legend
I am plotting a graph with ggplot2 and I want to put arithmetic symbols in the legend labels (or anywhere else for that matter) such as "≥". I've tried the coding line expression(x>=y) which works well, but I don't want the character before or after…

Jyu
- 61
- 3
6
votes
1 answer
What is the "best" way to overload arithmetic operators in modern C++?
I want to implement a kind of "number-like" mathematical objects (say, elements in a group or a ring) in C++. I'm sure that I'm not the only one dealing with this problem, so there may be abundant amount of discussions about what is the "best" way…

Junekey Jeon
- 1,496
- 1
- 11
- 18
6
votes
1 answer
Why is the default return type of `ceiling` and `floor` numeric?
Why are the following all "numeric"?
class(ceiling(3))
class(ceiling(3L))
class(ceiling(3.1))
class(floor(2))
class(floor(2L))
class(floor(2.1))
This seems like one arithmetic operation where the result is unambiguously an integer (unlike, say,…

MichaelChirico
- 33,841
- 14
- 113
- 198
6
votes
1 answer
Monkey Patching Float Infix Operator's Produces Unexpected Results
Redefining Float#/ appears to have no effect:
class Float
def /(other)
"magic!"
end
end
puts 10.0/2.0 # => 5.0
But when another infix operator Float#* is redefined, Float#/ suddenly takes on the new definition:
class Float
def /(other)
…

ChrisTimps
- 101
- 7
6
votes
7 answers
Bash script checking cpu usage of specific process
First off, I'm new to this. I have some experience with windows scripting and apple script but not much with bash. What I'm trying to do is grab the PID and %CPU of a specific process. then compare the %CPU against a set number, and if it's higher,…

user2073780
- 63
- 1
- 1
- 3
6
votes
3 answers
What's more costly on current CPUs: arithmetic operations or conditionals?
20-30 years ago arithmetic operations like division were one of the most costly operations for CPUs. Saving one division in a piece of repeatedly called code was a significant performance gain. But today CPUs have fast arithmetic operations and…

Petr
- 62,528
- 13
- 153
- 317
5
votes
3 answers
What is the difference between precedence, associativity, and order?
This confusion arises as most people are trained to evaluate arithmetic expressions as per PEDMAS or BODMAS rule whereas arithmetic expressions in programming languages like C# do not work in the same way.
What are your takes on it?

Codeslayer
- 3,383
- 7
- 35
- 42
5
votes
1 answer
Does the C++11 standard guarantee that the unary minus of a zero-valued signed integer is zero?
Does the C++11 standard guarantee that the unary minus of a zero-valued signed integer is zero?
For example:
int zero = 0;
int n = -zero;
int m = -0;
assert(memcmp(&n, &zero, sizeof(int)) == 0);
assert(memcmp(&m, &zero, sizeof(int)) == 0);
I know…

Emile Cormier
- 28,391
- 15
- 94
- 122
5
votes
2 answers
Expression recursion level exceeded error in Bash
I'm a newbie to bash scripting and trying to do some exercises. Getting error like this when I'm trying to stop the program with "finish" string.:
line 9: ((: finish: expression recursion level exceeded (error token is "finish").
What is the…

Cemil Çakmak
- 149
- 1
- 12
5
votes
1 answer
Color Arithmetic in CSS
Can we set calculated result as a background color in CSS.
background-color: var(--backColor) + #101010;
here --backColor is a CSS variable.

Gopinath
- 55
- 1
- 5
5
votes
2 answers
What does this arithmetic expression mean: A += B++ == 0 in C++;
I came accross this expression, and can't understand the meaning of line 3 in the following snippet:
int A=0, B=0;
std::cout << A << B << "\n"; // Prints 0, 0
A += B++ == 0; // how does this exp work exactly?
std::cout << A << B << "\n"; // Prints…

Batwoman05
- 215
- 1
- 2
- 9
5
votes
3 answers
How to simplify modulus arithmetic?
I have
let f = x => x % 4 === 0 ? 0 : 4 - x % 4
But that's a piece of garbage function. Help.
x is never going to be negative.
Here's a sort of Table of Truth, or something.
x x % 4 4 - (x % 4) f(x)
0 0 4 0
1 1…

Mulan
- 129,518
- 31
- 228
- 259
5
votes
5 answers
C: Substract double from integer
I have a question that might save a lot of debugging time for many people...
Given a function:
void my_func(double value)
Is there any difference between the 2 following code lines?
double my_value = 1 - value;
and
double my_value = 1.0 -…

vav
- 63
- 6
5
votes
1 answer
How to promote two template types for arithmitic operations like builtin types do?
If I have a generic struct/class:
template
struct Container
{
T value;
Container(const Value& value) : value(value) { }
};
And I want to perform an operation on two of them:
template
Container…

Therhang
- 825
- 1
- 9
- 15