Integer arithmetics in C# can be set to throw an  using checked, as in the following example:   int a = foo(); int b = bar() int result = checked(a * b); // Will result in OverflowException if this overflows   I'm currently getting more into C programming and just found a bug that was due to an integer overflow - which would have been much more easier to find with something like checked - and I ask myself: Why is nothing similar implemented in C? Can someone explain it to me or point me out (some standard reference, etc.) where it is stated why such a construct is not part of the C language?   Or am I completely wrong and there is some built-in functionality to check for (integer) overflows on arithmetic operations?
I was writing a program in C++ to find all solutions of ab = c, where a, b and c together use all the digits 0-9 exactly once. The program looped over values of a and b, and it ran a digit-counting routine each time on a, b and ab to check if the digits condition was satisfied.  However, spurious solutions can be generated when ab overflows the integer limit. I ended up checking for this using code like:  unsigned long b, c, c_test; ... c_test=c*b;         // Possible overflow if (c_test/b != c) {/* There has been an overflow*/} else c=c_test;      // No overflow   Is there a better way of testing for overflow? I know that some chips have an internal flag that is set when overflow occurs, but I've never seen it accessed through C or C++.    Beware that signed int overflow is undefined behaviour in C and C++, and thus you have to detect it without actually causing it. For signed int overflow before addition, see .
I am trying to parse url-encoded strings that are made up of key=value pairs separated by either &amp; or &amp;amp;.   The following will only match the first occurrence, breaking apart the keys and values into separate result elements:  var result = mystring.match(/(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/)   The results for the string '1111342=Adam%20Franco&amp;348572=Bob%20Jones' would be:  ['1111342', 'Adam%20Franco']   Using the global flag, 'g', will match all occurrences, but only return the fully matched sub-strings, not the separated keys and values:  var result = mystring.match(/(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/g)   The results for the string '1111342=Adam%20Franco&amp;348572=Bob%20Jones' would be:  ['1111342=Adam%20Franco', '&amp;348572=Bob%20Jones']   While I could split the string on &amp; and break apart each key/value pair individually, is there any way using JavaScript's regular expression support to match multiple occurrences of the pattern /(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/ similar to PHP's preg_match_all() function?  I'm aiming for some way to get results with the sub-matches separated like:  [['1111342', '348572'], ['Adam%20Franco', 'Bob%20Jones']]   or   [['1111342', 'Adam%20Franco'], ['348572', 'Bob%20Jones']] Limit point versus limit and implications for convergence I understand that similar questions to this have been asked  and  but I believe my question is different because with regards to (1) I am not asking about the set $X$ that contains the points of my sequence and with regard to (2) because I have the distinct definitions of limit and limit point in mind. That said:  My Question: My textbook, Fundamental Ideas of Analysis by Michael Reed, defines a limit point as:     Definition: Let $(a_n)$ be a sequence of real numbers. A number $d$ is called a limit point if, given $\epsilon &gt; 0$ and an integer $N$, there exists $\color{red}{\mathrm{ an }} \ n \ge N$ so that $|a_n - d| \le \epsilon$.    The definition of a limit is as follows:     Definition: We say that a sequence $(a_n)$ converges to a limit $a$ if, for every $\epsilon \ge 0$, there is an integer $N(\epsilon)$ so that $|a_n - a| \le \epsilon \color{red}{\text{  for all  }} n \ge N$.    From these definitions, and given this question:     If a sequence converges it has exactly one limit point. Is the converse true? If not, provide a counterexample   Can I conclude that the converse is indeed true simply by appealing to the definitions, or do I need a tighter proof. And if I do, I'm a little stuck on how to refine this proof. Why is there one P in "hoping" and two P's in "hopping"? Hoping is the present participle of hope. hopping is the present participle of hop. Hoping has only one p while hopping has two. What difference does it make? Why is hoping not hopping?  Edit: I changed mop to hop because of a comment by Kat.  Kat: Why would you compare hope to mop instead of hope to hop (in which case I think your answer will become obvious)? How to enlarge Ubuntu system partition to the left? sda6 is ext4 file system and where my ubuntu is installed, 30GB. sda3 is "ntfs" file system and where my windows is installed, 400GB. sda7 is a 50 GB empty partition with "ext4" file system.   How to move the space of sda7 to sda6 to let sda6 become 50+28=78 GB.    Here's a real case of mine :( I want to add more space into my ubuntu (28.2 GB one) from other emtpy partition space. A better serial voting trap Currently we capture fanatic, voting ring or rage-type activities, by measuring the number of up-votes or down-votes between the same two users in a certain (relatively short) time period. When this is detected by the system, the votes are reversed, and I've never bothered to investigate what else happens after that - though I'm sure some form of wrist-slapping ensues.  While it is intended to be well-guarded for obvious reasons, the algorithm used is not exactly a secret, and I am sure there are plenty of examples where people are dangling (maybe intentionally, or maybe by dumb luck) just on the safe side of getting caught.  Personally I believe there are active, intentional, long-term vendettas in operation right now where users either:   blindly up-vote every answer from a user; or, down-vote a particular user once or twice a day, regardless of topic or quality.   Now, maybe the first one is valid - if I'm operating in the same tag-sphere as some smart person, it may just be that I'm constantly enthralled with their answers, and I'm not even noticing who they're written by. (Though, even Skeet isn't perfect, and I haven't up-voted every answer I've seen him post.)  But still, can we do a better job of catching - or at least noticing - this activity over the long term in addition to the short term?  The behavior is the same, and shouldn't be tolerated, regardless of the time frame - vengeful rage serial voting, blind staker crush serial voting, and painstakingly patient serial voting are all undesirable behaviors IMHO.  I'm not saying it has to do anything automatically, as I'm well aware of the possibility of false positives. And I'm not even sure what to propose as a time frame or a vote threshold.      But if a large percentage of my up-votes or down-votes are against a particular user, and especially if on a majority of those posts I am the only one voting in that direction, I think it should at least be raised as some kind of flag to moderators.   This would work much like how other suspicious activity is highlighted (but also not dealt with automatically). If a pattern becomes obvious and persists, then they can intervene in some way (or not, but at least they were provided with the information - just like they can reject and ignore manual flags). Today, all I can do is e-mail team@stackoverflow.com, and unless I know exactly which person(s) are involved, there is not much they can do about it.  And you're thinking, "Meh, let some hater down-vote you once or twice a day. Unless all you're posting is utter crap, it should be statistically insignificant." You're right. But reputation is not the point, and is not the motivation behind my request. What I'd like to see curtailed is the tendency for folks to down-vote a question or answer because of who posted it, not because of what it said or didn't say. When a down-vote is personal it can leave a person second-guessing the quality of their post. Which isn't necessarily a bad thing, except when it happens repeatedly.  Sorry for the essay but I wanted to try to anticipate and cover all the objections and hole-poking. Today I was walking using my iPhone 6S running iOS 9.3 as a pedometer and it shutdown.   When I got home and plugged it in, it said 30% capacity.   That seems strange. I would expect it for 2% or 5% to preserve RAM, but 30%? Maybe there is a setting I don't know about.   My question is: Why does my iPhone power off when the battery is down to 30%?   Edit: this is not a duplicate of the low battery crash as I witnessed the low power shutdown and it was not a crash. I am trying to find out whether $A = \begin{bmatrix}     3 &amp; 1 \\     0 &amp; 2 \\ \end{bmatrix}$ and $B = \begin{bmatrix}     4 &amp; 1 \\     -2 &amp; 1 \\ \end{bmatrix}$ are similar. Both matrices have the same trace, same rank, same determinant and the same eigenvalues. So I think they are similar. The eigenvalues are $3, 2$. Now I'm not sure how to find if they are indeed similar.   I am trying to find if there is a basis for $\mathbb{R^2}$ that contains only eigenvectors but when trying to solve $(3 I - A)v = 0$ there is no solution... What should I do from here? Do I need a Schengen visa if I have UK permanent residency? InDesign: How to restore text-frame position/size to be managed by the master page instead of the actual page? I have some designer that moved slightly a text-frame and in order to be managed again by the master page we need to remove the page and create a new one inserting the content in it.  Is there any different way to do it?  I would like to be able to restore the "power" of positioning/size to the master page because now we need to change the master-page to position the text-frame a little bit to the right and in the case above mentioned will not be updated.  Thanks How can I disable the 2nd hard drive in my 27" iMac? Some websites have code to "break out" of IFRAME enclosures, meaning that if a page A is loaded as an IFRAME inside an parent page P some Javascript in A redirects the outer window to A.  Typically this Javascript looks something like this:  &lt;script type="text/javascript"&gt;   if (top.location.href != self.location.href)      top.location.href = self.location.href; &lt;/script&gt;   My question is: As the author of the parent page P and not being the author of the inner page A, how can I prevent A from doing this break-out?  P.S. It seems to me like it ought to be a cross-site security violation, but it isn't. Let f(x) be a  polynomial satisfying $\lim_{x \to\infty} \frac{x^4f(x)}{x^8+1}=3,$  $f(2)=5 $ and $f(3)=10$, $f(-1)=2$ and $f(-6)=37$ . And then there are some question related to this. In the solution it is given that according to the given information, $f(x)$ is a polynomial of degree 4 with leading coefficient 3. $f(x)=3(x-2)(x-3)(x+1)(x+6)+(x^2+1)$ Now what i think is that he got the coefficient 3 using the limits and the rest of the terms$[(x-2)(x-3)(x+1)(x+6)]$ from the respective $f(x)$ values from what was given and also the $(x^2+1)$ was added for the remainders, as they satisfy all the values that have been given to us in the question. I just wanted to know if my approach is right? or is there another elegant way to do it?. Proving the given quadratic form is chi-squared $k$ Suppose $\underline{X}$ is an $m$-dimensional vector following multivariate Normal distribution i.e. $\underline{X}$~$N_m(\underline{\mu},\Sigma)$ where $\Sigma$ is positive definite. Let $B$ be a symmetric $m$ by $m$ matrix, having the following properties:  $B\Sigma B=B$  $\underline{\mu}'B\underline{\mu}=0$  $trace(B\Sigma)=k$, where $k&lt;m$   Prove that $\underline{X}'B\underline{X}$ follows chi-squared ($k$).  I proceeded a lot but got stuck in one last step where I think linear algebra is troubling me. Kindly have  a look at my &quot;solution&quot;.  The second condition can be written as $\underline{\mu}'B\Sigma B\underline{\mu}=0\implies B\underline{\mu}=\underline{0}$ as $\Sigma$ is Positive definite. Then after a little algebra and considering condition 2, we can write $\underline{X}'B\underline{X}=(\underline{X}-\underline{\mu})'B(\underline{X}-\underline{\mu})=(\underline{X}-\underline{\mu})'B\Sigma B(\underline{X}-\underline{\mu})$ But $\Sigma$ is positive definite hence we can have a symmetric matrix $\sqrt{\Sigma}$ defined such that $\sqrt{\Sigma}\sqrt{\Sigma}=\Sigma$. Using this, we can write $(\underline{X}-\underline{\mu})'B\Sigma B(\underline{X}-\underline{\mu})=(\sqrt{\Sigma}B(\underline{X}-\underline{\mu}))'(\sqrt{\Sigma}B(\underline{X}-\underline{\mu}))$ We want to show that this follows chi-squared ($k$). Now, it is obvious that as $(\underline{X}-\underline{\mu})$~$N(\underline{0},\Sigma)$, $\sqrt{\Sigma}B(\underline{X}-\underline{\mu})$~$N(\underline{0},\sqrt{\Sigma}B\Sigma B\sqrt{\Sigma})=N(\underline{0},\sqrt{\Sigma}B\sqrt{\Sigma})$ Now, $trace(\sqrt{\Sigma}B\sqrt{\Sigma})=trace(B\Sigma)=k$ and $\sqrt{\Sigma}B\sqrt{\Sigma}$ is idempotent (verified). So its eigenvalues are only $0$ or $1$. Since its trace is $k$, there are $k$ eigenvalues with value $1$ and other $m-k$ eigenvalues are $0$. Now here is the thing I want to prove: I want to show that$\sqrt{\Sigma}B\sqrt{\Sigma}$, which is the covariance matrix, is diagonal and has only $k$ $1$'s and remaining $m-k$ diagonal entries $0$. The reason is, then I will be able to say that $k$ components of $\sqrt{\Sigma}B(\underline{X}-\underline{\mu})$ are independent standard normals whose sum of squares is our quadratic form and thus it follows chi-squared ($k$). But I really could not show that $\sqrt{\Sigma}B\sqrt{\Sigma}$ has the desired property i.e. it is diagonal with rank $k$. But this is crucial, it is the finale. If this does not happen, then some components will be correlated with each other and we cannot say that our quadratic form has chi-squared ($k$). I would really appreciate if someone helped me to prove this final part. How to replace a string with a string containing slash with sed? I am looking for a way to replace a string in a file with a string that contains a slash by using sed.  connect="192.168.100.61/foo" srcText="foo.bar=XPLACEHOLDERX" echo $srcText | sed "s/XPLACEHOLDERX/$connect"   The result is:  sed: -e Expression #1, Character 32: Unknown option for `s' Science fiction story where a colonist is sent by a company to colonize a planet and there a robot tries to sell him a depilating liquid by pulling a gun on him. The company who sponsored his trip to the new planet is extorting him by charging him exorbitant rates for anything they declare is not considered by them as bare necessities. The robot and man collaborate to get from the company the fair deal he deserves. Multivariate polynomial with no mixed terms Is there a standard name for multivariate polynomials wherein each term consists of only one coordinate? That is, polynomials of this form: $$p(x_1, \ldots, x_n)= \sum_{i=1}^n \sum_{j=1}^n a_{i,j}x_i^{j}$$ where all of the $a_{i,j}$ are constants. What is the name for moments, a parameter that is calculated C# Equivalent of SQL Server DataTypes For the following SQL Server datatypes, what would be the corresponding datatype in C#?  Exact Numerics  bigint numeric bit smallint decimal smallmoney int tinyint money     Approximate Numerics  float real     Date and Time  date datetimeoffset datetime2 smalldatetime datetime time     Character Strings  char varchar text     Unicode Character Strings  nchar nvarchar ntext     Binary Strings  binary varbinary image     Other Data Types  cursor timestamp hierarchyid uniqueidentifier sql_variant xml table   (source: ) I was given this problem 30 years ago by a coworker, posted it 15 years ago to rec.puzzles, and got a solution from Barry Wolk, but have never seen it again.  Consider the series:  $$1, \frac{1}{2},\frac{\displaystyle\frac{1}{2}}{\displaystyle\frac{3}{4}},\frac{\displaystyle\frac{\displaystyle\frac{1}{2}}{\displaystyle\frac{3}{4}}}{\displaystyle\frac{\displaystyle\frac{5}{6}}{\displaystyle\frac{7}{8}}},\cdots$$  Each fraction keeps its large bars while being put atop a similar structure. This can also be represented as $$\frac{1\cdot 4 \cdot 6 \cdot 7 \cdot\cdots}{2 \cdot 3 \cdot 5 \cdot 8 \cdot\cdots}$$ terminating at $2^n$ for some $n$, where it is much closer to the limit than elsewhere.  The challenge:   Find the limit, not too hard by experiment In the last expression, find a simple, nonrecursive, expression to say whether $n$ is in the numerator or denominator Prove the limit is correct-this is the hard one. Prove that $|f''(\xi)|\geqslant\frac{4|f(a)-f(b)|}{(b-a)^2}$ Let ${\rm f}:\left[a, b\right]\to\mathbb{R}$ be twice differentiable, and suppose   $$\lim_{x\to a^{+}} \frac{{\rm f}\left(x\right) - {\rm f}\left(a\right)}{x - a} = \lim_{x\to b^{-}}\frac{{\rm f}\left(x\right) - {\rm f}\left(b\right)}{x - b} =0 $$  Show that there exists $\xi \in \left(a, b\right)$ such that $\displaystyle{% \left\vert\vphantom{\Large A}\,{\rm f}''\left(\xi\right)\right\vert \geq \frac{4\left\vert\vphantom{\Large A}% \,{\rm f}\left(a\right) - {\rm f}\left(b\right)\right\vert} {\left(b - a\right)^{2}}}$.  I don't know how to start. Any hints ?.