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
3
votes
1 answer
Arithmetic overflow exception in .net 2.0 and greater
I'm getting this error
System.OverflowException: Arithmetic operation resulted in an overflow.
when i ran my application on Windows Server 2008 R2 Standard compiled in .Net 2.0 or greater (.Net 4.0). From what i know, C# should ignore Arithmetic…

user1576055
- 567
- 1
- 4
- 16
3
votes
1 answer
Is there a reason to use arithmetic expression n*(1/k) over n/k?
Sometimes I encounter in arithmetic operations expression like this: n*(1/k).
Such expression can be presented in simpler manner: n/k.
I could imagine that in certain situations the former could be more descriptive if (1/k) represents well known…

Ryszard Dżegan
- 24,366
- 6
- 38
- 56
3
votes
2 answers
2 or more digit numbers with delimiters in java
I have this basic program that works pretty well when entering single digit numbers. But when calculating an expression with multiple digits, like 1337 - 456 + 32, the program doesn't move on...it acts likes I did nothing.
It doesn't freeze or…

nmd
- 93
- 2
- 8
3
votes
4 answers
How do i handle arithmetic overflows ?
i am trying to figure out how to handle overflow for addition, subtraction, multiplication and division, for two very large integer numbers. Any feedback/input would be appreciated. Does anyone know any algorithms for this and/or sources I could…

Masterminder
- 1,127
- 7
- 21
- 31
3
votes
2 answers
In T-SQL how can I get a column of 2-decimal points(or percentages)?
In SQL Server 2008, I am running a report where I need to divide two columns (called Completes and Prescreens, whole integers), and then I go to Excel and get the Prescreens divided by the Completes, and turn that into a number with 2 decimal…

Caffeinated
- 11,982
- 40
- 122
- 216
3
votes
1 answer
Understanding why php increments characters the way it does
PHP Manual states:
PHP follows Perl's convention when dealing with arithmetic operations on character variables and not C's.
For example, in PHP and Perl $a = 'Z'; $a++; turns $a into 'AA',
while in C a = 'Z'; a++; turns a into '['
(ASCII value…

user_stackoverflow
- 734
- 2
- 10
- 18
3
votes
3 answers
BASH Arithmetic Issues
I'm working in BASH and I'm having an idiot moment right now. I've got a project I'm working on that I'm going to need to use some very basic arithmetic expressions and I just realized that a lot of my problems with it are because my variables are…

RedMageKnight
- 187
- 2
- 12
2
votes
4 answers
combining two variables to set a new variable to an already declared variable using javascript
I am trying to set a new variable to the same value as an already declared variable by combining two variables that together make the name of the original variable... This may sound confusing, so here's an example:
// JavaScript…

simonthumper
- 1,834
- 2
- 22
- 44
2
votes
1 answer
Different outputs with pipe after arithmetic operator vs calling it directly
I'm getting an unexpected result when piping a matrix into as.data.frame and could use some wisdom on why it's happening. When I run the below code:
library(magrittr)
matrix(c(1,0,0,1), nrow = 2)*5 %>% as.data.frame()
I'm expecting to get
V1 V2
1…

Dubukay
- 1,764
- 1
- 8
- 13
2
votes
2 answers
Arithmetic operators
As you know there are arithmetic operators like + or -.
Is there a way to create my own operator which can execute a specific task between two variables?
For example:
a, b = 2, 5
a '+' b == 7
What I would like to do:
a 'my own operator' b ==…

Florian
- 43
- 1
- 1
- 5
2
votes
2 answers
Bash Weirdness: Exit Codes of Arithmetic Expressions in Relation to Conditionals. true/false vs. success/failure
According to the bash man page,
while list-1; do list-2; done
The while command continuously executes the list list-2 as long as the last command in the list, list-1, returns an exit status of zero.
I'm trying to make sense of how bash is…

Diagon
- 473
- 5
- 16
2
votes
2 answers
Doing arithmetic with python array columns
If I have an array: A = np.array([[1,2,0],[5,6,0]]). How can I replace the third column with the sum of the first two or some other arithmetic combination of the other columns?
In the example, calculating the third column as the sum of the sum of…

SteveM49
- 61
- 1
- 1
- 5
2
votes
2 answers
How does spacing impact the globbing operator when used with a let construct?
Note: Generally it is advised to use (( ... )) over let. let is subject to word splitting and glob expansion, which is something you rarely want in arithmetic evaluation. Sources: link link.
Regardless, I would love to better understand how globbing…

melvio
- 762
- 6
- 24
2
votes
1 answer
XOR arithmetically defined with operations for natural numbers (or integers)
I was reviewing other posts to find an Arithmetic way for XOR and found this, but cannot apply to natural numbers in python3.
The trivial way:
a = 12
b = 5
a^b ===> 9
Using the other posts formula:
a = 12
b = 5
a + b - a*b*(1 + a + b - (a*b)) …

Nand0san
- 473
- 4
- 13
2
votes
3 answers
Why does the snippet throw a Floating point exception?
This
double what;
for (int i = 1; i < (long)pow(10, 7); i++)
what = (i + i) / (i * i) - i;
raises Floating point exception (core dumped). Why?
I'm using clang++.

Quirky Science
- 21
- 1