This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [fortran,patch] Patch for PR 14394 - Precision of real type.


Sorry, the patch is attached here.

 --- Feng Wang <wf_cs@yahoo.com> 的正文:> Hi, all
>   This patch fix PR 14394. Reported by Bud. Test case:


_________________________________________________________
Do You Yahoo!? 
完全免费的雅虎电邮,马上注册获赠额外60兆网络存储空间
http://cn.rd.yahoo.com/mail_cn/tag/?http://cn.mail.yahoo.com
*** /home/wf/0303/fortran/trans-const.c	Wed Mar  3 16:30:59 2004
--- trans-const.c	Tue Mar  9 15:04:37 2004
*************** gfc_conv_mpf_to_tree (mpf_t f, int kind)
*** 221,230 ****
    tree res;
    tree type;
    mp_exp_t exp;
-   char buff[128];
    char *p;
    int n;
-   int digits;
    int edigits;
  
    for (n = 0; gfc_real_kinds[n].kind != 0; n++)
--- 221,229 ----
    tree res;
    tree type;
    mp_exp_t exp;
    char *p;
+   char *q;
    int n;
    int edigits;
  
    for (n = 0; gfc_real_kinds[n].kind != 0; n++)
*************** gfc_conv_mpf_to_tree (mpf_t f, int kind)
*** 234,240 ****
      }
    assert (gfc_real_kinds[n].kind);
  
-   digits = gfc_real_kinds[n].precision + 1;
    assert (gfc_real_kinds[n].radix == 2);
  
    n = MAX (abs (gfc_real_kinds[n].min_exponent),
--- 233,238 ----
*************** gfc_conv_mpf_to_tree (mpf_t f, int kind)
*** 249,286 ****
        edigits += 3;
      }
  
-   /* We also have two minus signs, "e", "." and a null terminator.  */
-   if (digits + edigits + 5 > 128)
-     p = (char *) gfc_getmem (digits + edigits + 5);
-   else
-     p = buff;
  
!   mpf_get_str (&p[1], &exp, 10, digits, f);
!   if (p[1])
      {
!       if (p[1] == '-')
  	{
! 	  p[0] = '-';
! 	  p[1] = '.';
  	}
        else
  	{
! 	  p[0] = '.';
  	}
!       strcat (p, "e");
!       sprintf (&p[strlen (p)], "%d", (int) exp);
      }
    else
      {
!       strcpy (p, "0");
      }
  
    type = gfc_get_real_type (kind);
!   res = build_real (type, REAL_VALUE_ATOF (p, TYPE_MODE (type)));
!   if (p != buff)
!     gfc_free (p);
  
!   return (res);
  }
  
  
--- 247,285 ----
        edigits += 3;
      }
  
  
!   p = mpf_get_str (NULL, &exp, 10, 0, f);
! 
!   /* We also have one minus sign, "e", "." and a null terminator.  */
!   q = (char *) gfc_getmem (strlen (p) + edigits + 4);
! 
!   if (p[0])
      {
!       if (p[0] == '-')
  	{
! 	  strcpy (&q[2], &p[1]);
! 	  q[0] = '-';
! 	  q[1] = '.';
  	}
        else
  	{
! 	  strcpy (&q[1], p);
! 	  q[0] = '.';
  	}
!       strcat (q, "e");
!       sprintf (&q[strlen (q)], "%d", (int) exp);
      }
    else
      {
!       strcpy (q, "0");
      }
  
    type = gfc_get_real_type (kind);
!   res = build_real (type, REAL_VALUE_ATOF (q, TYPE_MODE (type)));
!   gfc_free (q);
!   gfc_free (p);
  
!   return res;
  }
  
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]