<br>Hi, <br> <br><div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br> 1. Can you tell me the arithmetic's theory (douchuan)
<br><br><br><br>hi<br> I don't know what does the arithmetic say!<br> The result from a is 1000, then the result from b is 6.<br> I have optimized a system for a long time, but i find out i must<br>optimize all aspects, just a aspect isn't work.
<br> I want to know arithmetic's theory.<br><br><br> a.<br> long endPoints = (1000 + 1000 + 1000 + 1000 + 1000) / 5;<br> if(endPoints > 6208L)<br> endPoints = 6208L;<br> long halfEndPoints = endPoints / 2L;
<br> long l2 = endPoints - halfEndPoints;<br> long l3 = 1L;<br> l3 = 1000L*1000L*1000L*1000L*1000L;<br><br> f(l3 != 0L)<br> while(halfEndPoints > 0L)<br> {<br> if(l2 * l2 * l2 * l2 * l2 > l3)
<br> endPoints = l2;<br> else<br> halfEndPoints /= 2L;<br> l2 = endPoints - halfEndPoints;<br> }<br> else<br> endPoints = 0L;
<br><br> System.out.println("endPoints: " + endPoints);<br><br><br><br> result : 1000</blockquote><div><br> The long type takes 64bits ,about 10^19 . Therefore there's no overflow.<br> I could see a limit arithmetic computation from this program:
<br> Assume endpoints = a ; halfendpoints = a/(2^n) (n -> Infinite)<br> Obvious,from the arithmetic view, halfendpoints would be evalued as lim halfendpoints (n->Infinite). Then the arithmetic hardware might finally compute halfendpoints as 0 (divition computation is somehow platform dependent) . Therefore ,endPoints would be 1000.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> b.<br><br> long endPoints = (6000 + 1 + 1 + 1 + 1) / 5;<br> if(endPoints > 6208L)
<br> endPoints = 6208L;<br> long halfEndPoints = endPoints / 2L;<br> long l2 = endPoints - halfEndPoints;<br> long l3 = 1L;<br> l3 = 6000L*1L*1L*1L*1L;<br><br> f(l3 != 0L)<br>
while(halfEndPoints > 0L)<br> {<br> if(l2 * l2 * l2 * l2 * l2 > l3)<br> endPoints = l2;<br> else<br> halfEndPoints /= 2L;<br>
l2 = endPoints - halfEndPoints;<br> }<br> else<br> endPoints = 0L;<br><br> System.out.println("endPoints: " + endPoints);<br><br><br><br> result : 6</blockquote>
<div><br> Similiar to the first program:<br> Assume endPoints = a , halfEndPoints = a/(2^n) (n->Infinite),in the previous program,endPoints keeps invariable,here in this case,both endPoints and halfEndPoints are variable.
<br> We can easily get the boudary value of l2 for "if(l2 * l2 * l2 * l2 * l2 > l3)" ,x^5 > l3 , the minimum value for x is 6. (5^5 < 6000,6^5 > 6000).<br> That means the program result would be no more than 6. Meaningwhile ,in the loop body,l2 = a - a/(2^n) (n->Infinite, a = l2 | l2^5>l3). Through some analysis of the loop itself,we could find the endpoint "a " would be decoupled every two loop turn. So let a = v/2^t (t is the turn counts,v is our initial endpoints ,600). l2 = v/2^t - (v/2^t) / (2^n) ( l2 <= 6 is our desired result). Now we could compute 600/2^t - (600/2^t)/(2^n) <= 6. Since n tends to be infinite,we now get 600/2^t <= 6. We could know the t value. Therefore,finally, the l2 value is 6, and then endPoints is 6, then we get the result 6.
<br> Sorry, I could not describe this process clearly enough. This program result might vary when the hardware rounding algorithm varies. <br> <br> <br> This is my view towards your questions.pls tell me if I made some mistakes. thanks.
<br><br>Cheers<br>Sakur<br></div></div><br>