diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-12-21 17:08:38 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-12-21 17:08:38 +0000 |
commit | c74d024d1bfb5cffbd9cf27664f824bb4087dda8 (patch) | |
tree | 5785612341cfeeaab51d555c975ec973b480292a /sqrt.c | |
parent | 783f93b38a3d8264f81fb1b303c11c9e9cd9c27e (diff) | |
download | mpfr-c74d024d1bfb5cffbd9cf27664f824bb4087dda8.tar.gz |
k2r -> ansi style
removed #include <math.h> 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
Diffstat (limited to 'sqrt.c')
-rw-r--r-- | sqrt.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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 <math.h> #include <stdio.h> #include <stdlib.h> #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); |