xref: /netbsd/external/lgpl3/gmp/dist/mpf/cmp_d.c (revision 671ea119)
14a1767b4Smrg /* mpf_cmp_d -- compare mpf and double.
24a1767b4Smrg 
34a1767b4Smrg Copyright 2001, 2003 Free Software Foundation, Inc.
44a1767b4Smrg 
54a1767b4Smrg This file is part of the GNU MP Library.
64a1767b4Smrg 
74a1767b4Smrg The GNU MP Library is free software; you can redistribute it and/or modify
8*f81b1c5bSmrg it under the terms of either:
9*f81b1c5bSmrg 
10*f81b1c5bSmrg   * the GNU Lesser General Public License as published by the Free
11*f81b1c5bSmrg     Software Foundation; either version 3 of the License, or (at your
124a1767b4Smrg     option) any later version.
134a1767b4Smrg 
14*f81b1c5bSmrg or
15*f81b1c5bSmrg 
16*f81b1c5bSmrg   * the GNU General Public License as published by the Free Software
17*f81b1c5bSmrg     Foundation; either version 2 of the License, or (at your option) any
18*f81b1c5bSmrg     later version.
19*f81b1c5bSmrg 
20*f81b1c5bSmrg or both in parallel, as here.
21*f81b1c5bSmrg 
224a1767b4Smrg The GNU MP Library is distributed in the hope that it will be useful, but
234a1767b4Smrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24*f81b1c5bSmrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25*f81b1c5bSmrg for more details.
264a1767b4Smrg 
27*f81b1c5bSmrg You should have received copies of the GNU General Public License and the
28*f81b1c5bSmrg GNU Lesser General Public License along with the GNU MP Library.  If not,
29*f81b1c5bSmrg see https://www.gnu.org/licenses/.  */
304a1767b4Smrg 
314a1767b4Smrg #include "config.h"
324a1767b4Smrg 
334a1767b4Smrg #if HAVE_FLOAT_H
344a1767b4Smrg #include <float.h>  /* for DBL_MAX */
354a1767b4Smrg #endif
364a1767b4Smrg 
374a1767b4Smrg #include "gmp-impl.h"
384a1767b4Smrg 
394a1767b4Smrg int
mpf_cmp_d(mpf_srcptr f,double d)404a1767b4Smrg mpf_cmp_d (mpf_srcptr f, double d)
414a1767b4Smrg {
424a1767b4Smrg   mp_limb_t  darray[LIMBS_PER_DOUBLE];
434a1767b4Smrg   mpf_t      df;
444a1767b4Smrg 
454a1767b4Smrg   /* d=NaN has no sensible return value, so raise an exception.
464a1767b4Smrg      d=Inf or -Inf is always bigger than z.  */
474a1767b4Smrg   DOUBLE_NAN_INF_ACTION (d,
484a1767b4Smrg                          __gmp_invalid_operation (),
494a1767b4Smrg                          return (d < 0.0 ? 1 : -1));
504a1767b4Smrg 
514a1767b4Smrg   if (d == 0.0)
524a1767b4Smrg     return SIZ(f);
534a1767b4Smrg 
544a1767b4Smrg   PTR(df) = darray;
554a1767b4Smrg   SIZ(df) = (d >= 0.0 ? LIMBS_PER_DOUBLE : -LIMBS_PER_DOUBLE);
564a1767b4Smrg   EXP(df) = __gmp_extract_double (darray, ABS(d));
574a1767b4Smrg 
584a1767b4Smrg   return mpf_cmp (f, df);
594a1767b4Smrg }
60