bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mpf_get_str trouble


From: Torbjorn Granlund
Subject: Re: mpf_get_str trouble
Date: 17 Dec 2002 18:25:22 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

"Cesar Delgado" <address@hidden> writes:

  I sent this email to the users mailing list and was told to send it
  here.  If a better description of the problem is needed please don't
  hesitate in contacting me and I will try to supply the needed
  information.
   
  #include <stdio.h>
  #include <gmp.h>
   
  int main() {
   
          mpf_t number ;
          mp_exp_t exponent ;
          char *word ;
   
          mpf_init(number) ;
          mpf_init(one) ;
   
          mpf_set_ui(number, 1) ;
          mpf_div_ui(number, number, 5) ;
          mpf_pow_ui(number, number, 365) ;
          mpf_div_ui(number, number, 365) ;
   
          gmp_printf("%1.*Ff\n", 450, number) ;
          word = mpf_get_str(NULL, &exponent, 10, 0, number) ;
          printf("exponent = %li\n", (long int)exponent) ;
  }
   
  I get:
   
  0.0000000000000000000000000000000000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  000000000020589962369524017340100000000000000000000000000000000000000000
  000000000000000000000000000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000000000000
  exponent = -257
   
Please apply the patch below and tell me if things now work as
expected.  This bug has such serious implications that it will
trigger a new patch release, GMP 4.1.2.

This patch fixes the problem with too many leading zeros.  It
looks odd to me that the number ends with many zeros, but perhaps
gmp_printf is defined to pad with zeros rather than develop
semi-spurious digits.

Index: printf/printffuns.c
===================================================================
RCS file: /home/cvsfiles/gmp/printf/printffuns.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -c -1 -r1.3 -r1.4
*** printf/printffuns.c 24 Jul 2001 23:41:52 -0000      1.3
--- printf/printffuns.c 17 Dec 2002 16:57:56 -0000      1.4
***************
*** 61,65 ****
    memset (buf, c, MIN (reps, sizeof (buf)));
!   for (i = reps; i > 0; i -= piece)
      {
!       piece = MIN (reps, sizeof (buf));
        ret = fwrite (buf, 1, piece, fp);
--- 61,65 ----
    memset (buf, c, MIN (reps, sizeof (buf)));
!   for (i = reps; i > 0; i -= sizeof (buf))
      {
!       piece = MIN (i, sizeof (buf));
        ret = fwrite (buf, 1, piece, fp);

-- 
Torbjörn



reply via email to

[Prev in Thread] Current Thread [Next in Thread]