Newbie question

jmonetti at uncu.edu.ar jmonetti at uncu.edu.ar
Mon Jun 8 15:00:11 CEST 2009


Hello,

I'm trying gmd and have a simple question.  I've the following
c code


...
    v2 = A[0][1] * ((2-h)/(2+h))   + A[1][1] * (2+h);
...

The matrix elements, 'v2' and 'h' are "doubles".
I need more precision when calculating this equation, so
started trying gmp.

The problem I found is that cannot express the equation
in a single line with gmp.  Is it right ?
With succesive 'adds' and 'muls' I calculated in the following
form

//        ------------------------6-------------------
//        -----------5-----------
//                   -----3------     -------4--------
//                   --1--  --2--               --2--
//   v2 = A[0][1] * ((2-h)/(2+h))   + A[1][1] * (2+h);

Simplified GMP CODE
-------------------
...
        mpf_set_ui(  A[0][0] , 1);
        mpf_set_ui(  A[0][1] , 1);
        mpf_set_ui(  A[1][0] , 1);
        mpf_set_ui(  A[1][1] , 1);
        mpf_init(h );
        mpf_init(v1 );
        mpf_init(v2 );
        mpf_init(delta );
        mpf_init(menosuno );
        mpf_init(uno );
        mpf_init(dos );
        mpf_init(tres );
        mpf_init(aux1 );
        mpf_init(aux2 );
        mpf_init(aux3 );
        mpf_init(aux4 );
        mpf_init(aux5 );
        mpf_init(aux6 );

        mpf_set_ui( h        , 1);
        mpf_set_ui( delta    , 2);
        mpf_set_ui( menosuno , 1);
        mpf_set_ui( uno      , 1);
        mpf_set_ui( dos      , 2);
        mpf_set_ui( tres     , 3);

        while(  mpf_cmp(v2, tres)   ) {
          mpf_mul(aux1, A[0][0],  menosuno);
          mpf_mul(aux2, A[0][1], dos);
          mpf_add(v1, aux1,aux2  );

          mpf_sub(aux1, dos, h) ;
          mpf_add(aux2, dos, h) ;
          mpf_div(aux3, aux1, aux2) ;
          mpf_mul(aux4, A[1][1], aux2) ;
          mpf_mul(aux5, A[0][1], aux3) ;
          mpf_add(aux6, aux5 , aux4) ;
...

I found my simple equation grows in complexity!  :)
I'm doing a correct use of the library or missing something?
So, can I do the work in a single line with gmp ?

Julio



More information about the gmp-discuss mailing list