From 8a7ab67d53367e71edb43970889b2a463a2354a1 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Mon, 21 Jan 2002 10:26:13 +0000 Subject: Bug fixes: * return 1 -> MPFR_RET_NAN * a MPFR_CLEAR_INF was missing. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1663 280ebfd0-de03-0410-8827-d642c229c3f4 --- sqrt.c | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'sqrt.c') diff --git a/sqrt.c b/sqrt.c index 1bd36d220..5caf0c2cf 100644 --- a/sqrt.c +++ b/sqrt.c @@ -1,6 +1,6 @@ /* mpfr_sqrt -- square root of a floating-point number -Copyright (C) 1999, 2001 Free Software Foundation, Inc. +Copyright (C) 1999-2002 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -19,8 +19,6 @@ 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 -#include #include "gmp.h" #include "gmp-impl.h" #include "mpfr.h" @@ -42,35 +40,40 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode) char can_round = 0; TMP_DECL(marker0); { - TMP_DECL (marker); + TMP_DECL (marker); - if (MPFR_IS_NAN(u)) { - MPFR_SET_NAN(r); - return 1; /* NaN is always inexact */ - } + if (MPFR_IS_NAN(u)) + { + MPFR_SET_NAN(r); + MPFR_RET_NAN; + } - if (MPFR_SIGN(u) < 0) { - if (MPFR_IS_INF(u) || MPFR_NOTZERO(u)) { - MPFR_SET_NAN(r); - return 1; /* NaN is always inexact */ - } - else { /* sqrt(-0) = -0 */ - MPFR_SET_ZERO(r); - if (MPFR_SIGN(r) > 0) MPFR_CHANGE_SIGN(r); - return 0; /* zero is exact */ - } - } + if (MPFR_SIGN(u) < 0) + { + if (MPFR_IS_INF(u) || MPFR_NOTZERO(u)) + { + MPFR_SET_NAN(r); + MPFR_RET_NAN; + } + else + { /* sqrt(-0) = -0 */ + MPFR_CLEAR_INF(r); + MPFR_SET_ZERO(r); + MPFR_SET_NEG(r); + MPFR_RET(0); + } + } - MPFR_CLEAR_NAN(r); + MPFR_CLEAR_NAN(r); + MPFR_SET_POS(r); - if (MPFR_SIGN(r) < 0) MPFR_CHANGE_SIGN(r); - if (MPFR_IS_INF(u)) - { - MPFR_SET_INF(r); - return 0; /* infinity is exact */ - } + if (MPFR_IS_INF(u)) + { + MPFR_SET_INF(r); + MPFR_RET(0); + } - MPFR_CLEAR_INF(r); + MPFR_CLEAR_INF(r); prec = MPFR_PREC(r); -- cgit v1.2.1