summaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorbrooks <brooks@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-25 02:12:47 +0000
committerbrooks <brooks@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-25 02:12:47 +0000
commit66fa16e6fb446fa09bb0c07485552b09552196b8 (patch)
treedb634c5069c7518a31fd69e68bc5446671f7df2a /gcc/real.c
parent950348eb8111dade20e7fed9ca72b205fa15d1a6 (diff)
downloadgcc-66fa16e6fb446fa09bb0c07485552b09552196b8.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@124139 138bc75d-0d04-0410-961f-82ee72b054a4
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 2e288187b77..48d9e9e23fa 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. */