From c74d024d1bfb5cffbd9cf27664f824bb4087dda8 Mon Sep 17 00:00:00 2001 From: zimmerma Date: Thu, 21 Dec 2000 17:08:38 +0000 Subject: k2r -> ansi style removed #include by defining auxiliary functions fixed several tiny remaining bugs with NaN/Inf git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@925 280ebfd0-de03-0410-8827-d642c229c3f4 --- sqrt.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'sqrt.c') diff --git a/sqrt.c b/sqrt.c index f8d24291f..19d0f14b1 100644 --- a/sqrt.c +++ b/sqrt.c @@ -19,7 +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 #include "gmp.h" @@ -50,19 +49,33 @@ mpfr_sqrt (r, u, rnd_mode) char can_round = 0; TMP_DECL (marker); TMP_DECL(marker0); - if (MPFR_IS_NAN(u) || MPFR_SIGN(u) == -1) { + if (MPFR_IS_NAN(u)) { MPFR_SET_NAN(r); return 1; } - if (MPFR_SIGN(r) != 1) { MPFR_CHANGE_SIGN(r); } + if (MPFR_SIGN(u) < 0) { + if (MPFR_IS_INF(u) || MPFR_NOTZERO(u)) { + MPFR_SET_NAN(r); + return 1; + } + else { /* sqrt(-0) = -0 */ + MPFR_SET_ZERO(r); + if (MPFR_SIGN(r) > 0) MPFR_CHANGE_SIGN(r); + return 0; + } + } + + MPFR_CLEAR_NAN(r); + + if (MPFR_SIGN(r) < 0) MPFR_CHANGE_SIGN(r); if (MPFR_IS_INF(u)) { MPFR_SET_INF(r); return 1; } - MPFR_CLEAR_FLAGS (r); + MPFR_CLEAR_INF(r); prec = MPFR_PREC(r); -- cgit v1.2.1