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
4
votes
2 answers
What else does round() do besides rounding a number?
I just "fixed" a bug in the following lines of PHP:
$value = 1091.09; // the failing test case
$prop = sprintf('%013d', $value * 100);
by adding those lines:
$cents = $value * 100; // $cents is now 109109
$cents =…

Hanno Fietz
- 30,799
- 47
- 148
- 234
4
votes
5 answers
comparing floating point numbers in C for unit testing
So I'm using CUnit to do unit testing. I expect something like
float x;
x = atof("17.99");
And I want to test this with an assert; obviously with some small epsilon I could
CU_ASSERT(abs(x - atof("17.99")) < epsilon);
However I'm considering
r…

Michael Conlen
- 1,959
- 2
- 17
- 19
4
votes
3 answers
Are basic arithmetic operations in C# atomic
Are the basic arithmetic operations Thread safe?
For example, if there is ++ operation on a global variable, which will be modified from different threads, is it necessary to a lock around it?
For example
void MyThread() // can have many running…

Shamim Hafiz - MSFT
- 21,454
- 43
- 116
- 176
3
votes
4 answers
WRBTR field calculation inside CASE throws error for max decimal places
I have following select:
SELECT FROM bseg
LEFT JOIN aufk ON ( ltrim( aufk~aufnr, '0' ) = bseg~zuonr )
JOIN bkpf ON bkpf~belnr = bseg~belnr AND bkpf~gjahr = bseg~gjahr AND bkpf~bukrs = bseg~bukrs
FIELDS bseg~bukrs, bseg~bschl, bseg~wrbtr,…

schmelto
- 427
- 5
- 18
3
votes
2 answers
Add 2d tuple to a 2d array in Julia
How to add a 2d tuple to a 2d matrix in Julia?
t1 = ((10,20),(30,40)); #2d immutable tuple
a = [1 2;3 4] #2d matrix
a .+ t1
throws an error:
MethodError: no method matching +(::Int64, ::Tuple{Int64, Int64})
Closest candidates are:
…

Vinod
- 4,138
- 11
- 49
- 65
3
votes
1 answer
Is $(( expr )) equivalent to $[ expr ] in bash?
Possible Duplicate:
bash: $[] vs. $(())
The $(( expr )) construct can be used for integer math in bash, e.g.
echo $(( 2*2 + 1 )) # 5
$[ expr ] seems to do to do the same (but isn't documented):
echo…

Eugene Yarmash
- 142,882
- 41
- 325
- 378
3
votes
2 answers
Check if 1/n has infinite number of digits after decimal point
If a user enters a number "n" (integer) not equal to 0, my program should check if the the fraction 1/n has infinite or finite number of digits after the decimal sign. For example: for n=2 we have 1/2=0.5, therefore we have 1 digit after the decimal…

Kotaka Danski
- 451
- 1
- 4
- 14
3
votes
1 answer
How to use a function to transform axis values with ggplot2?
Instead of 'log2', I want to use 'log2/(log2-1)'
sp <- ggplot(cars, aes(x = speed, y = dist)) + geom_point()
sp
sp + scale_x_continuous(trans='log2') +
scale_y_continuous(trans='log2')
When I try, I get:
object 'log2/(log2-1)_trans' of mode…

Krantz
- 1,424
- 1
- 12
- 31
3
votes
1 answer
Defining a left-to-right parser for arithmetic expressions
I'm having a hard time defining a left-to-right arithmetic expression parser in Haskell. What I have done so far is defining a right-to-left parser, following the "G. Hutton, Programming in Haskell" book.
-- the aexpr integer parser
aexpr_int ::…

mikelplhts
- 1,181
- 3
- 11
- 32
3
votes
1 answer
R- arithmetic does not respect logical NOT operator and order of operations?
It appears that the logical NOT operator ! has non-intuitive order of operations in arithemtic:
set.seed(42)
a <- sample(100, 3)
b <- sample(100, 3)
c <- sample(100, 3)
l <- (1:3) <= 2
a * !l - b * !l + c
# 0 0 29
# same expression, but…

cmo
- 3,762
- 4
- 36
- 64
3
votes
4 answers
expr and if in bash
What's wrong with this code? If I input the number 25, it output failed instead of lol. Am I missing something?
read -p "Enter number : " num
if [ `expr $num > 5` ]
then
echo "lol"
else
echo "failed"
fi

user8422062
- 59
- 1
- 3
3
votes
0 answers
Is there an algorithm to determine if an arithmetic function (given as an AST) is injective?
An arithmetic function is maths that uses only the arithmetic operators, addition, subtraction, multiplication and division.
I already have a way of parsing the expressions into an AST, so what I’m imagining is a tree walking algorithm to determine…

Robin Davis
- 622
- 4
- 10
3
votes
2 answers
"Indexing" a price series to a starting time point (index level = 100) with pandas data frame : P(i,t) / P(i)
I have a pandas data frame, where datetime is the index of the data frame (I use t=0 for simplification, in fact there is something like 20170101 09:30:00)
datetime Stock A Stock B
t=0 5 20
t=1 6 30
t=2 …

eternity1
- 651
- 2
- 15
- 31
3
votes
3 answers
Matlab: need some help for a seemingly simple vectorization of an operation
I would like to optimize this piece of Matlab code but so far I have failed. I have tried different combinations of repmat and sums and cumsums, but all my attempts seem to not give the correct result. I would appreciate some expert guidance on this…

SebDL
- 200
- 1
- 7
3
votes
1 answer
Algorithm to find if regularly recurring intervals of time overlap with each other?
There are multiple recurring intervals of time, starting from a startTime to an endTime. Each interval is defined by the start time of the recurrence, the end time (till the point where the recurrence is going to continue), the onDuration (when it…

user1271286
- 333
- 5
- 14