summaryrefslogtreecommitdiff
path: root/sqrt.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-01-21 10:26:13 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-01-21 10:26:13 +0000
commit8a7ab67d53367e71edb43970889b2a463a2354a1 (patch)
tree6e41ead9085ab331d11b0d15a4cca53e57de2cda /sqrt.c
parent95eb0cf93a326dfb74927ab8e10c5956186a2ab5 (diff)
downloadmpfr-8a7ab67d53367e71edb43970889b2a463a2354a1.tar.gz
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
Diffstat (limited to 'sqrt.c')
-rw-r--r--sqrt.c57
1 files changed, 30 insertions, 27 deletions
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 <stdio.h>
-#include <stdlib.h>
#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);