summaryrefslogtreecommitdiff
path: root/sqrt_ui.c
diff options
context:
space:
mode:
authorZhang Qiang <qiang.z.zhang@intel.com>2012-05-19 16:03:26 +0800
committerZhang Qiang <qiang.z.zhang@intel.com>2012-05-19 16:03:26 +0800
commitd7d4544895c1a12c160a7fd8454e5edf6fc4cc21 (patch)
tree1c6f3945d71b436ff34589526a2863d37c83c4ad /sqrt_ui.c
parent0713f18c74a4f5e9b85ac69459bff2c931dfa6da (diff)
downloadmpfr-d7d4544895c1a12c160a7fd8454e5edf6fc4cc21.tar.gz
mpfr-d7d4544895c1a12c160a7fd8454e5edf6fc4cc21.tar.bz2
mpfr-d7d4544895c1a12c160a7fd8454e5edf6fc4cc21.zip
Sync code from obs
Diffstat (limited to 'sqrt_ui.c')
-rw-r--r--sqrt_ui.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/sqrt_ui.c b/sqrt_ui.c
new file mode 100644
index 0000000..502273e
--- /dev/null
+++ b/sqrt_ui.c
@@ -0,0 +1,54 @@
+/* mpfr_sqrt_ui -- square root of a machine integer
+
+Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+Contributed by the Arenaire and Cacao projects, INRIA.
+
+This file is part of the GNU MPFR Library.
+
+The GNU 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 3 of the License, or (at your
+option) any later version.
+
+The GNU 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 GNU MPFR Library; see the file COPYING.LESSER. If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#define MPFR_NEED_LONGLONG_H
+#include "mpfr-impl.h"
+
+int
+mpfr_sqrt_ui (mpfr_ptr r, unsigned long u, mpfr_rnd_t rnd_mode)
+{
+ if (u)
+ {
+ mpfr_t uu;
+ mp_limb_t up[1];
+ unsigned long cnt;
+ int inex;
+ MPFR_SAVE_EXPO_DECL (expo);
+
+ MPFR_TMP_INIT1 (up, uu, GMP_NUMB_BITS);
+ MPFR_ASSERTN (u == (mp_limb_t) u);
+ count_leading_zeros (cnt, (mp_limb_t) u);
+ *up = (mp_limb_t) u << cnt;
+
+ MPFR_SAVE_EXPO_MARK (expo);
+ MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
+ inex = mpfr_sqrt(r, uu, rnd_mode);
+ MPFR_SAVE_EXPO_FREE (expo);
+ return mpfr_check_range(r, inex, rnd_mode);
+ }
+ else /* sqrt(0) = 0 */
+ {
+ MPFR_SET_ZERO(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0);
+ }
+}