What is the best (fastest) way to clip a variable using C++ on a modern processor. e.g. If it is below a value, clip it to that value.  I'm aware of a few ways to do it, however, branch prediction comes to mind about the speed.  For example:  double ClipValue(double value) {   if (value &lt; 0)   {     value = 0.0;   }    return value; }   I would guess that the above would have to branch some of the time.  double ClipValue(double value) {   return value &lt; 0.0 ? 0.0 : value; }   This may not.  double ClipValue(double value) {   return std::max(value, 0.0); }   And I'm unsure how this would behave.  I guess a lot of it comes down to the compiler and optimizations settings, but what is generally considered the fastest method to saturate a variable. I have used double in this example but I'm equally interested in integers.
Is there a more efficient way to clamp real numbers than using if statements or ternary operators? I want to do this both for doubles and for a 32-bit fixpoint implementation (16.16). I'm not asking for code that can handle both cases; they will be handled in separate functions.  Obviously, I can do something like:  double clampedA; double a = calculate(); clampedA = a &gt; MY_MAX ? MY_MAX : a; clampedA = a &lt; MY_MIN ? MY_MIN : a;   or  double a = calculate(); double clampedA = a; if(clampedA &gt; MY_MAX)     clampedA = MY_MAX; else if(clampedA &lt; MY_MIN)     clampedA = MY_MIN;   The fixpoint version would use functions/macros for comparisons.  This is done in a performance-critical part of the code, so I'm looking for an as efficient way to do it as possible (which I suspect would involve bit-manipulation)   EDIT: It has to be standard/portable C, platform-specific functionality is not of any interest here. Also, MY_MIN and MY_MAX are the same type as the value I want clamped (doubles in the examples above).
Conditional expectation of $X$ given $\sin(X)$ Random place change in row with restrictions Let $X \sim Bin(n,p)$ show that $X/n \nsim Bin()$ Let $X \sim Bin(n,p)$   Part A.  Show that the argument      "Then $X/n \sim Bin()$ with $E[X/n]=p$and $Var[X/n]=pq/n$"    is false.   My book says we can prove this result using a moment generating function. But to me it makes no intuitive sense: We have Bin-distributed RV $X$ and if we rescale it with $1/n$ of course it will be Bin-distributed.  And we know from standard formulas that $E[aX]=aE[X]$ and $Var[aX] = a^2Var[X]$ so I think the argument is correct.   (For full disclosure, the argument we should falsify according to the book is "Let X be a binomial random variable with mean np and variance np(1−p). Show that the ratio X/n also has a binomial distribution with mean p and variance p(1−p)/n." But I think the argument is correct. )    Ok, now I get part A. Here is Part B. Prove it using the moment generating function of $X/n$.   Attempt: I get $$m_X(t)=E[\exp(tX/n)]=(m_X(t))^{1/n}$$ Verbatim Environment in Figure Caption Why have the subjunctive and indicative converged in Modern English? Dwellers return automatically after finding a low amount of items in Wasteland I have a strange thing happening - dwellers I send to explore wasteland are automatically returning to vault after finding a little amount of items (4 or 5).   The exploration log says: "That's as much as I can carry. I better head back and show the Overseer what I found".  Before today they successfully carried up to 30 items and never returned to vault on their own.  I don't know is it relevant or not, but I have a lot of free storage space available.  What caused this change? What can I do to prevent this? I've posted a question or an answer, and I have received one or more downvotes. I am not really sure why I was down voted, or I think I know why, but I disagree.  Why did this happen, and what should I do about it? I've a Skype interview for PhD application (it will make me miss  today.) I've been asked, in advance, to prepare a short presentation and then there would be some discussion with the panel (I guess.) I expect that they will ask if I have some questions so, I'm wondering what are the best (type of) questions one might consider? Getting tabular statistics from table using QGIS? Are there QGIS tools that will allow users to get tabular statistics from their table?  I kind of expected I would be able to just open the table, select the field I was interested in, right-click on the field header and get something similar to this (screenshot taken from ArcGIS):    More specifically, I am looking for a QGIS alternative to the ArcGIS  and  tools, that offer a  you can retrieve about the tabular data.    Just after asking, I found  (see section 4.2 ) that describes how to find this functionality... Vector > Analysis Tools > Basic statistics.  I also found Vector > Analysis Tools > List Unique Values right next to it.  This gets me the list of unique values, but I would also like to see an additional column of frequency (count) of each unique item.  Is this similar tool available "out-of-the-box"? A well-supported wireless PCI adapter for Ubuntu 12.04? Will this schematic work as a four-bit shift register? &ndash; Schematic created using   Will this work as a four-bit shift register? (And by extension a shift register of any size?) Each vertical PMOS / NMOS transistor pair acts as a multiplexer, and the PMOS transistor to its left amplifies the voltage back up to close to V_high. I'd be interested in hearing people's feedback on this. Right now I have only three transistors (and a resistor) per bit. Can I really get it that small a ratio, or are there reasons why I need more transistors per bit?  It's probably worth noting that I don't have master/slave here, so I can only assert (Shift) long enough to move one bit toward the right and no more.  Furthermore, I'm not trying to say that I need a resistor with 100 ohms. That appeared to be the only resistor I could use to make this schematic! What I want is a resistor that has significantly less resistance than the PMOS it's next to when it's at high impedance, but enough resistance to prevent a short circuit from V_high to ground when that transistor is conducting.  Okay, now I've changed each of the BJT's to MOSFET's, and reduced the resistance of each resistor from 100 ohms to 10 ohms. I'm still going on the assumption that (shift) will only be asserted long enough for the gate delays of M4 and M5, and then of M6, so the value of (dataIn) will only make it to M6's output, and won't move to M8 until the next time (shift) is asserted. Is this enough to get this circuit behaving like a four-bit shift register? Defender of the Realm hat broken, or just badly worded? Description of the hat unlock requirement:     at least 5 flags dismissed as helpful and at most 20% of non-disputed flags declined   Does "dismissed" mean something unusual here, or is this hat not unlocking properly? I'm not sure if that means "since winter bash started" or "since your account was created": if the former, I've flagged 8 items so far today, of which 6 were marked "helpful" (the other two are still active; none have been disputed or declined). If the latter, the flag page indicates I've flagged 391 items (plus 6 for spam), of which 1 was declined (which incidentally, I assume that was by accident, given that the question was closed soon after for the reason I flagged it for), 1 was disputed (that one was legitimate), and 21 are still open. That is definitely way under 20%.  So what's up with that unlock?  edit: it appears to be the case (further edit: this has now been confirmed first-hand) that this hat unlock disregards any flags that are the flag equivalent of voting to close. I put forth that if this is intended behavior, well, it shouldn't be (if it's to equalize the playing field for over-3k-rep people, it should just also count votes-to-close. Though granted, I suppose in the scheme of things it really doesn't matter much, as it'll all go away in a couple weeks anyway. But dang it, I want to show off all the flagging I do! :p) I made an svg in Illustrator, but now I want to use it in a website/app but it's a huge size (around 10 MB) how can I decrease the size of it? My illustrator file is pretty big but that because I have some tracing elements underneath. The file also has a big artboard, but when I save should I delete my tracing elements, and decrease the artboard size? Calculating the limit $\lim((n!)^{1/n})$ Find $\lim_{n\to\infty} ((n!)^{1/n})$. The question seemed rather simple at first, and then I realized I was not sure how to properly deal with this at all. My attempt: take the logarithm,  $$\lim_{n\to\infty} \ln((n!)^{1/n}) =  \lim_{n\to\infty} (1/n)\ln(n!) =  \lim_{n\to\infty} (\ln(n!)/n)$$ Applying L'hopital's rule:  $$\lim_{n\to\infty} [n! (-\gamma + \sum(1/k))]/n! = \lim_{n\to\infty} (-\gamma + \sum(1/k))=  \lim_{n\to\infty} (-(\lim(\sum(1/k) - \ln(n)) + \sum(1/k))  = \lim_{n\to\infty} (\ln(n) + \sum(1/k)-\sum(1/k)  = \lim_{n\to\infty} (\ln(n))$$ I proceeded to expand the $\ln(n)$ out into Maclaurin form $$\lim_{n\to\infty} (n + (n^2/2)+...) = \infty$$ Since I $\ln$'ed in the beginning, I proceeded to e the infinity  $$= e^\infty  = \infty$$  So am I write in how I approached this or am I just not on the right track? I know it diverges, I was just wanted to try my best to explicitly show it. I've got a qml file and I just want to ssh to the phone and do  qmlscene myfile.qml   Is it possible without doing all that stuff with SDK and packages? Just vim and some simple commands that can fit into person's memory. What does it do exactly if I click in the window of cmd? Suppose I run cmd.exe and ping localhost. After that I ping localhost again but I click into the window and the ping stops until I press enter.  What happens exactly when I click into the window? Does it suspend the process or something else? I attached a screenshot to clarify this issue.  Note: I do not actually click but drag using the mouse which creates a white box in the window as you can see on the screenshot.  Edit: further clarification: What I really wish to know is whether dragging the window halts the cmd process or not?  Edit: even more clarification: I know that I'm using Quick Edit and pressing enter copies the contents I selected. What I do not know is what happens in the background. What resampling method is used in the raster 'Save as...' dialog? I received a raster that was resampled using the Save as dialog in QGIS. Now I need to describe the resampling process in a report. But I could not figure out the method used in the resampling. Is it Nearest Neighbor? Bicubic?  This question has been asked before () but the answer does not specify the method used.   I also tried looking at the QGis source code in GitHub, but unfortunately, I could not find where the magic takes place (I'm not a programmer) "Naturally occurring" non-Hausdorff spaces? What do parentheses surrounding an object/function/class declaration mean? I'm new to both JavaScript and . In YUI library examples, you can find many uses of this construct:  (function() {     var Dom = YAHOO.util.Dom,     Event = YAHOO.util.Event,     layout = null,         ... })();   I think the last couple of parentheses are to execute the function just after the declaration.  ... But what about the previous set of parentheses surrounding the function declaration?  I think it is a matter of scope; that's to hide inside variables to outside functions and possibly global objects. Is it? More generally, what are the mechanics of those parentheses? Performance Advantages to Iterators? What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that.