diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-11-28 17:57:53 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-11-28 17:57:53 +0000 |
commit | 2138f3c63f0ae1e5c5551fc99ab2b85bdc02d928 (patch) | |
tree | 2e5582caedc950c44e00e6a9e8cdfc6526bd819c | |
parent | 775b838f196a48df901daf89bafc3d7aeae4f539 (diff) | |
download | mpfr-2138f3c63f0ae1e5c5551fc99ab2b85bdc02d928.tar.gz |
Particular cases (NaN and signed zeros).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1586 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | minmax.c | 80 |
1 files changed, 48 insertions, 32 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 <stdio.h> #include "gmp.h" #include "gmp-impl.h" #include "mpfr.h" @@ -32,50 +31,67 @@ MA 02111-1307, USA. */ */ int -mpfr_min (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y ,mp_rnd_t rnd_mode) +mpfr_min (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) { - if (MPFR_IS_NAN(x) && MPFR_IS_NAN(y) ) + if (MPFR_IS_NAN(x) && MPFR_IS_NAN(y) ) { MPFR_SET_NAN(z); - return 1; + MPFR_RET_NAN; } - MPFR_CLEAR_NAN(z); - if (MPFR_IS_NAN(x) ) - return mpfr_set(z,y,rnd_mode); - - if (MPFR_IS_NAN(y) ) - return mpfr_set(z,x,rnd_mode); - - if(mpfr_cmp(x,y) <= 0) - return mpfr_set(z,x,rnd_mode); - else - return mpfr_set(z,y,rnd_mode); + MPFR_CLEAR_NAN(z); + + if (MPFR_IS_NAN(x)) + return mpfr_set(z, y, rnd_mode); + + if (MPFR_IS_NAN(y)) + return mpfr_set(z, x, rnd_mode); + + if (MPFR_IS_FP(x) && MPFR_IS_ZERO(x) && MPFR_IS_FP(y) && MPFR_IS_ZERO(y)) + { + if (MPFR_SIGN(x) < 0) + return mpfr_set(z, x, rnd_mode); + else + return mpfr_set(z, y, rnd_mode); + } + + if (mpfr_cmp(x,y) <= 0) + return mpfr_set(z, x, rnd_mode); + else + return mpfr_set(z, y, rnd_mode); } + /* The computation of z=max(x,y) z=x if x >= y z=y if x < y */ + int -mpfr_max (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y ,mp_rnd_t rnd_mode) +mpfr_max (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) { - if (MPFR_IS_NAN(x) && MPFR_IS_NAN(y) ) + if (MPFR_IS_NAN(x) && MPFR_IS_NAN(y) ) { - MPFR_SET_NAN(z); - return 1; + MPFR_SET_NAN(z); + MPFR_RET_NAN; } - MPFR_CLEAR_NAN(z); - - if (MPFR_IS_NAN(x) ) - return mpfr_set(z,y,rnd_mode); - - if (MPFR_IS_NAN(y) ) - return mpfr_set(z,x,rnd_mode); - - if(mpfr_cmp(x,y) <= 0) - return mpfr_set(z,y,rnd_mode); - else - return mpfr_set(z,x,rnd_mode); -} + MPFR_CLEAR_NAN(z); + + if (MPFR_IS_NAN(x)) + return mpfr_set(z, y, rnd_mode); + if (MPFR_IS_NAN(y)) + return mpfr_set(z, x, rnd_mode); + if (MPFR_IS_FP(x) && MPFR_IS_ZERO(x) && MPFR_IS_FP(y) && MPFR_IS_ZERO(y)) + { + if (MPFR_SIGN(x) < 0) + return mpfr_set(z, y, rnd_mode); + else + return mpfr_set(z, x, rnd_mode); + } + + if (mpfr_cmp(x,y) <= 0) + return mpfr_set(z, y, rnd_mode); + else + return mpfr_set(z, x, rnd_mode); +} |