Annotation of OpenXM_contrib/gmp/mpf/sqrt.c, Revision 1.1.1.2
1.1 maekawa 1: /* mpf_sqrt -- Compute the square root of a float.
2:
1.1.1.2 ! maekawa 3: Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc.
1.1 maekawa 4:
5: This file is part of the GNU MP Library.
6:
7: The GNU MP Library is free software; you can redistribute it and/or modify
1.1.1.2 ! maekawa 8: it under the terms of the GNU Lesser General Public License as published by
! 9: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1 maekawa 10: option) any later version.
11:
12: The GNU MP Library is distributed in the hope that it will be useful, but
13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1.1.1.2 ! maekawa 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 15: License for more details.
16:
1.1.1.2 ! maekawa 17: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 18: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20: MA 02111-1307, USA. */
21:
1.1.1.2 ! maekawa 22: #include <stdio.h> /* for NULL */
1.1 maekawa 23: #include "gmp.h"
24: #include "gmp-impl.h"
25:
26: void
27: #if __STDC__
28: mpf_sqrt (mpf_ptr r, mpf_srcptr u)
29: #else
30: mpf_sqrt (r, u)
31: mpf_ptr r;
32: mpf_srcptr u;
33: #endif
34: {
35: mp_size_t usize;
36: mp_ptr up, tp;
37: mp_size_t prec;
38: mp_exp_t tsize, rexp;
39: TMP_DECL (marker);
40:
41: usize = u->_mp_size;
42: if (usize <= 0)
43: {
1.1.1.2 ! maekawa 44: if (usize < 0)
! 45: SQRT_OF_NEGATIVE;
! 46: r->_mp_size = 0;
1.1 maekawa 47: r->_mp_exp = 0;
48: return;
49: }
50:
51: TMP_MARK (marker);
52:
53: prec = r->_mp_prec;
54: rexp = (u->_mp_exp + 1) >> 1; /* round towards -inf */
55: tsize = 2 * prec + (u->_mp_exp & 1);
56:
57: up = u->_mp_d;
58: tp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB);
59:
60: if (usize > tsize)
61: {
62: up += usize - tsize;
63: usize = tsize;
64: MPN_COPY (tp, up, tsize);
65: }
66: else
67: {
68: MPN_ZERO (tp, tsize - usize);
69: MPN_COPY (tp + (tsize - usize), up, usize);
70: }
71:
72: mpn_sqrtrem (r->_mp_d, NULL, tp, tsize);
73:
74: r->_mp_size = (tsize + 1) / 2;
75: r->_mp_exp = rexp;
76: TMP_FREE (marker);
77: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>