xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/cmp_str.c (revision ba125506a622fe649968631a56eba5d42ff57863)
1efee5258Smrg /* mpfr_cmp_str -- compare a floating-point number with a string.
2efee5258Smrg 
3*ba125506Smrg Copyright 2004-2023 Free Software Foundation, Inc.
4efdec83bSmrg Contributed by the AriC and Caramba projects, INRIA.
5efee5258Smrg 
6efee5258Smrg This file is part of the GNU MPFR Library.
7efee5258Smrg 
8efee5258Smrg The GNU MPFR Library is free software; you can redistribute it and/or modify
9efee5258Smrg it under the terms of the GNU Lesser General Public License as published by
10efee5258Smrg the Free Software Foundation; either version 3 of the License, or (at your
11efee5258Smrg option) any later version.
12efee5258Smrg 
13efee5258Smrg The GNU MPFR Library is distributed in the hope that it will be useful, but
14efee5258Smrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15efee5258Smrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16efee5258Smrg License for more details.
17efee5258Smrg 
18efee5258Smrg You should have received a copy of the GNU Lesser General Public License
19efee5258Smrg along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
202ba2404bSmrg https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21efee5258Smrg 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22efee5258Smrg 
23efee5258Smrg #include "mpfr-test.h"
24efee5258Smrg 
25efee5258Smrg int
mpfr_cmp_str(mpfr_srcptr x,const char * s,int base,mpfr_rnd_t rnd)26efee5258Smrg mpfr_cmp_str (mpfr_srcptr x, const char *s, int base, mpfr_rnd_t rnd)
27efee5258Smrg {
28efee5258Smrg   mpfr_t y;
29efee5258Smrg   int res;
30efee5258Smrg 
31efee5258Smrg   MPFR_ASSERTN (!MPFR_IS_NAN (x));
32efee5258Smrg   mpfr_init2 (y, MPFR_PREC(x));
33efee5258Smrg   mpfr_set_str (y, s, base, rnd);
34*ba125506Smrg   MPFR_ASSERTN (!MPFR_IS_NAN (y));
35efee5258Smrg   res = mpfr_cmp (x, y);
36efee5258Smrg   mpfr_clear (y);
37efee5258Smrg   return res;
38efee5258Smrg }
39