[BACK]Return to cmp.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpfr

Annotation of OpenXM_contrib/gmp/mpfr/cmp.c, Revision 1.1.1.2

1.1       maekawa     1: /* mpfr_cmp -- compare two floating-point numbers
                      2:
1.1.1.2 ! ohara       3: Copyright 1999, 2001 Free Software Foundation.
1.1       maekawa     4:
                      5: This file is part of the MPFR Library.
                      6:
                      7: The MPFR Library is free software; you can redistribute it and/or modify
1.1.1.2 ! ohara       8: it under the terms of the GNU Lesser General Public License as published by
        !             9: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1       maekawa    10: option) any later version.
                     11:
                     12: The MPFR Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1.1.1.2 ! ohara      14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
1.1       maekawa    15: License for more details.
                     16:
1.1.1.2 ! ohara      17: You should have received a copy of the GNU Lesser General Public License
1.1       maekawa    18: along with the MPFR Library; see the file COPYING.LIB.  If not, write to
                     19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     20: MA 02111-1307, USA. */
                     21:
                     22: #include "gmp.h"
                     23: #include "gmp-impl.h"
                     24: #include "mpfr.h"
1.1.1.2 ! ohara      25: #include "mpfr-impl.h"
1.1       maekawa    26:
1.1.1.2 ! ohara      27: /* returns 0 iff b = sign(s) * c
        !            28:            a positive value iff b > sign(s) * c
        !            29:            a negative value iff b < sign(s) * c
1.1       maekawa    30: */
                     31:
1.1.1.2 ! ohara      32: int
        !            33: mpfr_cmp3 (mpfr_srcptr b, mpfr_srcptr c, int s)
1.1       maekawa    34: {
1.1.1.2 ! ohara      35:   mp_exp_t be, ce;
        !            36:   mp_size_t bn, cn;
        !            37:   mp_limb_t *bp, *cp;
1.1       maekawa    38:
1.1.1.2 ! ohara      39:   MPFR_ASSERTN(!MPFR_IS_NAN(b));
        !            40:   MPFR_ASSERTN(!MPFR_IS_NAN(c));
        !            41:   s *= MPFR_SIGN(c);
1.1       maekawa    42:
1.1.1.2 ! ohara      43:   if (MPFR_IS_INF(b))
        !            44:     return (MPFR_IS_INF(c) && s * MPFR_SIGN(b) > 0) ? 0 : MPFR_SIGN(b);
1.1       maekawa    45:
1.1.1.2 ! ohara      46:   if (MPFR_IS_INF(c))
        !            47:     return -s;
1.1       maekawa    48:
1.1.1.2 ! ohara      49:   /* b and c are real numbers */
1.1       maekawa    50:
1.1.1.2 ! ohara      51:   if (MPFR_IS_ZERO(b))
        !            52:     return MPFR_IS_ZERO(c) ? 0 : -s;
        !            53:
        !            54:   if (MPFR_IS_ZERO(c))
        !            55:     return MPFR_SIGN(b);
        !            56:
        !            57:   if (s * MPFR_SIGN(b) < 0)
        !            58:     return MPFR_SIGN(b);
        !            59:
        !            60:   /* now signs are equal */
        !            61:
        !            62:   be = MPFR_EXP(b);
        !            63:   ce = MPFR_EXP(c);
        !            64:   if (be > ce)
        !            65:     return s;
        !            66:   if (be < ce)
        !            67:     return -s;
1.1       maekawa    68:
1.1.1.2 ! ohara      69:   /* both signs and exponents are equal */
        !            70:
        !            71:   bn = (MPFR_PREC(b)-1)/BITS_PER_MP_LIMB;
        !            72:   cn = (MPFR_PREC(c)-1)/BITS_PER_MP_LIMB;
        !            73:
        !            74:   bp = MPFR_MANT(b);
        !            75:   cp = MPFR_MANT(c);
        !            76:
        !            77:   for ( ; bn >= 0 && cn >= 0; bn--, cn--)
        !            78:     {
        !            79:       if (bp[bn] > cp[cn])
        !            80:         return s;
        !            81:       if (bp[bn] < cp[cn])
        !            82:         return -s;
1.1       maekawa    83:     }
                     84:
1.1.1.2 ! ohara      85:   for ( ; bn >= 0; bn--)
        !            86:     if (bp[bn])
        !            87:       return s;
        !            88:
        !            89:   for ( ; cn >= 0; cn--)
        !            90:     if (cp[cn])
        !            91:       return -s;
1.1       maekawa    92:
1.1.1.2 ! ohara      93:    return 0;
1.1       maekawa    94: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>