arithmetic-expressions

C# checking if expression is brackets valid [closed]

混江龙づ霸主 提交于 2019-12-20 07:27:34
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . The expression: "( a[i]+{-1}*(8-9) )" should return true since it is valid to write syntax like this. Every left bracket has a right closer in the correct place and all brackets are at legal positions. I tried to do this via one stack and I know where I'm wrong but I want to know

Comparison of double, long double, float and float128?

荒凉一梦 提交于 2019-12-20 06:01:04
问题 Why is there no difference between double, long double or float? For instance, the computation of pi in C++ is, #include <iostream> #include <quadmath.h> #include <math.h> int main() { float PI0 = acos(-1.0); double PI1 = acos(-1.0); long double PI2= acos(-1.0L); __float128 x = acos(-1.0); char buf[128]; quadmath_snprintf (buf, sizeof buf, "%*.34Qf",10, x); std::cout << "Float=" << PI0 << std::endl; std::cout << "Double=" << PI1 << std::endl; std::cout << "LongDouble=" << PI2 << std::endl;

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

只谈情不闲聊 提交于 2019-12-20 01:08:51
问题 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 cleans up complicated expressions rather nicely. bash (versions 3.2.25(1)-release from CentOS 5 and 4.3.33(1)-release from debian unstable) as well as ksh ( Version AJM 93t+ 2010-06-21

Arithmetic operation within string concatenation without parenthesis causes strange result

对着背影说爱祢 提交于 2019-12-19 09:10:17
问题 Consider the following line of code: <?php $x = 10; $y = 7; echo '10 - 7 = '.$x-$y; ?> The output of that is 3, which is the expected result of the calculation $x-$y. However, the expected output is: 10 - 7 = 3 My question therefore is, what happened to the string that I'm concatenating with the calculation? I know that in order to produce the result I expected, I need to enclose the arithmetic operation in parenthesis: <?php $x = 10; $y = 7; echo '10 - 7 = '.($x-$y); ?> outputs 10 - 7 = 3

Arithmetic operation within string concatenation without parenthesis causes strange result

人走茶凉 提交于 2019-12-19 09:10:11
问题 Consider the following line of code: <?php $x = 10; $y = 7; echo '10 - 7 = '.$x-$y; ?> The output of that is 3, which is the expected result of the calculation $x-$y. However, the expected output is: 10 - 7 = 3 My question therefore is, what happened to the string that I'm concatenating with the calculation? I know that in order to produce the result I expected, I need to enclose the arithmetic operation in parenthesis: <?php $x = 10; $y = 7; echo '10 - 7 = '.($x-$y); ?> outputs 10 - 7 = 3

Arithmetic C++ Operators

此生再无相见时 提交于 2019-12-19 05:25:09
问题 I was just asked a question in a technical interview that I was a bit confused about. The question was as follows: If int i = -1, int j = -1, and int k = -1, and we run the following line: ++i && ++j && ++k what would be the new values of i, j, and k? The reason I was confused is that, since we are not assigning this expression to anything, it doesn't seem like the and operators should make any difference (only the increment operators should). However, running a simple test program quickly

Why does NaN^0 == 1

谁说胖子不能爱 提交于 2019-12-17 10:49:07
问题 Prompted by a spot of earlier code golfing why would: >NaN^0 [1] 1 It makes perfect sense for NA^0 to be 1 because NA is missing data, and any number raised to 0 will give 1, including -Inf and Inf . However NaN is supposed to represent not-a-number , so why would this be so? This is even more confusing/worrying when the help page for ?NaN states: In R, basically all mathematical functions (including basic Arithmetic), are supposed to work properly with +/- Inf and NaN as input or output. The

How do promotion rules work when the signedness on either side of a binary operator differ? [duplicate]

£可爱£侵袭症+ 提交于 2019-12-17 00:05:53
问题 This question already has answers here : Implicit type conversion rules in C++ operators (9 answers) Closed last year . Consider the following programs: // http://ideone.com/4I0dT #include <limits> #include <iostream> int main() { int max = std::numeric_limits<int>::max(); unsigned int one = 1; unsigned int result = max + one; std::cout << result; } and // http://ideone.com/UBuFZ #include <limits> #include <iostream> int main() { unsigned int us = 42; int neg = -43; int result = us + neg; std

How do promotion rules work when the signedness on either side of a binary operator differ? [duplicate]

假装没事ソ 提交于 2019-12-17 00:05:31
问题 This question already has answers here : Implicit type conversion rules in C++ operators (9 answers) Closed last year . Consider the following programs: // http://ideone.com/4I0dT #include <limits> #include <iostream> int main() { int max = std::numeric_limits<int>::max(); unsigned int one = 1; unsigned int result = max + one; std::cout << result; } and // http://ideone.com/UBuFZ #include <limits> #include <iostream> int main() { unsigned int us = 42; int neg = -43; int result = us + neg; std

Difference between v.assign(v + 1) and v = v + 1 in Tensorflow

こ雲淡風輕ζ 提交于 2019-12-13 06:34:08
问题 The following Tensorflow code works fine and v1 becomes [1., 1., 1.] v1 = tf.get_variable('v1', shape=[3], initializer=tf.zeros_initializer) v1 = v1 + 1 with tf.Session() as sess: sess.run(tf.global_variables_initializer()) print (v1.eval()) The following code segment also gives us the exactly the same result as the above. v1 becomes [1., 1., 1.] if we run sess.run(inc_v1) . v1 = tf.get_variable('v1', shape=[3], initializer=tf.zeros_initializer) inc_v1 = v1.assign(v1 + 1) with tf.Session() as