Times-two faster than bit-shift, for Python 3.x integers?

This seems to be because multiplication of small numbers is optimized in CPython 3.5, in a way that left shifts by small numbers are not. Positive left shifts always create a larger integer object to store the result, as part of the calculation, while for multiplications of the sort you used in your test, a … Read more

Unexpected results when working with very big integers on interpreted languages

Python works: >>> sum(x for x in xrange(1000000000 + 1)) 500000000500000000 Or: >>> sum(xrange(1000000000+1)) 500000000500000000 Python’s int auto promotes to a Python long which supports arbitrary precision. It will produce the correct answer on 32 or 64 bit platforms. This can be seen by raising 2 to a power far greater than the bit width … Read more

How can I add numbers in a Bash script?

For integers: Use arithmetic expansion: $((EXPR)) num=$((num1 + num2)) num=$(($num1 + $num2)) # Also works num=$((num1 + 2 + 3)) # … num=$[num1+num2] # Old, deprecated arithmetic expression syntax Using the external expr utility. Note that this is only needed for really old systems. num=`expr $num1 + $num2` # Whitespace for expr is important For … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)