Commit c41993e8 by Steven G. Kargl Committed by Steven G. Kargl

trans-const.c (gfc_conv_mpfr_to_tree): Remove unneeded computation; simplify…

trans-const.c (gfc_conv_mpfr_to_tree): Remove unneeded computation; simplify logic; Add a gcc_assert.

* trans-const.c (gfc_conv_mpfr_to_tree): Remove unneeded computation;
  simplify logic; Add a gcc_assert.

From-SVN: r98587
parent eeab1ad2
2005-04-21 Steven G. Kargl <kargls@comcast.net>
* trans-const.c (gfc_conv_mpfr_to_tree): Remove unneeded computation;
simplify logic; Add a gcc_assert.
2005-04-19 Steven G. Kargl <kargls@comcast.net> 2005-04-19 Steven G. Kargl <kargls@comcast.net>
* trans-const.c (gfc_conv_mpz_to_tree): Fix comment. * trans-const.c (gfc_conv_mpz_to_tree): Fix comment.
......
...@@ -221,10 +221,8 @@ gfc_conv_mpfr_to_tree (mpfr_t f, int kind) ...@@ -221,10 +221,8 @@ gfc_conv_mpfr_to_tree (mpfr_t f, int kind)
tree res; tree res;
tree type; tree type;
mp_exp_t exp; mp_exp_t exp;
char *p; char *p, *q;
char *q;
int n; int n;
int edigits;
for (n = 0; gfc_real_kinds[n].kind != 0; n++) for (n = 0; gfc_real_kinds[n].kind != 0; n++)
{ {
...@@ -233,45 +231,20 @@ gfc_conv_mpfr_to_tree (mpfr_t f, int kind) ...@@ -233,45 +231,20 @@ gfc_conv_mpfr_to_tree (mpfr_t f, int kind)
} }
gcc_assert (gfc_real_kinds[n].kind); gcc_assert (gfc_real_kinds[n].kind);
n = MAX (abs (gfc_real_kinds[n].min_exponent), /* A decimal representation is used here, which requires the additional
abs (gfc_real_kinds[n].max_exponent)); two characters for rounding. TODO: Use a hexadecimal representation
to avoid rounding issues. */
p = mpfr_get_str (NULL, &exp, 10, gfc_real_kinds[n].precision+2,
f, GFC_RND_MODE);
gcc_assert (p);
edigits = 1; /* The additional 10 characters add space for the sprintf below. */
while (n > 0) q = (char *) gfc_getmem (strlen (p) + 10);
{
n = n / 10;
edigits += 3;
}
if (kind == gfc_default_double_kind)
p = mpfr_get_str (NULL, &exp, 10, 17, f, GFC_RND_MODE);
else
p = mpfr_get_str (NULL, &exp, 10, 8, f, GFC_RND_MODE);
/* 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] == '-') if (p[0] == '-')
{ sprintf (q, "-.%se%d", &p[1], (int) exp);
strcpy (&q[2], &p[1]);
q[0] = '-';
q[1] = '.';
}
else else
{ sprintf (q, ".%se%d", p, (int) exp);
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); type = gfc_get_real_type (kind);
res = build_real (type, REAL_VALUE_ATOF (q, TYPE_MODE (type))); res = build_real (type, REAL_VALUE_ATOF (q, TYPE_MODE (type)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment