summaryrefslogtreecommitdiff
path: root/src/rint.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-07-20 15:59:51 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-07-20 15:59:51 +0000
commite0263aed74458d29a8b976cd1491c3bd8641baa4 (patch)
tree5d85422c525a3f981beba00494cfa4e34ae55daa /src/rint.c
parent1bca62e60e0b443e310b7633ee96dc92d49c6bfd (diff)
downloadmpfr-e0263aed74458d29a8b976cd1491c3bd8641baa4.tar.gz
Added mpfr_rint_roundeven and mpfr_roundeven functions, with
documentation and tests. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9629 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/rint.c')
-rw-r--r--src/rint.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/rint.c b/src/rint.c
index ed0494ff5..5969d8853 100644
--- a/src/rint.c
+++ b/src/rint.c
@@ -304,6 +304,14 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mpfr_rnd_t rnd_mode)
} /* exp > 0, |u| >= 1 */
}
+#undef mpfr_roundeven
+
+int
+mpfr_roundeven (mpfr_ptr r, mpfr_srcptr u)
+{
+ return mpfr_rint (r, u, MPFR_RNDN);
+}
+
#undef mpfr_round
int
@@ -341,6 +349,32 @@ mpfr_floor (mpfr_ptr r, mpfr_srcptr u)
* the inexact flag when the argument is not an integer.
*/
+#undef mpfr_rint_roundeven
+
+int
+mpfr_rint_roundeven (mpfr_ptr r, mpfr_srcptr u, mpfr_rnd_t rnd_mode)
+{
+ if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(u) ) || mpfr_integer_p (u))
+ return mpfr_set (r, u, rnd_mode);
+ else
+ {
+ mpfr_t tmp;
+ int inex;
+ mpfr_flags_t saved_flags = __gmpfr_flags;
+ MPFR_BLOCK_DECL (flags);
+
+ mpfr_init2 (tmp, MPFR_PREC (u));
+ /* round(u) is representable in tmp unless an overflow occurs */
+ MPFR_BLOCK (flags, mpfr_roundeven (tmp, u));
+ __gmpfr_flags = saved_flags;
+ inex = (MPFR_OVERFLOW (flags)
+ ? mpfr_overflow (r, rnd_mode, MPFR_SIGN (u))
+ : mpfr_set (r, tmp, rnd_mode));
+ mpfr_clear (tmp);
+ return inex;
+ }
+}
+
#undef mpfr_rint_round
int