Home | History | Annotate | Line # | Download | only in mpf
      1      1.1  mrg /* mpf_cmp_d -- compare mpf and double.
      2      1.1  mrg 
      3      1.1  mrg Copyright 2001, 2003 Free Software Foundation, Inc.
      4      1.1  mrg 
      5      1.1  mrg This file is part of the GNU MP Library.
      6      1.1  mrg 
      7      1.1  mrg The GNU MP Library is free software; you can redistribute it and/or modify
      8  1.1.1.2  mrg it under the terms of either:
      9  1.1.1.2  mrg 
     10  1.1.1.2  mrg   * the GNU Lesser General Public License as published by the Free
     11  1.1.1.2  mrg     Software Foundation; either version 3 of the License, or (at your
     12  1.1.1.2  mrg     option) any later version.
     13  1.1.1.2  mrg 
     14  1.1.1.2  mrg or
     15  1.1.1.2  mrg 
     16  1.1.1.2  mrg   * the GNU General Public License as published by the Free Software
     17  1.1.1.2  mrg     Foundation; either version 2 of the License, or (at your option) any
     18  1.1.1.2  mrg     later version.
     19  1.1.1.2  mrg 
     20  1.1.1.2  mrg or both in parallel, as here.
     21      1.1  mrg 
     22      1.1  mrg The GNU MP Library is distributed in the hope that it will be useful, but
     23      1.1  mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     24  1.1.1.2  mrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     25  1.1.1.2  mrg for more details.
     26      1.1  mrg 
     27  1.1.1.2  mrg You should have received copies of the GNU General Public License and the
     28  1.1.1.2  mrg GNU Lesser General Public License along with the GNU MP Library.  If not,
     29  1.1.1.2  mrg see https://www.gnu.org/licenses/.  */
     30      1.1  mrg 
     31      1.1  mrg #include "config.h"
     32      1.1  mrg 
     33      1.1  mrg #if HAVE_FLOAT_H
     34      1.1  mrg #include <float.h>  /* for DBL_MAX */
     35      1.1  mrg #endif
     36      1.1  mrg 
     37      1.1  mrg #include "gmp-impl.h"
     38      1.1  mrg 
     39      1.1  mrg int
     40      1.1  mrg mpf_cmp_d (mpf_srcptr f, double d)
     41      1.1  mrg {
     42      1.1  mrg   mp_limb_t  darray[LIMBS_PER_DOUBLE];
     43      1.1  mrg   mpf_t      df;
     44      1.1  mrg 
     45      1.1  mrg   /* d=NaN has no sensible return value, so raise an exception.
     46      1.1  mrg      d=Inf or -Inf is always bigger than z.  */
     47      1.1  mrg   DOUBLE_NAN_INF_ACTION (d,
     48      1.1  mrg                          __gmp_invalid_operation (),
     49      1.1  mrg                          return (d < 0.0 ? 1 : -1));
     50      1.1  mrg 
     51      1.1  mrg   if (d == 0.0)
     52      1.1  mrg     return SIZ(f);
     53      1.1  mrg 
     54      1.1  mrg   PTR(df) = darray;
     55      1.1  mrg   SIZ(df) = (d >= 0.0 ? LIMBS_PER_DOUBLE : -LIMBS_PER_DOUBLE);
     56      1.1  mrg   EXP(df) = __gmp_extract_double (darray, ABS(d));
     57      1.1  mrg 
     58      1.1  mrg   return mpf_cmp (f, df);
     59      1.1  mrg }
     60