FAQ Database Discussion Community


Where does the recursive variable expansion in bash/shell numeric contexts come from?

bash,shell,posix,ksh,arithmetic-expressions
The POSIX spec states with regard to Arithmetic Expansion that [i]f the shell variable x contains a value that forms a valid integer constant, optionally including a leading plus or minus sign, then the arithmetic expansions "$((x))" and "$(($x))" shall return the same value. Which is a reasonable shortcut and...

How to perform arithmetic on the same line as a augmented assignment in Python 3.x.x?

python,arithmetic-expressions
In one of my programs, I had the following line: a = (a * b) + a Where a = 30, b = .05 This outputted 31.5 as the result This worked properly, but PyCharm told me I could turn it into an augmented assignment. I know that a *...

Is Swift the only (mainstream) language with overflow checking arithmetic?

performance,swift,language-agnostic,arithmetic-expressions
I started studying Swift language today. I've leaned up to basic and advanced operators. To me, the fact that all the default arithmetic operations in Swift are checked against overflow/underflow is a little surprising. Is there any other mainstream language with this feature? Is Swift runtime's arithmetic could be sub-optimal...

How to write an Scala parser for arithmetic operations including string?

scala,parsing,arithmetic-expressions
I am trying to use Scala Combinator-Parsing to parse and arithmetic operation in which at least one of the variables is string. I am a beginner in scala and I like this feature of it! For instance I wanna parse: (number + 2) * 4 It has a good example...

Wrong output from an double operation

java,double,arithmetic-expressions
I'm a beginner in Java programming. When I coded a simple console app it gave an output which was not what I wanted. My code is: class myClass{ public static void main(String[] args) { int ballsPlayed = 100; double o = (double)(( ballsPlayed / 6 ) + ( ( ballsPlayed...

Why is 3-1*8+2*3 equal to 1 [closed]

math,arithmetic-expressions
I used PEMDAS on 3 - 1 * 8 + 2 * 3. Steps: 1) 1 * 8 = 8 2) 2 * 3 = 6 3) 8 + 6 = 14 4) 3 - 14 = -11 Multiply all the terms, then add and finally subtract but I get...

Convert Text to Number in MySQL to allow arithmetic operators

mysql,arithmetic-expressions
I'm dealing with some crappy datasources (the data is being stored on another database and pushed into my database as text even though it should be stored as integer... this isn't always the case, but it is happening frequently due to the way the datasource was set up and unfortunately...

Bash arithmetic expression's side effects not executed

bash,post-increment,arithmetic-expressions,side-effects
$ declare -i i=0 $ for j in {0..2}; do echo "${j} $((i++))"; done 0 0 1 1 2 2 $ for j in {0..2}; do echo "$(echo "${j} $((i++))")"; done 0 3 1 3 2 3 $ Why i doesn't get incremented in the 2nd for loop? (Yes, I...

Adding two integers in the debugger gives unexpected output

int,lldb,arithmetic-expressions
I feel silly asking this, but I've debugged this as far as I can. I'm adding two integers together and am getting non-deterministic random letters as output. Any idea what's going on? ...