diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2009-09-14 09:29:55 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2009-09-14 09:29:55 +0000 |
commit | b1f0db5a06da43609d68678ea313ff79eb8a3cec (patch) | |
tree | 4d1f66e37bac8dc6d14166ca97bd29d5477148c5 | |
parent | 1ba2beefb5baff0d6faf34573d94d8a43f6e7302 (diff) | |
download | mpfr-b1f0db5a06da43609d68678ea313ff79eb8a3cec.tar.gz |
[isregular.c] new function mpfr_regular_p
[iszero.c] fixed typo in comment
[tests/tisnan.c] added tests for mpfr_regular_p
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@6417 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | isregular.c | 29 | ||||
-rw-r--r-- | iszero.c | 2 | ||||
-rw-r--r-- | mpfr.h | 1 | ||||
-rw-r--r-- | mpfr.texi | 4 | ||||
-rw-r--r-- | tests/tisnan.c | 69 |
6 files changed, 97 insertions, 10 deletions
diff --git a/Makefile.am b/Makefile.am index a4c893e60..31382b1e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ include_HEADERS = mpfr.h mpf2mpfr.h lib_LTLIBRARIES = libmpfr.la -libmpfr_la_SOURCES = mpfr.h mpf2mpfr.h mpfr-gmp.h mpfr-impl.h mpfr-longlong.h mpfr-thread.h exceptions.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_si.c cmp_ui.c comparisons.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp10.c exp2.c exp3.c exp.c frac.c get_d.c get_exp.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c modf.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.c out_str.c printf.c vasprintf.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c reldiff.c round_prec.c set.c setmax.c setmin.c set_d.c set_dfl_prec.c set_exp.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_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 sinh_cosh.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 fms.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c signbit.c copysign.c setsign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c set_zero.c powerof2.c gamma.c set_ld.c get_ld.c cbrt.c volatile.c fits_s.h fits_sshort.c fits_sint.c fits_slong.c fits_u.h fits_ushort.c fits_uint.c fits_ulong.c fits_uintmax.c fits_intmax.c get_si.c get_ui.c zeta.c cmp_d.c erf.c inits.c inits2.c clears.c sgn.c check.c sub1sp.c version.c mpn_exp.c mpfr-gmp.c mp_clz_tab.c sum.c add1sp.c free_cache.c si_op.c cmp_ld.c set_ui_2exp.c set_si_2exp.c set_uj.c set_sj.c get_sj.c get_uj.c get_z.c iszero.c cache.c sqr.c int_ceil_log2.c isqrt.c strtofr.c pow_z.c logging.c mulders.c get_f.c round_p.c erfc.c atan2.c subnormal.c const_catalan.c root.c gen_inverse.h sec.c csc.c cot.c eint.c sech.c csch.c coth.c round_near_x.c constant.c abort_prec_max.c stack_interface.c lngamma.c zeta_ui.c set_d64.c get_d64.c jn.c yn.c rem1.c get_patches.c add_d.c sub_d.c d_sub.c mul_d.c div_d.c d_div.c li2.c rec_sqrt.c min_prec.c buildopt.c digamma.c bernoulli.c +libmpfr_la_SOURCES = mpfr.h mpf2mpfr.h mpfr-gmp.h mpfr-impl.h mpfr-longlong.h mpfr-thread.h exceptions.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_si.c cmp_ui.c comparisons.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp10.c exp2.c exp3.c exp.c frac.c get_d.c get_exp.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c modf.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.c out_str.c printf.c vasprintf.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c reldiff.c round_prec.c set.c setmax.c setmin.c set_d.c set_dfl_prec.c set_exp.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_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 sinh_cosh.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 fms.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c signbit.c copysign.c setsign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c set_zero.c powerof2.c gamma.c set_ld.c get_ld.c cbrt.c volatile.c fits_s.h fits_sshort.c fits_sint.c fits_slong.c fits_u.h fits_ushort.c fits_uint.c fits_ulong.c fits_uintmax.c fits_intmax.c get_si.c get_ui.c zeta.c cmp_d.c erf.c inits.c inits2.c clears.c sgn.c check.c sub1sp.c version.c mpn_exp.c mpfr-gmp.c mp_clz_tab.c sum.c add1sp.c free_cache.c si_op.c cmp_ld.c set_ui_2exp.c set_si_2exp.c set_uj.c set_sj.c get_sj.c get_uj.c get_z.c iszero.c cache.c sqr.c int_ceil_log2.c isqrt.c strtofr.c pow_z.c logging.c mulders.c get_f.c round_p.c erfc.c atan2.c subnormal.c const_catalan.c root.c gen_inverse.h sec.c csc.c cot.c eint.c sech.c csch.c coth.c round_near_x.c constant.c abort_prec_max.c stack_interface.c lngamma.c zeta_ui.c set_d64.c get_d64.c jn.c yn.c rem1.c get_patches.c add_d.c sub_d.c d_sub.c mul_d.c div_d.c d_div.c li2.c rec_sqrt.c min_prec.c buildopt.c digamma.c bernoulli.c isregular.c libmpfr_la_LIBADD = @LIBOBJS@ diff --git a/isregular.c b/isregular.c new file mode 100644 index 000000000..7feaa7c9a --- /dev/null +++ b/isregular.c @@ -0,0 +1,29 @@ +/* mpfr_regular_p -- check for regular number (neither NaN, Inf or zero) + +Copyright 2009 Free Software Foundation, Inc. +Contributed by the Arenaire and Cacao projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFR Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFR Library 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 Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "mpfr-impl.h" + +int +(mpfr_regular_p) (mpfr_srcptr x) +{ + return MPFR_IS_SINGULAR(x) == 0; +} @@ -1,4 +1,4 @@ -/* mpfr_zero_p -- check for infinities +/* mpfr_zero_p -- check for zero Copyright 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Contributed by the Arenaire and Cacao projects, INRIA. @@ -573,6 +573,7 @@ __MPFR_DECLSPEC int mpfr_inf_p _MPFR_PROTO((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_number_p _MPFR_PROTO((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_integer_p _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_zero_p _MPFR_PROTO ((mpfr_srcptr)); +__MPFR_DECLSPEC int mpfr_regular_p _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_greater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_greaterequal_p _MPFR_PROTO ((mpfr_srcptr, @@ -1591,8 +1591,10 @@ If one of the operands is NaN, set the @emph{erange} flag and return zero. @deftypefunx int mpfr_inf_p (mpfr_t @var{op}) @deftypefunx int mpfr_number_p (mpfr_t @var{op}) @deftypefunx int mpfr_zero_p (mpfr_t @var{op}) +@deftypefunx int mpfr_regular_p (mpfr_t @var{op}) Return non-zero if @var{op} is respectively NaN, an infinity, an ordinary -number (i.e.@: neither NaN nor an infinity) or zero. Return zero otherwise. +number (i.e.@: neither NaN nor an infinity), zero, or a regular number +(i.e.@: neither NaN, nor an infinity nor zero). Return zero otherwise. @end deftypefun @deftypefn Macro int mpfr_sgn (mpfr_t @var{op}) diff --git a/tests/tisnan.c b/tests/tisnan.c index 978525930..b80550c93 100644 --- a/tests/tisnan.c +++ b/tests/tisnan.c @@ -1,4 +1,5 @@ -/* Test file for mpfr_nan_p, mpfr_inf_p and mpfr_number_p. +/* Test file for mpfr_nan_p, mpfr_inf_p, mpfr_number_p, mpfr_zero_p and + mpfr_regular_p. Copyright 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Contributed by the Arenaire and Cacao projects, INRIA. @@ -57,6 +58,11 @@ main (void) printf ("Error: mpfr_zero_p(+Inf) gives non-zero\n"); exit (1); } + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) + { + printf ("Error: mpfr_regular_p(+Inf) gives non-zero\n"); + exit (1); + } /* same for -Inf */ mpfr_neg (x, x, MPFR_RNDN); @@ -80,6 +86,11 @@ main (void) printf ("Error: mpfr_zero_p(-Inf) gives non-zero\n"); exit (1); } + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) + { + printf ("Error: mpfr_regular_p(-Inf) gives non-zero\n"); + exit (1); + } /* same for NaN */ mpfr_sub (x, x, x, MPFR_RNDN); @@ -103,8 +114,13 @@ main (void) printf ("Error: mpfr_number_p(NaN) gives non-zero\n"); exit (1); } + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) + { + printf ("Error: mpfr_regular_p(NaN) gives non-zero\n"); + exit (1); + } - /* same for an ordinary number */ + /* same for a regular number */ mpfr_set_ui (x, 1, MPFR_RNDN); if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) { @@ -126,27 +142,66 @@ main (void) printf ("Error: mpfr_zero_p(1) gives non-zero\n"); exit (1); } + if (mpfr_regular_p (x) == 0 || (mpfr_regular_p) (x) == 0) + { + printf ("Error: mpfr_regular_p(1) gives zero\n"); + exit (1); + } - /* Same for 0 */ + /* Same for +0 */ mpfr_set_ui (x, 0, MPFR_RNDN); if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) { - printf ("Error: mpfr_nan_p(0) gives non-zero\n"); + printf ("Error: mpfr_nan_p(+0) gives non-zero\n"); exit (1); } if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) { - printf ("Error: mpfr_inf_p(0) gives non-zero\n"); + printf ("Error: mpfr_inf_p(+0) gives non-zero\n"); exit (1); } if (mpfr_number_p (x) == 0) { - printf ("Error: mpfr_number_p(0) gives zero\n"); + printf ("Error: mpfr_number_p(+0) gives zero\n"); exit (1); } if (mpfr_zero_p (x) == 0 ) { - printf ("Error: mpfr_zero_p(0) gives zero\n"); + printf ("Error: mpfr_zero_p(+0) gives zero\n"); + exit (1); + } + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) + { + printf ("Error: mpfr_regular_p(+0) gives non-zero\n"); + exit (1); + } + + /* Same for -0 */ + mpfr_set_ui (x, 0, MPFR_RNDN); + mpfr_neg (x, x, MPFR_RNDN); + if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) + { + printf ("Error: mpfr_nan_p(-0) gives non-zero\n"); + exit (1); + } + if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) + { + printf ("Error: mpfr_inf_p(-0) gives non-zero\n"); + exit (1); + } + if (mpfr_number_p (x) == 0) + { + printf ("Error: mpfr_number_p(-0) gives zero\n"); + exit (1); + } + if (mpfr_zero_p (x) == 0 ) + { + printf ("Error: mpfr_zero_p(-0) gives zero\n"); + exit (1); + } + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) + { + printf ("Error: mpfr_regular_p(-0) gives non-zero\n"); exit (1); } |