diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-04-13 18:27:39 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-04-13 18:27:39 +0000 |
commit | 4a95597f6e43693f155a45688296b5c12f5c14c2 (patch) | |
tree | d42370c42d64e9b16dbe11b70ec0bc97db9a8742 | |
parent | 50d7203e4edc72d649da87a954603ae9f8a42f81 (diff) | |
download | mpfr-4a95597f6e43693f155a45688296b5c12f5c14c2.tar.gz |
Support for NaN and Inf (case insensitive) in mpfr_set_str. Tests.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1869 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | acinclude.m4 | 2 | ||||
-rw-r--r-- | set_str.c | 30 | ||||
-rw-r--r-- | strcasecmp.c | 81 | ||||
-rw-r--r-- | tests/tset_str.c | 27 |
5 files changed, 140 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index 75d5ba182..8ab8021b6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,13 +7,11 @@ lib_LIBRARIES = libmpfr.a libmpfr_a_SOURCES = cputime.h mpfr.h mpf2mpfr.h mpfi.h mpfr-impl.h mpfr-math.h mpfr-test.h exceptions.c save_expo.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_one_ulp.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_ui.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp2.c exp3.c exp.c get_d.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c out_str.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c random2.c random.c reldiff.c rnd_mode.c round_prec.c set.c set_d.c set_dfl_prec.c set_rnd.c set_f.c set_prc_raw.c set_prec.c set_q.c set_si.c set_str.c set_str_raw.c set_ui.c set_z.c sqrt.c sqrt_ui.c sub.c sub1.c sub_one_ulp.c sub_ui.c rint.c ui_div.c ui_sub.c urandomb.c get_z_exp.c swap.c factorial.c cosh.c sinh.c tanh.c acosh.c asinh.c atanh.c atan.c cmp2.c exp_2.c asin.c const_euler.c cos.c sin.c tan.c fma.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c copysign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c +libmpfr_a_LIBADD = @LIBOBJS@ + info_TEXINFOS = mpfr.texi DISTCLEANFILES = mpfr.info tests: cd tests ; make tests - - - - diff --git a/acinclude.m4 b/acinclude.m4 index 95f9456de..5c94fcb4f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -53,6 +53,8 @@ case $OS_TYPE in ;; esac +AC_REPLACE_FUNCS(strcasecmp) + dnl Check for IEEE-754 switches on Alpha if test "$MACHTYPE" = "alpha"; then saved_CFLAGS="$CFLAGS" @@ -24,6 +24,13 @@ MA 02111-1307, USA. */ #include <stdlib.h> #include <limits.h> #include <errno.h> + +#ifdef HAVE_STRCASECMP +#include <string.h> +#else +int strcasecmp (const char *, const char *); +#endif + #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" @@ -44,13 +51,32 @@ mpfr_set_str (mpfr_ptr x, __gmp_const char *str, int base, mp_rnd_t rnd_mode) if (base < 2 || base > 36) return 1; - mpz_init(mantissa); - mpz_set_ui(mantissa, 0); + if (strcasecmp(str, "NaN") == 0) + { + MPFR_SET_NAN(x); + /* MPFR_RET_NAN not used as the return value isn't a ternary value */ + __mpfr_flags |= MPFR_FLAGS_NAN; + return 0; + } negative = *str == '-'; if (negative || *str == '+') str++; + if (strcasecmp(str, "Inf") == 0) + { + MPFR_CLEAR_NAN(x); + MPFR_SET_INF(x); + if (negative) + MPFR_SET_NEG(x); + else + MPFR_SET_POS(x); + return 0; + } + + mpz_init(mantissa); + mpz_set_ui(mantissa, 0); + while (*str == '0') str++; /* skip initial zeros */ diff --git a/strcasecmp.c b/strcasecmp.c new file mode 100644 index 000000000..c090b8677 --- /dev/null +++ b/strcasecmp.c @@ -0,0 +1,81 @@ +/* Copyright (C) 1991, 1992, 1995, 2002 Free Software Foundation, Inc. +This file was part of the GNU C Library. Modified by kb@mail.tug.org to +avoid glibc-isms. Modified by Vincent Lefevre (-> ISO C prototypes). + +This file is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +This file is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this file; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#if !defined (__STDC__) || !__STDC__ +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +#ifndef const +#define const +#endif +#endif + +#include <ctype.h> + +int strcasecmp (const char *, const char *); +int strncasecmp (const char *, const char *, size_t); + +/* Compare S1 and S2, ignoring case, returning less than, equal to or + greater than zero if S1 is lexiographically less than, + equal to or greater than S2. */ +int +strcasecmp (const char *s1, const char *s2) +{ + register const unsigned char *p1 = (const unsigned char *) s1; + register const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2) + return 0; + + do + { + c1 = tolower (*p1++); + c2 = tolower (*p2++); + if (c1 == '\0') + break; + } + while (c1 == c2); + + return c1 - c2; +} + +int +strncasecmp (const char *s1, const char *s2, size_t n) +{ + register const unsigned char *p1 = (const unsigned char *) s1; + register const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2 || n == 0) + return 0; + + do + { + c1 = tolower (*p1++); + c2 = tolower (*p2++); + if (c1 == '\0' || c1 != c2) + return c1 - c2; + } while (--n > 0); + + return c1 - c2; +} diff --git a/tests/tset_str.c b/tests/tset_str.c index 75c595a34..da59e5d37 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -163,6 +163,33 @@ main (int argc, char *argv[]) free (str); } + if (mpfr_set_str (x, "NaN", 10, GMP_RNDN) != 0 || !mpfr_nan_p(x)) + { + fprintf (stderr, "mpfr_set_str failed on NaN\n"); + exit (1); + } + + if (mpfr_set_str (x, "Inf", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || + MPFR_SIGN(x) < 0) + { + fprintf (stderr, "mpfr_set_str failed on Inf\n"); + exit (1); + } + + if (mpfr_set_str (x, "-Inf", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || + MPFR_SIGN(x) > 0) + { + fprintf (stderr, "mpfr_set_str failed on -Inf\n"); + exit (1); + } + + if (mpfr_set_str (x, "+Inf", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || + MPFR_SIGN(x) < 0) + { + fprintf (stderr, "mpfr_set_str failed on +Inf\n"); + exit (1); + } + mpfr_clear (x); mpfr_clear (y); |