my first code using GMP!

Pranav Jawale pranavshriram at gmail.com
Thu May 31 12:27:32 CEST 2012


Hi,

And this works too!

// this works
gmp_printf("\n number is %.*Ff with %d digits", totalDigits , mpfNumber,
totalDigits);

I thought there has to be one argument per % in the printf statement. But
this one works differently and takes 2 arguments for %.*.

Regards,
Pranav

On Thu, May 31, 2012 at 3:47 PM, Pranav Jawale <pranavshriram at gmail.com>wrote:

> Hello,
>
> Yes, my code had a problem with exponent, and I had fixed it(but didn't
> post). Please look at below code wrt gmp_printf where it's giving me seg
> fault. I tried variation of the example given in manual and also Marco's
> both lines (first of them doesn't work)
>
> ------------------------ code --------------------------------
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <gmp.h>
> #include <string.h>
>
> int main ()
> {
>   mpf_t mpfNumber;
>   int totalDigits = 10;
>   mpf_init(mpfNumber);
>   double d = 1.0003;
>   mpf_set_d(mpfNumber,d);
>
>   // this gives seg fault (same as in manual, except * replaced with 10)
>   //gmp_printf ("fixed point mpf %.10Ff with %d digits\n", totalDigits,
> mpfNumber, totalDigits);
>
>   // this gives seg fault
>   //gmp_printf ("\n%%.*FE, with %d digits, gives: %.10FE\n",
> totalDigits,totalDigits, mpfNumber);
>
>   //this gives seg fault
>   //gmp_printf ("\n%%.10FE, with %d digits, gives: %.10Ff\n",
> totalDigits,totalDigits, mpfNumber);
>
>   //this gives seg fault
>   //gmp_printf ("\n%%.10Ff, with %d digits, gives: %.10Ff\n", mpfNumber,
> totalDigits, mpfNumber);
>
>   // this works
>   gmp_printf("\n number is %.10Ff with %d digits", mpfNumber, totalDigits);
>
>   mpf_clear(mpfNumber);
>   printf("\n");
>   return 0;
>
> }
>
>
> On Thu, May 31, 2012 at 12:23 PM, <bodrato at mail.dm.unipi.it> wrote:
>
>> Ciao Pranav,
>>
>> Il Mer, 30 Maggio 2012 8:53 pm, Pranav Jawale ha scritto:
>> > Earlier I tried to use gmp_printf, but it was giving seg fault.
>>
>> Maybe your code was not ready yet :-)
>>
>> > I think this line
>> > gmp_printf ("fixed point mpf %.*Ff with %d digits\n", n, f, n);
>> > is not working properly
>>
>> I tried to insert the two lines below in your code, they work smoothly.
>>
>>  gmp_printf ("\n%%.*FE, with %d digits, gives: %.*FE\n", totalDigits,
>> totalDigits, ans);
>>  gmp_printf ("\nfixed point mpf %.*Ff with %d digits\n", totalDigits,
>> ans, totalDigits);
>>
>> m
>>
>> --
>> http://bodrato.it/software/combinatorics.html
>>
>>
>
>
> --
> *
> *
> The best way to get something done is to begin.  ~Author Unknown
>
>
>


-- 
*
*
The best way to get something done is to begin.  ~Author Unknown


More information about the gmp-discuss mailing list