summaryrefslogtreecommitdiff
path: root/mul_2ui.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2001-11-29 03:15:54 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2001-11-29 03:15:54 +0000
commitfe300a2ce7710555c22cda56bffe6905ec1f2d5d (patch)
tree5b64726e9977a59b7450738256361d443313d9c8 /mul_2ui.c
parent2138f3c63f0ae1e5c5551fc99ab2b85bdc02d928 (diff)
downloadmpfr-fe300a2ce7710555c22cda56bffe6905ec1f2d5d.tar.gz
Functions mpfr_{mul,div}_2{si,ui} added.
Functions mpfr_{mul,div}_2exp still exist for backward compatibility; they are obsolete and should not be used any longer. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1587 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'mul_2ui.c')
-rw-r--r--mul_2ui.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/mul_2ui.c b/mul_2ui.c
new file mode 100644
index 000000000..64ac7c7ae
--- /dev/null
+++ b/mul_2ui.c
@@ -0,0 +1,59 @@
+/* mpfr_mul_2ui -- multiply a floating-point number by a power of two
+
+Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+
+This file is part of the MPFR Library.
+
+The MPFR Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPFR Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPFR Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "mpfr.h"
+#include "mpfr-impl.h"
+
+int
+mpfr_mul_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int n, mp_rnd_t rnd_mode)
+{
+ int inexact;
+
+ inexact = y != x ? mpfr_set (y, x, rnd_mode) : 0;
+
+ if (MPFR_IS_FP(y) && MPFR_NOTZERO(y))
+ {
+ /* n will have to be casted to long to make sure that the addition
+ and subtraction below (for overflow detection) are signed */
+ while (n > LONG_MAX)
+ {
+ int inex2;
+
+ n -= LONG_MAX;
+ inex2 = mpfr_mul_2ui(y, y, LONG_MAX, rnd_mode);
+ if (inex2)
+ return inex2; /* overflow */
+ }
+
+ /* MPFR_EMIN_MIN + (long) n is signed and doesn't lead to an overflow;
+ the first test useful so that the real test can't lead to an
+ overflow. */
+ if (__mpfr_emax < MPFR_EMIN_MIN + (long) n ||
+ MPFR_EXP(y) > __mpfr_emax - (long) n)
+ return mpfr_set_overflow (y, rnd_mode, MPFR_SIGN(y));
+
+ MPFR_EXP(y) += (long) n;
+ }
+
+ return inexact;
+}