Well, I tried out a couple of lines but it seems not to work.  double equation= ( ((double)avg-(double)cur_avg) / (1/(double)n) ); cout&lt;&lt;"equation is "&lt;&lt;equation&lt;&lt;endl; lld needed = ceil(equation); cout&lt;&lt;"needed is "&lt;&lt;needed&lt;&lt;endl;   Here avg and n are integers of type long long int. And cur_avg is already a double. Also avg=4, n=5 and cur_avg=3.4 . The output in the terminal reads as follows:  output: equation is 3 needed is 4   Now, my question is if "equation" is 3 then ceil(equation) should have been 3 as well, but why it reads 4 then? In short, what I require is this:  output: equation is 3 needed is 3   Also, how to modify the above code snippet to get this result?  Edit:  Thank you  for proposing the solution in the comments.  An explanation of this behavior could be found  A probable solution is to subtract a small epsilon when calling ceil:  double equation= ( ((double)avg-(double)cur_avg) / (1/(double)n) ); cout&lt;&lt;"equation is "&lt;&lt;equation&lt;&lt;endl; lld needed = ceil(equation - .000001); cout&lt;&lt;"needed is "&lt;&lt;needed&lt;&lt;endl;
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
Is $\lim\limits_{n\rightarrow\infty} n$ comparable to $\aleph_0$? For example, can we say: $\infty=\lim\limits_{n\rightarrow\infty} n &lt; \aleph_0$?  These are two different types of structures. The limit being like the length, extension, or just generic magnitude and the other being cardinality of a set. Can we compare magnitude to cardinality?  Intuitively, we can reach $\aleph_0$ by counting the natural numbers on the number line and in the process will be approaching $\infty$. Which leads me to believe $\infty\leq\aleph_0$. But I can't see why it should be a strict inequality. I feel like they should be of equal magnitude.  I saw on a recent comment that $2^\infty=\infty$, but are those infinities really the same? It seems not to me. Of course we (usually) have that  $2^{\aleph_0}=\aleph_1$ where ${\aleph_0}$ and $\aleph_1$ are clearly two very distinct infinities, countable vs uncountable at least. Maybe one might argue that as far as the concept of magnitude is concerned, all infinities are "equal". $$ z = 1+2i \ (complex \ number) \\ z^n = a_n + b_ni \ \ \ (a_n, b_n \in \mathbb{Z}, n \in \mathbb{N}^*) $$ Prove that $ b_{n+2} - 2b_{n+1} + 5b_n = 0$  How can I solve this? Thank you!  EDIT: Or please tell me your ideas. Prove a graph Containing $2k$ odd vertices contains $k$ distinct trails I'm reading the book Graphs and Their Uses which contains the following theorem and proof:     THEOREM 2.3. A connected graph with 2k odd vertices contains a family   of k distinct trails which, together, traverse all edges of the graph   exactly once.       PROOF. Let the odd vertices in the graph be denoted by   in some order.       $a_1,a_2,\dots,a_k$ and $b_1,b_2,\dots,b_k$      When we add the $k$ edges $a_lb_l, a_2b_2 ,\dots, a_kb_k$ to the graph, all   vertices become even and there is an Eulerian trail T. When these   edges are dropped out again, T falls into k separate trails covering   the edges in the original graph.   However this doesn't seem to make sense since in the graph whose vertices have degrees 3, 1, 1, 1 there is no way to add 2 edges in such a way that the degree of all odd vertices becomes even.  What am I missing here? Is there an elegant way to have performant, natural sorting in a MySQL database?  For example if I have this data set:   Final Fantasy Final Fantasy 4 Final Fantasy 10 Final Fantasy 12 Final Fantasy 12: Chains of Promathia Final Fantasy Adventure Final Fantasy Origins Final Fantasy Tactics   Any other elegant solution than to split up the games' names into their components    Title: "Final Fantasy" Number: "12" Subtitle: "Chains of Promathia"   to make sure that they come out in the right order? (10 after 4, not before 2).  Doing so is a pain in the a** because every now and then there's another game that breaks that mechanism of parsing the game title (e.g. "Warhammer 40,000", "James Bond 007") Vec2 a, b; // some random vector Vec2 cross = a.Cross(b); RelativeDirection(a,b,cross); // return true if the direction of                               // rotating a to b is counter-clockwise   How do I implement the function RelativeDirection()?  I got some suedo code from the textbook:  if a.Cross(b) &gt; 0 then ... else ...   but the cross product is a vector right? how do you compare it with an integer? iPhone 7 Plus takes days to turn on showing Apple logo or black screen I’ve had this issue for months but in the last couple of days it’s got very very bad.  When my phone runs out of battery it needs like 2–3 days to turn back on. At the beginning of this problem the phone would need about 1h. Every time when my phone goes off again the time to switching on goes up.  What does this all look like? Well, when my phone died I put it on the charger, then the logo appears and goes off. When it goes off, a black screen pops out with a little white line on in it, then it turns on back to Apple logo. It keeps doing this until it turns on which is 1 or 2 even now 3 days.  I tried to restore it and also update it but nothing happens, literally nothing happened. Did Voldemort refer to Snape as one of the missing Death Eaters at his rebirth? In Goblet of Fire, Voldemort says of the missing six Death Eaters:     “And here we have six missing Death Eaters… three dead in my service. One,   too cowardly to return… he will pay. One, who I believe has left me forever… he   will be killed, of course… and one, who remains my most faithful servant, and   who has already reentered my service."   The answer to  speculates about who the three dead Death Eaters were.  We know who the last one is. I’m guessing one of the remaining two is Karkaroff. Is the other Snape? If so, which one? How can we know that all of the results for entangled photons are not chosen when the pair is created? The  claims that likelihood and probability are distinct concepts.     In non-technical parlance, "likelihood" is usually a synonym for "probability," but in statistical usage there is a clear distinction in perspective: the number that is the probability of some observed outcomes given a set of parameter values is regarded as the likelihood of the set of parameter values given the observed outcomes.    Can someone give a more down-to-earth description of what this means?  In addition, some examples of how "probability" and "likelihood" disagree would be nice. UITextField - capture return button event I came across this strange code snippet which compiles fine:  class Car {     public:     int speed; };  int main() {     int Car::*pSpeed = &amp;Car::speed;     return 0; }   Why does C++ have this pointer to a non-static data member of a class? What is the use of this strange pointer in real code? Time complexity of nested for-loop Potential difference across a zero resistance wire Derivation of E step in EM algorithm While im going through the derivation of E step in EM algorithm for pLSA, i came across the following derivation . Could anyone explain me how the following step is derived.   $\sum_z q(z) log \frac{P(X|z,\theta)P(z|\theta)}{q(z)}  = \sum_z q(z) log \frac{P(z|X,\theta)P(X,\theta)}{q(z)} $ Removing control chars (including console codes / colours) from script output I can use the "script" command to record an interactive session at the command line.  However, this includes all control characters and colour codes.  I can remove control characters (like backspace) with "col -b", but I can't find a simple way to remove the colour codes.  Note that I want to use the command line in the normal way, so don't want to disable colours there - I just want to remove them from the script output.  Also, I know can play around and try find a regexp to fix things up, but I am hoping there is a simpler (and more reliable - what if there's a code I don't know about when I develop the regexp?) solution.  To show the problem:   spl62 tmp: script Script started, file is typescript spl62 lepl: ls add-licence.sed  build-example.sh  commit-test         push-docs.sh add-licence.sh   build.sh          delete-licence.sed  setup.py asn              build-test.sh     delete-licence.sh   src build-doc.sh     clean             doc-src             test.ini spl62 lepl: exit Script done, file is typescript spl62 tmp: cat -v typescript Script started on Thu 09 Jun 2011 09:47:27 AM CLT spl62 lepl: ls^M ^[[0m^[[00madd-licence.sed^[[0m  ^[[00;32mbuild-example.sh^[[0m  ^[[00mcommit-test^[[0m         ^[[00;32mpush-docs.sh^[[0m^M ^[[00;32madd-licence.sh^[[0m   ^[[00;32mbuild.sh^[[0m          ^[[00mdelete-licence.sed^[[0m  ^[[00msetup.py^[[0m^M ^[[01;34masn^[[0m              ^[[00;32mbuild-test.sh^[[0m     ^[[00;32mdelete-licence.sh^[[0m   ^[[01;34msrc^[[0m^M ^[[00;32mbuild-doc.sh^[[0m     ^[[00;32mclean^[[0m             ^[[01;34mdoc-src^[[0m             ^[[00mtest.ini^[[0m^M spl62 lepl: exit^M  Script done on Thu 09 Jun 2011 09:47:29 AM CLT spl62 tmp: col -b &lt; typescript  Script started on Thu 09 Jun 2011 09:47:27 AM CLT spl62 lepl: ls 0m00madd-licence.sed0m  00;32mbuild-example.sh0m  00mcommit-test0m         00;32mpush-docs.sh0m 00;32madd-licence.sh0m   00;32mbuild.sh0m          00mdelete-licence.sed0m  00msetup.py0m 01;34masn0m              00;32mbuild-test.sh0m     00;32mdelete-licence.sh0m   01;34msrc0m 00;32mbuild-doc.sh0m     00;32mclean0m             01;34mdoc-src0m             00mtest.ini0m spl62 lepl: exit  Script done on Thu 09 Jun 2011 09:47:29 AM CLT Design for Facebook authentication in an iOS app that also accesses a secured web service Map a function across a list conditionally What is the difference between DPI (dots per inch) and PPI (pixels per inch)? There are lots of other questions on Graphic Design which partly cover this, e.g. .  However, I have become frustrated at the number of questions and answers which confuse the two terms. I think understanding the difference is important.  So here's a place to answer this question well and clear up the confusion! Intuition behind the definition of a measurable set Determinant of a rank $1$ update of a scalar matrix, or characteristic polynomial of a rank $1$ matrix