summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-04-20 09:32:20 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-04-20 09:32:20 +0000
commit97724b73df1ca86917d114df64da54152cdfef5e (patch)
treea659ff4f04469673cc9af66b0fe3dbb6fd4e4759
parent2b1f5a024237b70c0bde10a682d67ec279479f91 (diff)
downloadmpfr-97724b73df1ca86917d114df64da54152cdfef5e.tar.gz
Add mpfr_zero_p.
Add macros for mpfr_inf_p, mpfr_nan_p and mpfr_zero_p. Add macro for mpfr_sgn. Update doc. Add new tests. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2871 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--Makefile.am2
-rw-r--r--isinf.c4
-rw-r--r--isnan.c3
-rw-r--r--mpfr.h21
-rw-r--r--mpfr.texi7
-rw-r--r--sgn.c8
-rw-r--r--tests/tisnan.c61
-rw-r--r--tests/tsgn.c6
8 files changed, 76 insertions, 36 deletions
diff --git a/Makefile.am b/Makefile.am
index 43bb6b3a2..57bd0f6dd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@ include_HEADERS = mpfr.h mpf2mpfr.h
lib_LIBRARIES = libmpfr.a
-libmpfr_a_SOURCES = mpfr.h mpf2mpfr.h mpfr-impl.h mpfr-test.h log_b2.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_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 mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.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 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_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 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 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_z.c
+libmpfr_a_SOURCES = mpfr.h mpf2mpfr.h mpfr-impl.h mpfr-test.h log_b2.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_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 mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.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 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_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 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 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_z.c iszero.c
libmpfr_a_LIBADD = @LIBOBJS@
diff --git a/isinf.c b/isinf.c
index 41b75034e..176bf2b0c 100644
--- a/isinf.c
+++ b/isinf.c
@@ -22,7 +22,7 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
int
-mpfr_inf_p (mpfr_srcptr x)
+(mpfr_inf_p) (mpfr_srcptr x)
{
- return !MPFR_IS_NAN(x) && MPFR_IS_INF(x);
+ return MPFR_IS_INF(x);
}
diff --git a/isnan.c b/isnan.c
index 486a4bfe1..26c5ccb4f 100644
--- a/isnan.c
+++ b/isnan.c
@@ -19,11 +19,10 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-
#include "mpfr-impl.h"
int
-mpfr_nan_p (mpfr_srcptr x)
+(mpfr_nan_p) (mpfr_srcptr x)
{
return MPFR_IS_NAN (x);
}
diff --git a/mpfr.h b/mpfr.h
index 031fec56d..0a6f7a04f 100644
--- a/mpfr.h
+++ b/mpfr.h
@@ -213,10 +213,10 @@ int mpfr_copysign _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
int mpfr_neg _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
#ifdef _MPFR_H_HAVE_INTMAX_T
-#define mpfr_set_sj mpfr_set_sj_internal
-#define mpfr_set_sj_2exp mpfr_set_sj_2exp_internal
-#define mpfr_set_uj mpfr_set_uj_internal
-#define mpfr_set_uj_2exp mpfr_set_uj_2exp_internal
+#define mpfr_set_sj __gmpfr_set_sj
+#define mpfr_set_sj_2exp __gmpfr_set_sj_2exp
+#define mpfr_set_uj __gmpfr_set_uj
+#define mpfr_set_uj_2exp __gmpfr_set_uj_2exp
int mpfr_set_sj _MPFR_PROTO ((mpfr_t, intmax_t, mpfr_rnd_t));
int mpfr_set_sj_2exp _MPFR_PROTO ((mpfr_t, intmax_t, intmax_t, mpfr_rnd_t));
int mpfr_set_uj _MPFR_PROTO ((mpfr_t, uintmax_t, mpfr_rnd_t));
@@ -232,7 +232,7 @@ long mpfr_get_si _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
unsigned long mpfr_get_ui _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
char* mpfr_get_str _MPFR_PROTO ((char *, mp_exp_t *, int, size_t, mpfr_srcptr,
mpfr_rnd_t));
-void mpz_set_fr _MPFR_PROTO ((mpz_ptr z, mpfr_srcptr f, mp_rnd_t rnd));
+void mpz_set_fr _MPFR_PROTO ((mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd));
void mpfr_free_str _MPFR_PROTO ((char *str));
@@ -248,8 +248,8 @@ int mpfr_add_one_ulp _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
int mpfr_sub_one_ulp _MPFR_PROTO((mpfr_ptr, mpfr_rnd_t));
#ifdef _MPFR_H_HAVE_FILE
-#define mpfr_inp_str mpfr_inp_str_internal
-#define mpfr_out_str mpfr_out_str_internal
+#define mpfr_inp_str __gmpfr_inp_str
+#define mpfr_out_str __gmpfr_out_str
size_t mpfr_inp_str _MPFR_PROTO ((mpfr_ptr, FILE *, int, mpfr_rnd_t));
size_t mpfr_out_str _MPFR_PROTO ((FILE *, int, size_t, mpfr_srcptr, mpfr_rnd_t));
#endif
@@ -348,6 +348,8 @@ int mpfr_nan_p _MPFR_PROTO((mpfr_srcptr));
int mpfr_inf_p _MPFR_PROTO((mpfr_srcptr));
int mpfr_number_p _MPFR_PROTO((mpfr_srcptr));
int mpfr_integer_p _MPFR_PROTO ((mpfr_srcptr));
+int mpfr_zero_p _MPFR_PROTO ((mpfr_srcptr));
+ /* int mpfr_one_p _MPFR_PROTO ((mpfr_srcptr x));*/
int mpfr_greater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
int mpfr_greaterequal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
@@ -421,6 +423,11 @@ int mpfr_sum _MPFR_PROTO ((mpfr_ptr ret, mpfr_ptr const tab[], unsigned long n,
mp_limb_t __gmpfr_local_tab_##_x[((_p)-1)/GMP_NUMB_BITS+1]; \
mpfr_t _x = {{(_p),1,__MPFR_EXP_NAN,__gmpfr_local_tab_##_x}}
+#define mpfr_nan_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_NAN)
+#define mpfr_inf_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_INF)
+#define mpfr_zero_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_ZERO)
+#define mpfr_sgn(_x) (mpfr_zero_p(_x) ? 0 : MPFR_SIGN(_x))
+
/* Compatibility with 2.0.1
'mpfr_round_prec' is used to detect 2.0.1 and 2.0.2 */
#define mpfr_cmp_abs mpfr_cmpabs
diff --git a/mpfr.texi b/mpfr.texi
index fd9c12a80..9b49f19c1 100644
--- a/mpfr.texi
+++ b/mpfr.texi
@@ -1075,9 +1075,10 @@ make much sense.
@deftypefun int mpfr_nan_p (mpfr_t @var{op})
@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})
Return non-zero if @var{op} is respectively Not-a-Number (NaN),
an infinity, an ordinary number (i.e.@: neither Not-a-Number nor
-an infinity). Return zero otherwise.
+an infinity) or zero. Return zero otherwise.
@end deftypefun
@deftypefun void mpfr_reldiff (mpfr_t @var{rop}, mpfr_t @var{op1}, mpfr_t @var{op2}, mp_rnd_t @var{rnd})
@@ -1088,11 +1089,11 @@ it just computes @math{|@var{op1}-@var{op2}|/@var{op1}}, using the
rounding mode @var{rnd} for all operations and the precision of @var{rop}.
@end deftypefun
-@deftypefun int mpfr_sgn (mpfr_t @var{op})
+@deftypefn Macro int mpfr_sgn (mpfr_t @var{op})
Return a positive value if @math{@var{op} > 0}, zero if @math{@var{op} = 0},
and a negative value if @math{@var{op} < 0}.
Its result is undefined when @var{op} is NaN (Not-a-Number).
-@end deftypefun
+@end deftypefn
@deftypefun int mpfr_greater_p (mpfr_t @var{op1}, mpfr_t @var{op2})
Return non-zero if @math{@var{op1} > @var{op2}}, zero otherwise.
diff --git a/sgn.c b/sgn.c
index 95eeeeac2..9ec2b31df 100644
--- a/sgn.c
+++ b/sgn.c
@@ -23,11 +23,7 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
int
-mpfr_sgn (mpfr_srcptr a)
+(mpfr_sgn) (mpfr_srcptr a)
{
- if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(a) ))
- /* Only infinite is signed */
- return MPFR_IS_INF (a) ? MPFR_INT_SIGN (a) : 0;
- else
- return MPFR_INT_SIGN (a);
+ return MPFR_UNLIKELY ( MPFR_IS_ZERO (a) ) ? 0 : MPFR_INT_SIGN (a);
}
diff --git a/tests/tisnan.c b/tests/tisnan.c
index 7cee98202..edf1e3f02 100644
--- a/tests/tisnan.c
+++ b/tests/tisnan.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_nan_p, mpfr_inf_p and mpfr_number_p.
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -36,7 +36,7 @@ main (void)
/* check +infinity gives non-zero for mpfr_inf_p only */
mpfr_set_ui (x, 1L, GMP_RNDZ);
mpfr_div_ui (x, x, 0L, GMP_RNDZ);
- if (mpfr_nan_p (x))
+ if (mpfr_nan_p (x) || (mpfr_nan_p) (x) )
{
printf ("Error: mpfr_nan_p(+Inf) gives non-zero\n");
exit (1);
@@ -46,15 +46,20 @@ main (void)
printf ("Error: mpfr_inf_p(+Inf) gives zero\n");
exit (1);
}
- if (mpfr_number_p (x))
+ if (mpfr_number_p (x) || (mpfr_number_p) (x) )
{
printf ("Error: mpfr_number_p(+Inf) gives non-zero\n");
exit (1);
}
+ if (mpfr_zero_p (x) || (mpfr_zero_p) (x) )
+ {
+ printf ("Error: mpfr_zero_p(+Inf) gives non-zero\n");
+ exit (1);
+ }
/* same for -Inf */
mpfr_neg (x, x, GMP_RNDN);
- if (mpfr_nan_p (x))
+ if (mpfr_nan_p (x) || (mpfr_nan_p(x)))
{
printf ("Error: mpfr_nan_p(-Inf) gives non-zero\n");
exit (1);
@@ -64,11 +69,16 @@ main (void)
printf ("Error: mpfr_inf_p(-Inf) gives zero\n");
exit (1);
}
- if (mpfr_number_p (x))
+ if (mpfr_number_p (x) || (mpfr_number_p)(x) )
{
printf ("Error: mpfr_number_p(-Inf) gives non-zero\n");
exit (1);
}
+ if (mpfr_zero_p (x) || (mpfr_zero_p)(x) )
+ {
+ printf ("Error: mpfr_zero_p(-Inf) gives non-zero\n");
+ exit (1);
+ }
/* same for NaN */
mpfr_sub (x, x, x, GMP_RNDN);
@@ -77,12 +87,17 @@ main (void)
printf ("Error: mpfr_nan_p(NaN) gives zero\n");
exit (1);
}
- if (mpfr_inf_p (x))
+ if (mpfr_inf_p (x) || (mpfr_inf_p)(x) )
{
printf ("Error: mpfr_inf_p(NaN) gives non-zero\n");
exit (1);
}
- if (mpfr_number_p (x))
+ if (mpfr_number_p (x) || (mpfr_number_p) (x) )
+ {
+ printf ("Error: mpfr_number_p(NaN) gives non-zero\n");
+ exit (1);
+ }
+ if (mpfr_zero_p (x) || (mpfr_zero_p)(x) )
{
printf ("Error: mpfr_number_p(NaN) gives non-zero\n");
exit (1);
@@ -90,12 +105,12 @@ main (void)
/* same for an ordinary number */
mpfr_set_ui (x, 1, GMP_RNDN);
- if (mpfr_nan_p (x))
+ if (mpfr_nan_p (x) || (mpfr_nan_p)(x))
{
printf ("Error: mpfr_nan_p(1) gives non-zero\n");
exit (1);
}
- if (mpfr_inf_p (x))
+ if (mpfr_inf_p (x) || (mpfr_inf_p)(x) )
{
printf ("Error: mpfr_inf_p(1) gives non-zero\n");
exit (1);
@@ -105,6 +120,34 @@ main (void)
printf ("Error: mpfr_number_p(1) gives zero\n");
exit (1);
}
+ if (mpfr_zero_p (x) || (mpfr_zero_p) (x) )
+ {
+ printf ("Error: mpfr_zero_p(1) gives non-zero\n");
+ exit (1);
+ }
+
+ /* Same for 0 */
+ mpfr_set_ui (x, 0, GMP_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);
+ }
mpfr_clear (x);
diff --git a/tests/tsgn.c b/tests/tsgn.c
index 71c12d61e..2273ce775 100644
--- a/tests/tsgn.c
+++ b/tests/tsgn.c
@@ -38,12 +38,6 @@ check_special(void)
printf("Sgn error for 0.\n");
ret = 1;
}
- MPFR_SET_NAN(x);
- if (mpfr_sgn(x) != 0)
- {
- printf("Sgn error for NAN.\n");
- ret = 1;
- }
MPFR_SET_INF(x);
MPFR_SET_POS(x);
if (mpfr_sgn(x) != 1)