Hi,


   1. Can you tell me the arithmetic's theory (douchuan)



hi
   I don't know what does the arithmetic say!
   The result from a is 1000, then the result from b is 6.
   I have optimized a system for a long time, but i find out i must
optimize all aspects, just a aspect isn't work.
   I want to know arithmetic's theory.


   a.
        long endPoints = (1000 + 1000 + 1000 + 1000 + 1000) / 5;
        if(endPoints > 6208L)
            endPoints = 6208L;
        long halfEndPoints = endPoints / 2L;
        long l2 = endPoints - halfEndPoints;
        long l3 = 1L;
        l3 = 1000L*1000L*1000L*1000L*1000L;

        f(l3 != 0L)
            while(halfEndPoints > 0L)
            {
                if(l2 * l2 * l2 * l2 * l2 > l3)
                    endPoints = l2;
                else
                    halfEndPoints /= 2L;
                l2 = endPoints - halfEndPoints;
            }
        else
            endPoints = 0L;

        System.out.println("endPoints: " + endPoints);



        result :  1000


     The long type takes 64bits ,about 10^19 . Therefore there's no
overflow.
     I could see a  limit arithmetic computation from this program:
      Assume  endpoints = a ; halfendpoints = a/(2^n) (n -> Infinite)
     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.

b.

               long endPoints = (6000 + 1 + 1 + 1 + 1) / 5;
        if(endPoints > 6208L)
            endPoints = 6208L;
        long halfEndPoints = endPoints / 2L;
        long l2 = endPoints - halfEndPoints;
        long l3 = 1L;
        l3 = 6000L*1L*1L*1L*1L;

        f(l3 != 0L)
            while(halfEndPoints > 0L)
            {
                if(l2 * l2 * l2 * l2 * l2 > l3)
                    endPoints = l2;
                else
                    halfEndPoints /= 2L;
                l2 = endPoints - halfEndPoints;
            }
        else
            endPoints = 0L;

        System.out.println("endPoints: " + endPoints);



        result : 6


 Similiar to the first program:
 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.
        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).
        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.
      Sorry, I could not describe this process clearly enough.  This
program result might vary when the hardware rounding algorithm varies.


 This is my view towards your questions.pls tell me if I made some
mistakes. thanks.

Cheers
Sakur
_______________________________________________
kaffe mailing list
[email protected]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to