question about mpf_mul_ui

ppmsn2005 ppmsn2005 at gmail.com
Mon Feb 22 11:21:51 CET 2010


hi all
    i had wrote some simple code, i found mpf lost data.

  code like this

        mpf_t   t6, t7, t8,t9 ;  
 
        mpf_init(t6);
        mpf_init(t7);
        mpf_init(t8);
        mpf_init(t9);



        mpf_set_str(t6,"6378137", 10);
        mpf_set_str(t7,"3.1415926", 10);

        mpf_mul(t8, t6, t7);
        gmp_printf("1 result:  %40.25Ff\n", t8);
        mpf_set(t6, t8);
        gmp_printf("2 result:  %40.25Ff\n", t6);
        //mpf_set_str(t9,"2", 10);
        //mpf_mul(t8, t6, t9);
        mpf_mul_ui(t8, t8, 2);
        gmp_printf("3 result:  %40.25Ff\n", t8);


but the result is

1 result:        20037508.0009862000000000000000000
2 result:        20037508.0009862000000000000000000
3 result:        40075016.0019723999999000000000000

i think 3 result is wrong , it should be 40075016.001972400000000000000. if i use double type. i also can get 
the right result. so how can i fix this bug? thanks

2010-02-22 



ppmsn2005 


More information about the gmp-discuss mailing list