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
0 answers
Test Suite for Arithmetic Expression Parser
I am writing a simple parser (in JavaScript, and, later, in Swift) to evaluate basic arithmetic expressions such as 1+2*3 and 3*(4+5).
I have a working version, but I would like to test whether it is reliable.
Is there a test suite of arithmetic…

Manngo
- 14,066
- 10
- 88
- 110
3
votes
1 answer
GCC won't optimize integer arithmetic expression
int f(int x, int y) {
return 20 * (x - 10) + 50 * (x + 5);
}
int f_expected(int x, int y) {
return 70 * x + 50;
}
The generated code is:
f(int, int):
lea eax, [rdi-50+rdi*4]
add edi, 5
imul edi, edi, 50
…

Gabriel Garcia
- 1,000
- 10
- 11
3
votes
1 answer
Perform arithmetic in loop with variables in Batch
I would like to print the following:
0
1
2
3
4
I have tried this:
ECHO OFF
FOR /L %%A in (1,1,5) DO (
SET /a "B=%%A-1"
ECHO %B%
)
However, this gives me:
4
4
4
4
4
How can I achieve the desired output while using both A and B in my code?

IslandPatrol
- 261
- 3
- 11
3
votes
1 answer
How do you get the remainder of a decimal in Racket?
I'm looking at Racket as a friendly introduction to lisp, but I'm missing something. I need to simplify angles, so all I need to do get n mod 360. The problem is n may be a decimal. I looked through the documentation, but "remainder" and "modulo"…

Caitlin Rainone
- 116
- 8
3
votes
1 answer
Adding numbers in bash script says "not found"
I'm making a bash script in Vim editor for my operating systems fundamentals class, and I am having an extremely simple yet frustrating error occur where I cannot add variables together and set the sum to another variable. I've tried numerous…

Greg M
- 33
- 4
3
votes
4 answers
Input validation only working once
I am trying to create a script that will take 2 inputs and calculate the sum. I would like both inputs to be validated before the calculation takes place - inputs must range between 0 and 10.
However when I input values over 10 in both fields…

tomoyo385538
- 35
- 4
3
votes
3 answers
In bash how do I divide two variables and output the answer rounded upto 5 decimal digits?
I took two variables as input and after dividing them, I want to get the output rounded up to 5 decimal digits. I have tried this way ->
sum=12
n=7
output=$("scale=5;sum/n"|bc)
echo $output
My code isn't showing any output. What can I…

jbsu32
- 1,036
- 1
- 11
- 31
3
votes
1 answer
How to properly parse numbers in an arithmetic expression, differentiating positive and negative ones?
I have an assignment in my Data Structures class in which I have to program a calculator that solves arithmetic expressions with the 4 basic operations and parenthesis, the input is done via the stdin buffer and the same with the output.
It was easy…

Mikael
- 969
- 12
- 24
3
votes
2 answers
Is it "Bad" practice to multiply $val * 1 to convert null to zero
I'm using PHP 5.5 to retrieve a numeric value from a numeric postgresql database table field. It could come from the DB as null or as an actual number, either way I store it in a variable. As some of us may or may not know null * 1 = 0, which is…

atomCode
- 842
- 7
- 17
3
votes
1 answer
Displaying DelayedExpansion variables inside a loop
I've got the following code which finds and prints out the values of of DWORD type within the key at SpecialUserRegDir. Secondary part of this code is a number that simply increases with each iteration. Unfortunately, I can't find a way to access…

Zero
- 1,562
- 1
- 13
- 29
3
votes
6 answers
Calculator using 2 stacks
I have an intel assembly assignment. I need to write a calculator which uses 2 stacks. For example, i have an expression like 23+4/2^4$ .So that $ indicates the end of expression. What I will do is to have two stacks, one for numbers, one for…

israkir
- 2,111
- 7
- 30
- 39
3
votes
3 answers
Implementing equality function with basic arithmetic operations
Given positive-integer inputs x and y, is there a mathematical formula that will return 1 if x==y and 0 otherwise? I am in the unfortunate position of having to use a tool that only allows me to use the following symbols: numerals 0-9; decimal point…
user2384183
3
votes
5 answers
Arithmetic Operation
hello guys I am having this problem. When I enter a score in the editText, I want the app to generate the equivalent in the Textview(w/ red box). But the app crashes with this code.
private void calculateEquivalent(){
double x , y;
…
user3660378
3
votes
1 answer
use prolog to solve arithmetic expression
i am a novice in Prolog.Now I want to use Prolog to solve arithmetic expression problems. suppose we have a predicate like this: expr(E,Val,Var,Sol)
the first is the expression the second is the value the third one is the variable and the forth one…

Lin Jiayin
- 499
- 1
- 6
- 11
3
votes
1 answer
Modular reduction of big numbers
For a toy program, I'd need an efficient way to compute
(2**64 * x) % m
where x and m are java longs and ** denotes exponentiation. This could be computed as
BigInteger.valueOf(x).shiftLeft(64).mod(BigInteger.valueOf(m)).longValue()
or by…

maaartinus
- 44,714
- 32
- 161
- 320