aboutsummaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorBrooks Moses <brooks.moses@codesourcery.com>2007-04-25 02:12:47 +0000
committerBrooks Moses <brooks@gcc.gnu.org>2007-04-24 19:12:47 -0700
commit205a4d09cae7765310f0a6ae45d4fbde41af1571 (patch)
treedb634c5069c7518a31fd69e68bc5446671f7df2a /gcc/real.c
parentdf80379db8bcba55301b23d560e42a98e9e79130 (diff)
downloadgcc-205a4d09cae7765310f0a6ae45d4fbde41af1571.zip
gcc-205a4d09cae7765310f0a6ae45d4fbde41af1571.tar.gz
gcc-205a4d09cae7765310f0a6ae45d4fbde41af1571.tar.bz2
real.c (mpfr_from_real): Handle Inf and NaN, and allow the rounding mode to be specified by the caller.
* real.c (mpfr_from_real): Handle Inf and NaN, and allow the rounding mode to be specified by the caller. (real_to_mpfr) Likewise. * real.h: Update mpfr_from_real, mpfr_to_real prototypes to include new arguments. * builtins.c: Update mpfr_from_real, mpfr_to_real calls. From-SVN: r124139
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/gcc/real.c b/gcc/real.c
index 2e28818..48d9e9e 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -4991,29 +4991,58 @@ real_copysign (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *x)
for initializing and clearing the MPFR parameter. */
void
-mpfr_from_real (mpfr_ptr m, const REAL_VALUE_TYPE *r)
+mpfr_from_real (mpfr_ptr m, const REAL_VALUE_TYPE *r, mp_rnd_t rndmode)
{
/* We use a string as an intermediate type. */
char buf[128];
int ret;
+ /* Take care of Infinity and NaN. */
+ if (r->cl == rvc_inf)
+ {
+ mpfr_set_inf (m, r->sign);
+ return;
+ }
+
+ if (r->cl == rvc_nan)
+ {
+ mpfr_set_nan (m);
+ return;
+ }
+
real_to_hexadecimal (buf, r, sizeof (buf), 0, 1);
/* mpfr_set_str() parses hexadecimal floats from strings in the same
format that GCC will output them. Nothing extra is needed. */
- ret = mpfr_set_str (m, buf, 16, GMP_RNDN);
+ ret = mpfr_set_str (m, buf, 16, rndmode);
gcc_assert (ret == 0);
}
-/* Convert from MPFR to REAL_VALUE_TYPE. */
+/* Convert from MPFR to REAL_VALUE_TYPE, for a given type TYPE and rounding
+ mode RNDMODE. TYPE is only relevant if M is a NaN. */
void
-real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m)
+real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, tree type, mp_rnd_t rndmode)
{
/* We use a string as an intermediate type. */
char buf[128], *rstr;
mp_exp_t exp;
- rstr = mpfr_get_str (NULL, &exp, 16, 0, m, GMP_RNDN);
+ /* Take care of Infinity and NaN. */
+ if (mpfr_inf_p (m))
+ {
+ real_inf (r);
+ if (mpfr_sgn (m) < 0)
+ *r = REAL_VALUE_NEGATE (*r);
+ return;
+ }
+
+ if (mpfr_nan_p (m))
+ {
+ real_nan (r, "", 1, TYPE_MODE (type));
+ return;
+ }
+
+ rstr = mpfr_get_str (NULL, &exp, 16, 0, m, rndmode);
/* The additional 12 chars add space for the sprintf below. This
leaves 6 digits for the exponent which is supposedly enough. */