summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(no author) <(no author)@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-20 17:54:55 +0000
committer(no author) <(no author)@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-20 17:54:55 +0000
commit662ab46d65a908e728ac64d3aac5aefeb2f7a025 (patch)
tree019495d9d35a4c4754502207c3c19d3bfdd775c7
parent7f857964d869e4a3f316a7da845e11a9da0388a5 (diff)
downloadmpfr-2-0-3-rel.tar.gz
This commit was manufactured by cvs2svn to create tagmpfr-2-0-3-rel
'mpfr-2-0-3-rel'. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/tags/mpfr-2-0-3-rel@2778 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--ChangeLog380
-rw-r--r--NEWS56
-rw-r--r--README11
-rw-r--r--README.dev9
-rw-r--r--TODO4
-rw-r--r--VERSION2
-rw-r--r--acinclude.m47
-rw-r--r--acosh.c54
-rw-r--r--agm.c8
-rw-r--r--config.guess214
-rw-r--r--config.sub122
-rw-r--r--const_log2.c86
-rw-r--r--const_pi.c28
-rw-r--r--erf.c49
-rw-r--r--exp.c11
-rw-r--r--factorial.c67
-rw-r--r--frac.c28
-rw-r--r--from_Torbjorn28
-rw-r--r--gamma.c84
-rw-r--r--gammaPiAGMformula.c229
-rw-r--r--get_str.c98
-rw-r--r--gmp_op.c208
-rw-r--r--hypot.c8
-rw-r--r--log1p.c14
-rw-r--r--minmax.c2
-rw-r--r--mpf2mpfr.h6
-rw-r--r--mpfi.c400
-rw-r--r--mpfi.h137
-rw-r--r--mpfr-test.h4
-rw-r--r--mpfr.h2
-rw-r--r--mpfr.texi63
-rw-r--r--neg.c6
-rw-r--r--pow.c14
-rw-r--r--pow_si.c4
-rw-r--r--pow_ui.c37
-rw-r--r--rint.c175
-rw-r--r--set_f.c45
-rw-r--r--sqrt.c4
-rw-r--r--sub1.c70
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/Makefile.in920
-rw-r--r--tests/tacosh.c30
-rw-r--r--tests/tagm.c21
-rw-r--r--tests/tasin.c2
-rw-r--r--tests/terf.c39
-rw-r--r--tests/tests.c5
-rw-r--r--tests/texp.c162
-rw-r--r--tests/tfactorial.c42
-rw-r--r--tests/tfrac.c38
-rw-r--r--tests/tgamma.c64
-rw-r--r--tests/tget_str.c52
-rw-r--r--tests/tgmpop.c361
-rw-r--r--tests/thyperbolic.c284
-rw-r--r--tests/thypot.c15
-rw-r--r--tests/tpow.c16
-rw-r--r--tests/trint.c205
-rw-r--r--tests/tset.c21
-rw-r--r--tests/tset_f.c83
-rw-r--r--tests/tset_ld.c16
-rw-r--r--tests/tsub.c14
-rw-r--r--tests/tui_pow.c46
-rw-r--r--tests/tzeta.c48
-rw-r--r--zeta.c82
63 files changed, 2669 insertions, 2674 deletions
diff --git a/ChangeLog b/ChangeLog
index cc55d227e..b7e5f6a99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,385 @@
+2004-02-20 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * NEWS, neg.c, tests/tset.c:
+ Ported bug fix / test of mpfr_neg to the 2.0 branch.
+
+ * mpfr-test.h, tests/tgmpop.c, gmp_op.c:
+ Ported bug fix / test of gmp_op.c (0.5+3/2 freezes) to the 2.0 branch.
+
+2004-02-18 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * config.guess, config.sub:
+ Update from the autotools-dev Debian package (2004-01-05).
+
+ * mpfr.texi: Updated the 2.0 branch.
+
+ * minmax.c: Updated copyright line (2.0 branch).
+
+ * mpfr.texi: Updated the 2.0 branch (up to rev. 1.200 / 2004-01-07).
+
+ * set_f.c, tests/tset_f.c:
+ Ported bug fix / test of mpfr_set_f to the 2.0 branch.
+
+2004-02-17 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * NEWS, ChangeLog: Update (2.0 branch).
+
+ * mpf2mpfr.h: Added 2004 in Copyright line (2.0 branch).
+
+ * set_f.c, tests/tset_f.c:
+ Ported bug fixes / tests of mpfr_set_f to the 2.0 branch.
+
+ * acinclude.m4: Try so support GMP as a Shared Library (2.0 branch).
+
+ * gmp_op.c, tests/tgmpop.c:
+ Ported bug fixes / tests of gmp_op.c to the 2.0 branch.
+
+2004-02-16 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpf2mpfr.h: Ported the mpf_dump fix to the 2.0 branch.
+
+ * tests/texp.c, exp.c:
+ Ported bug fixes / tests of mpfr_exp to the 2.0 branch.
+
+2004-02-11 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * gmp_op.c, tests/Makefile.am, tests/tgmpop.c:
+ Ported bug fixes / tests of gmp_op.c to the 2.0 branch.
+
+ * sub1.c, tests/tsub.c:
+ Ported bug fixes / tests of mpfr_sub1 to the 2.0 branch.
+
+2004-02-10 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * sqrt.c: Bug fix.
+
+2004-02-09 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * ChangeLog, NEWS: Update (2.0 branch).
+
+2004-02-06 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * factorial.c, gamma.c, tests/tfactorial.c, tests/tgamma.c:
+ Ported bug fixes / tests of mpfr_fac_ui and mpfr_gamma to
+ the 2.0 branch.
+
+ * hypot.c, tests/thypot.c:
+ Ported bug fixes / tests of mpfr_hypot to the 2.0 branch.
+
+ * agm.c, tests/tagm.c:
+ Ported bug fixes / tests of mpfr_agm to the 2.0 branch.
+
+ * get_str.c, tests/tget_str.c:
+ Ported bug fixes / tests of mpfr_get_str to the 2.0 branch.
+
+ * frac.c, tests/tfrac.c, tests/tzeta.c, zeta.c:
+ Ported bug fixes / tests of mpfr_frac and mpfr_zeta to the 2.0 branch.
+
+ * from_Torbjorn, gammaPiAGMformula.c, mpfi.c, mpfi.h:
+ (2.0 branch) Removed unused files.
+
+ * NEWS:
+ Added changes from version 2.0.1 to version 2.0.2 and updated MPFR URL
+ (2.0 branch).
+
+ * README.dev: Added (2.0 branch): "3) Update the NEWS file.".
+
+ * VERSION, mpfr.texi:
+ Updated the branch for the future version 2.0.3 (bug-fix release).
+
+2003-11-19 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * tests/tui_pow.c, pow.c:
+ Ported Paul's patch (fix and tests) concerning the pow.c bug (in case
+ exact result) to the 2.0.2 branch.
+
+2003-11-14 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * pow_si.c, tests/tpow.c:
+ Ported the pow_si patch (and test) to the 2.0.2 branch.
+
+ * pow.c, tests/tui_pow.c, tests/tzeta.c:
+ Ported the pow.c precision patch to the 2.0.2 branch (with the tests).
+
+ * tests/tset_ld.c:
+ Detect optimization bug of gcc 3.3 on Alpha to avoid a test failure.
+
+2003-11-11 Kevin Ryde <user42@zip.com.au>
+
+ * tests/tests.c (tests_rand_start): Use gmp_randinit_default not the
+ RANDS macro, to cope with new non-seeding MT setup by RANDS.
+
+2003-11-04 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * pow_ui.c:
+ Overflow on err (which is now unsigned) avoided, simplified its
+ computation, added some asserts, fixed the underflow check (the
+ cast to double was useless and could be inexact).
+
+ * tests/tacosh.c: Merged the check_inf test to the 2.0.2 branch.
+
+ * tests/tacosh.c:
+ The check_inf test wasn't called. Added 2 missing mpfr_clear and \n.
+
+ * acosh.c: Special cases rewritten.
+
+2003-10-30 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * log1p.c: MPFR_RET_NAN -> MPFR_RET(0).
+
+2003-10-27 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * tests/thyperbolic.c:
+ Fixes for thyperbolic.c merged to the 2.0.2 branch.
+
+ * tests/thyperbolic.c: Another fix, for acosh(-INF).
+
+ * tests/thyperbolic.c: Fixed exit status.
+
+2003-10-21 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * ChangeLog: Update.
+
+ * const_log2.c, const_pi.c, mpfr.h, TODO:
+ Fixed the mpfr_round bug (the mpfr_round macro hadn't been updated).
+ The ternary value wasn't always set in const_log2.c and const_pi.c.
+ Updated TODO.
+
+ * tests/trint.c: Value of y is displayed when a test fails.
+
+ * tests/trint.c: More tests (showing a bug for mpfr_round).
+
+ * tests/trint.c: More tests for the rounding-to-integer functions.
+
+2003-10-20 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * gmp_op.c: Wrong comment updated.
+
+ * rint.c, tests/trint.c, mpfr.texi:
+ Major update of the function mpfr_rint, including a small semantics
+ change to behave like the C function rint (unless the result is not
+ representable); as a consequence, mpfr_round now calls mpfr_rint with
+ the NEAREST_AWAY internal (to rint.c) rounding mode. Manual updated
+ to reflect this change.
+
+2003-10-17 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * erf.c, tests/terf.c: Fixed ternary value bugs and added tests.
+
+2003-10-16 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * tests/tasin.c, tests/tgamma.c: Added some necessary #include's.
+
+ * tests/trint.c:
+ Added a test against the libc (compiled and performed only when
+ __STDC_VERSION__ >= 199901L), showing a difference between mpfr_rint
+ and the C rint function (the behavior of mpfr_rint will change and
+ the manual will be updated).
+
+ * tests/trint.c:
+ Added mpfr_rint tests (as the behavior of this function will change).
+
+ * ChangeLog: Update.
+
+ * get_d.c, set_d.c: Fixed several bugs.
+
+ * get_d.c: Added XDEBUG support (like in set_d.c).
+
+2003-10-15 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr.texi:
+ Replaced all non-ASCII characters by an equivalent 7-bit sequence
+ to support unpatched texinfo.tex files.
+
+2003-10-15 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * tests/reuse.c: removed #define DEBUG (turned on accidentally)
+
+2003-10-15 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * BUGS:
+ Bug on the ternary value was fixed by Paul Zimmermann on 2003-10-14.
+
+2003-10-14 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * mpfr.texi: added preamble about ternary flag for special functions
+
+ * tests/reuse.c, tests/tacos.c, tests/tagm.c, tests/tasin.c, tests/tatan.c, tests/terf.c, tests/texp.c, tests/tgamma.c, tests/tgeneric.c, tests/thypot.c, tests/tzeta.c:
+ now uses #include "tgeneric.c" everywhere
+ (and modified test_generic to check also the inexact flag)
+
+ * tests/tui_div.c: check_nan() is back
+
+ * tests/tlog.c: removed old unused code
+
+ * tests/thyperbolic.c: fixed tests for x=0
+ removed composition tests (were already in-between #if 0 ... #endif)
+
+ * pow.c, pow_si.c, pow_ui.c, sin.c, sinh.c, sqrt.c, tan.c, tanh.c, ui_pow_ui.c, zeta.c, factorial.c, gamma.c, hypot.c, log.c, log10.c, log1p.c, log2.c, asinh.c, atan.c, atanh.c, const_euler.c, const_log2.c, const_pi.c, cos.c, cosh.c, erf.c, exp2.c, expm1.c, acos.c, acosh.c, agm.c, asin.c:
+ replaced mpfr_can_round (approx, err, rnd1, GMP_RNDN, prec)
+ by mpfr_can_round (approx, err, rnd1, GMP_RNDZ, prec + 1)
+ which in addition guarantees a correct inexact flag
+
+ * TODO: added new items (version number, rounding modes)
+
+ * README.dev: added comment about --enable-alloca=debug
+
+2003-10-13 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * BUGS: added section "Problems due to compiler bugs"
+
+ * exp3.c, exp_2.c:
+ change in can_round calls to get correct inexact flag for rounding to nearest
+
+2003-10-10 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * pow.c, tests/tpow.c:
+ fixed bug in mpfr_pow found by Ming J. Tsai (overflow)
+
+2003-10-08 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * acos.c, asin.c, atan.c:
+ Removed useless inclusion of standard headers and some #ifdef DEBUG
+ code. Partial reindentation.
+
+ * strncasecmp.c: Added a #include <stddef.h> because size_t is used.
+
+2003-10-07 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * tests/tabs.c, tests/tacos.c, tests/tadd.c, tests/tasin.c, tests/tatan.c, tests/tcmp.c, tests/tconst_log2.c, tests/tdiv.c, tests/tfactorial.c, tests/tfrac.c, tests/tgamma.c, tests/tget_str.c, tests/tlog10.c, tests/tlog1p.c, tests/tpow3.c, tests/tset_d.c, tests/tset_si.c, tests/tset_str.c, tests/tset_z.c, tests/tsub.c, tests/tui_pow.c, tests/tzeta.c, tests/tsin.c:
+ reduced test time
+
+2003-10-06 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * round_prec.c: fixed comment of mpfr_round_raw_generic
+
+ * add1.c, extract.c, get_si.c, get_ui.c:
+ replaced ABSSIZE by ESIZE (ABSSIZE is the allocated size, and should be
+ used only in functions init, set_prec, round_prec)
+
+ * tests/tadd.c: fixed bug in allocation for in-place operation
+
+ * asin.c, atan.c:
+ inexact flag should now be correct for directed rounding
+ fixed a bug for mpfr_atan(-Inf) [gave +Pi/2 instead of -Pi/2]
+
+ * tests/tatan.c: added test for atan(-Inf)
+
+ * set_ld.c: use macros to avoid possible problem with float input
+
+ * TODO: new proposal for mpfr_can_round
+
+ * mpfr.texi: mpfr_mul_2exp/mpfr_div_2exp are not obsolete
+
+2003-10-05 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr.texi:
+ Clearer mpfr_eq documentation (thanks to Kevin Ryde for the remark).
+
+2003-10-03 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr-impl.h:
+ MPFR_ASSERTN rewritten to avoid "statement with no effect" warnings
+ with gcc when the assertion is always true.
+
+ * add1.c:
+ Optimization (thanks to Patrick Pelissier), as the allocated size
+ may be larger than the size used by the significant bits.
+
+ * mpfr.texi, INSTALL: Updated installation notes.
+
+ * cmp_abs.c, mpfr.texi:
+ Infinities are now accepted in mpfr_cmpabs. Updated its definition
+ in the source (no longer sign(abs(b) - abs(c))).
+
+2003-10-02 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr.texi: Use @url{} for URLs.
+
+ * mpfr.texi: As suggested by PZ:
+ o documentation of mpfr_fits_* functions moved to the section
+ on conversions;
+ o grouped some mpfr_pow special cases;
+ o explanation concerning the meaning of rnd in mpfr_frac.
+
+ * tests/tset_str.c, tests/tset_z.c, tests/tsinh.c, tests/tsqrt.c, tests/tsub.c, tests/ttanh.c, tests/tui_pow.c, tests/tui_sub.c, tests/tzeta.c, tests/tmul.c, tests/tmul_ui.c, tests/tout_str.c, tests/tpow.c, tests/tset.c, tests/tset_d.c, tests/tlog.c, tests/tlog10.c, tests/tlog1p.c, tests/tlog2.c, tests/texpm1.c, tests/tfma.c, tests/tget_str.c, tests/thypot.c, tests/tadd.c, tests/tadd_ui.c, tests/tagm.c, tests/tasinh.c, tests/tatan.c, tests/tatanh.c, tests/tcan_round.c, tests/tcmp.c, tests/tcmp2.c, tests/tcos.c, tests/tcosh.c, tests/tdiv.c, tests/tdiv_ui.c, tests/terf.c, tests/texceptions.c, tests/texp.c, mpfr.h, mpfr.texi, print_raw.c, set_str_raw.c, tests/tacosh.c, BUGS, mpfr-impl.h:
+ Updated documentation. In particular, mpfr_set_str_raw renamed
+ as mpfr_set_str_binary. This function and mpfr_print_binary are
+ now internal functions. mpfr_print_binary no longer prints the
+ non-significant 0 bits. Updated the source to match the manual.
+ mpfr_print_binary has been completely rewritten (now directly
+ prints to stdout, without using an intermediate string). In
+ mpfr_set_str_binary, replaced atol by strtol + error checking.
+
+2003-10-02 Paul Zimmermann <Paul.Zimmermann@loria.fr>
+
+ * mpfr.texi: added paragraph on support/grants
+ added help for mpfr_erf
+
+2003-10-02 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr.texi:
+ Make node titles match section titles, and updated menus and xrefs.
+ Added a line break after @samp{uninstall}.
+
+2003-10-01 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * TODO, const_log2.c, const_pi.c, mpfr.h, mpfr.texi, zeta.c:
+ Corrections in the MPFR manual (PZ & VL). Functions mpfr_const_pi,
+ mpfr_const_log2 and mpfr_zeta now return a ternary value. Updated
+ TODO file.
+
+2003-09-30 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * BUGS: Added a bug related to the ternary value and worst cases.
+
+ * pow_si.c, pow_ui.c: Added exponent range support.
+
+ * mpfr.texi: Corrections up to Section 5.6 (PZ & VL).
+
+ * get_z_exp.c:
+ Re-added the assert on the exponent, but replacing MPFR_EMIN_MIN by
+ MP_EXP_T_MIN (this makes more sense): an assertion failed would mean
+ that the exponent is not representable (an undefined behavior in the
+ ISO C standard). If need be, we could choose to return MP_EXP_T_MIN
+ in such a case, or perhaps MP_EXP_T_MAX to signal an error. The
+ mantissa would still be meaningful.
+
+2003-09-30 Patrick Pelissier <Patrick.Pelissier@loria.fr>
+
+ * TODO: Update TODO & mpfr_set_prec.
+
+2003-09-29 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr.texi: Corrections up to Section 4.
+
+ * AUTHORS: Added authors Kevin Ryde and Patrick Pelissier.
+
+ * INSTALL: Removed "known problems" that are no longer problems.
+
+2003-09-26 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * BUGS: Removed bugs related to the tests and to the exponents
+ as they no longer occur. Updated some potentials bugs.
+
2003-09-25 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+ * mpfr-impl.h, mpfr.h, mpfr.texi, tests/tinits.c:
+ Removed mpfr_inits, mpfr_inits2, mpfr_clears from the documentation.
+ Moved their prototypes to mpfr-impl.h (internal functions until
+ decided otherwise).
+
+2003-09-25 Patrick Pelissier <Patrick.Pelissier@loria.fr>
+
+ * const_log2.c, const_pi.c, generic.c, atan.c:
+ Modify 'r' arg of GENERIC from int to long (min 32 bits).
+
+2003-09-25 Vincent Lefevre <Vincent.Lefevre@loria.fr>
+
+ * mpfr.texi: 8-bit ISO-8859-1 characters + consistent spelling.
+
+ * ChangeLog: Update.
+
* tests/tgeneric.c, tests/tget_d.c, tests/tget_str.c, tests/thypot.c, tests/tisnan.c, tests/tlog.c, tests/tlog10.c, tests/tmul.c, tests/tmul_2exp.c, tests/tmul_ui.c, tests/tout_str.c, tests/tpow.c, tests/tpow3.c, tests/trandom.c, tests/tconst_pi.c, tests/tcos.c, tests/tdiv.c, tests/tdiv_ui.c, tests/teq.c, tests/terf.c, tests/tests.c, tests/texceptions.c, tests/texp.c, tests/texp2.c, tests/tfactorial.c, tests/tfma.c, tests/tfrac.c, tests/tgamma.c, tests/mpf_compat.h, tests/reuse.c, tests/tabs.c, tests/tacos.c, tests/tadd.c, tests/tagm.c, tests/tasin.c, tests/tatan.c, tests/tcan_round.c, tests/tcbrt.c, tests/tcmp.c, tests/tcmp2.c, tests/tcmp_d.c, tests/tcmp_ui.c, tests/tconst_log2.c:
Changed the remaining stderr to stdout.
diff --git a/NEWS b/NEWS
index 34eb7eecf..c5eba258d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-Copyright 2000, 2001, 2002, 2003 Free Software Foundation.
+Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation.
Contributed by the Spaces project, INRIA Lorraine.
This file is part of the MPFR Library.
@@ -20,6 +20,28 @@ MA 02111-1307, USA.
##############################################################################
+Changes from version 2.0.2 to version 2.0.3:
+- bug fixes (mpfr_add_q, mpfr_add_z, mpfr_agm, mpfr_div_q, mpfr_div_z,
+ mpfr_exp, mpfr_fac_ui, mpfr_frac, mpfr_gamma, mpfr_get_str, mpfr_hypot,
+ mpfr_mul_q, mpfr_mul_z, mpfr_neg, mpfr_set_f, mpfr_sqrt, mpfr_sub1,
+ mpfr_sub_q, mpfr_sub_z, mpfr_zeta, mpf_dump from mpf2mpfr.h)
+- support GMP as a shared library (not fully tested)
+
+Changes from version 2.0.1 to version 2.0.2:
+- many bug fixes and other improvements.
+- new functions mpfr_prec_round (replaces mpfr_round_prec), mpfr_get_exp,
+ mpfr_set_exp, mpfr_get_ld, mpfr_set_ld, mpfr_get_d_2exp, mpfr_get_si,
+ mpfr_get_ui, mpfr_nextabove, mpfr_nextbelow, mpfr_nexttoward, mpfr_frac,
+ mpfr_fits_*, mpfr_cmp_d, mpfr_cmpabs, mpfr_erf, mpfr_gamma, mpfr_zeta,
+ mpfr_greater_p, mpfr_greaterequal_p, mpfr_less_p, mpfr_lessequal_p,
+ mpfr_lessgreater_p, mpfr_equal_p, mpfr_unordered_p.
+- removed functions: mpfr_print_binary, mpfr_round_prec (replaced by
+ mpfr_prec_round), mpfr_set_str_raw, mpfr_set_machine_rnd_mode.
+- function mpfr_isinteger renamed mpfr_integer_p.
+- return type of some functions changed from void to int, for consistency.
+- return type of mpfr_set_prec changed from int to void.
+- new values for exponent range.
+
Changes from version 2001 to version 2.0.1:
- new mathematical functions: acos, acosh, asin, asinh, atan, atanh, cosh,
base-2 exponential and logarithm, base-10 logarithm, expm1, factorial,
@@ -40,8 +62,8 @@ Changes from version 2001 to version 2.0.1:
mpfr_print_raw is now mpfr_print_binary.
Changes from version 1.0 to version 2001:
-- the default installation does not provide any more access to machine
- rounding mode, and as a consequence does not compare MPFR results with
+- the default installation does not provide any more access to machine
+ rounding mode, and as a consequence does not compare MPFR results with
precision=53 to machine results. Add option -DTEST if you want to have
access to machine rounding mode, and to check MPFR results against.
- the MPFR files do not need <math.h> any more
@@ -59,19 +81,19 @@ Changes from version 1.0 to version 2001:
Changes from version 0.4 to version 1.0:
-- Version 1.0 now uses a standard configure/make installation.
-- Version 1.0 implements all functions that are available in the MPF class
- from GMP 3.1 (except mpf_swap) and a header file mpf2mpfr.h is included in
- the distribution for easy change from MPF to MPFR.
-- Version 1.0 implements new elementary functions: mpfr_sincos
-- Some functions and macros have been renamed: mpfr_log2 is now
- mpfr_const_log2, mpfr_pi is now mpfr_const_pi, SIGN is now MPFR_SIGN.
-- Version 1.0 uses faster algorithms for mpfr_exp, mpfr_const_pi,
- mpfr_const_log2. Compare the timings from version 1.0 and version 0.4.
-- Version 1.0 corrects some bugs of version 0.4.
-- The precision of MPFR variables is now named mpfr_prec, which makes it
- easier to change it, to say unsigned long long. Same for the rounding mode
- which is called mp_rnd_t.
+- Version 1.0 now uses a standard configure/make installation.
+- Version 1.0 implements all functions that are available in the MPF class
+ from GMP 3.1 (except mpf_swap) and a header file mpf2mpfr.h is included in
+ the distribution for easy change from MPF to MPFR.
+- Version 1.0 implements new elementary functions: mpfr_sincos
+- Some functions and macros have been renamed: mpfr_log2 is now
+ mpfr_const_log2, mpfr_pi is now mpfr_const_pi, SIGN is now MPFR_SIGN.
+- Version 1.0 uses faster algorithms for mpfr_exp, mpfr_const_pi,
+ mpfr_const_log2. Compare the timings from version 1.0 and version 0.4.
+- Version 1.0 corrects some bugs of version 0.4.
+- The precision of MPFR variables is now named mpfr_prec, which makes it
+ easier to change it, to say unsigned long long. Same for the rounding mode
+ which is called mp_rnd_t.
You'll find other news concerning the MPFR library on the web
-page <http://www.loria.fr/projets/mpfr/>.
+page <http://www.mpfr.org/>.
diff --git a/README b/README
index 2180ce51a..86b70e3a7 100644
--- a/README
+++ b/README
@@ -30,22 +30,25 @@ COPYING - the GNU General Public License, version 2
COPYING.LIB - the GNU Lesser General Public License, version 2.1
ChangeLog - the log of changes
INSTALL - how to install MPFR (see also mpfr.texi)
-Makefile* - files for building the library
+Makefile.* - files for building the library
NEWS - new features with respect to previous versions
README - this file
TODO - what remains to do (any help is welcome!)
VERSION - version of MPFR (next release version if taken from CVS)
ac*.m4 - automatic configuration files
*.c - source files
-configure* - configuration files
+config* - configuration files
+depcomp - compile a program generating dependencies as side-effects
fdl.texi - the GNU Free Documentation License
-install* - installation files
+fits_s.h - source file
+fits_u.h - source file
+install-sh - installation file
+log_b2.h - header file for mpfr_get_str and mpfr_set_str
missing - auxiliary installation file
mkinst* - auxiliary installation file
mpf2mpfr.h - header file for compatibility with MPF
mpfr.h - external header file for MPFR
mpfr-impl.h - internal header file for MPFR
-mpfr-math.h - another internal header file for MPFR
mpfr-test.h - header file for test files
mpfr.info - info file for MPFR
mpfr.texi - texinfo documentation for MPFR
diff --git a/README.dev b/README.dev
index 1ee77630b..19b66e299 100644
--- a/README.dev
+++ b/README.dev
@@ -38,12 +38,13 @@ To make a release (for the MPFR team):
directly or with emacs), e.g. rcs2log > ChangeLog.2 and edit
ChangeLog to insert ChangeLog.2 at the beginning and remove
the duplicated lines.
- 3) Generate the release version with "make dist".
- 4) Test the release version on different machines, with and without
+ 3) Update the NEWS file.
+ 4) Generate the release version with "make dist".
+ 5) Test the release version on different machines, with and without
the --disable-alloca configure option (or compile gmp with
--enable-alloca=debug).
- 5) If there is no problem, add a tag to the CVS corresponding to the
+ 6) If there is no problem, add a tag to the CVS corresponding to the
release, e.g. mpfr-2-0-1-rel for mpfr 2.0.1 (note that the periods
are replaced by dashes): cvs tag mpfr-2-0-1-rel
- 6) Update the VERSION file to indicate the next version.
+ 7) Update the VERSION file to indicate the next version.
Update the version in mpfr.texi.
diff --git a/TODO b/TODO
index 18d96ef36..bca377d7f 100644
--- a/TODO
+++ b/TODO
@@ -173,10 +173,12 @@ Miscellaneous:
add one ulp to the mantissa.
- add a new rounding mode: round to nearest, with ties away from zero
- (will be in 754r)
+ (will be in 754r, could be used by mpfr_round)
- check/define the sign of infinity for gamma(-integer)
+- add tests of the ternary value for constants
+
Reentrancy / Thread-Safety:
- Temporary changes to emin/emax are not safe (all uses of
diff --git a/VERSION b/VERSION
index e9307ca57..50ffc5aa7 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0.2
+2.0.3
diff --git a/acinclude.m4 b/acinclude.m4
index d50d3d41d..849c67517 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -36,7 +36,12 @@ then
then
LDADD="$LDADD $1/lib$2.a"
else
- AC_MSG_ERROR($1/lib$2.a not found)
+ if test -r "$1/lib$2.so"
+ then
+ LDADD="$LDADD $1/lib$2.so"
+ else
+ AC_MSG_ERROR($1/lib$2.a/so not found)
+ fi
fi
AC_MSG_RESULT(yes)
else
diff --git a/acosh.c b/acosh.c
index 20539a81f..2e6603a34 100644
--- a/acosh.c
+++ b/acosh.c
@@ -30,48 +30,47 @@ MA 02111-1307, USA. */
*/
int
-mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
+mpfr_acosh (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
-
+
int inexact = 0;
int comp;
- if (MPFR_IS_NAN(x) || (comp = mpfr_cmp_ui (x, 1)) < 0)
+ if (MPFR_IS_NAN (x) || (comp = mpfr_cmp_ui (x, 1)) < 0)
{
- MPFR_SET_NAN(y);
+ MPFR_SET_NAN (y);
MPFR_RET_NAN;
}
-
- MPFR_CLEAR_NAN(y);
- if (comp == 0)
+ MPFR_SET_POS (y);
+
+ if (MPFR_IS_INF (x))
{
- MPFR_SET_ZERO(y); /* acosh(1) = 0 */
- MPFR_SET_POS(y);
- MPFR_RET(0);
- }
-
- if (MPFR_IS_INF(x))
- {
- MPFR_SET_INF(y);
- MPFR_SET_POS(y);
- MPFR_RET(0);
+ MPFR_CLEAR_FLAGS (y);
+ MPFR_SET_INF (y);
+ MPFR_RET (0);
}
- MPFR_CLEAR_INF(y);
+ MPFR_CLEAR_FLAGS (y);
+
+ if (comp == 0)
+ {
+ MPFR_SET_ZERO (y); /* acosh(1) = 0 */
+ MPFR_RET (0);
+ }
/* General case */
{
/* Declaration of the intermediary variables */
mpfr_t t, te, ti;
-
+
/* Declaration of the size variables */
mp_prec_t Nx = MPFR_PREC(x); /* Precision of input variable */
mp_prec_t Ny = MPFR_PREC(y); /* Precision of output variable */
-
+
mp_prec_t Nt; /* Precision of the intermediary variable */
int err; /* Precision of error */
-
+
/* compute the precision of intermediary variable */
Nt = MAX(Nx, Ny);
/* the optimal number of bits : see algorithms.ps */
@@ -110,7 +109,7 @@ mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
}
while ((err < 0) || !mpfr_can_round (t, err, GMP_RNDN, GMP_RNDZ,
Ny + (rnd_mode == GMP_RNDN)));
-
+
inexact = mpfr_set (y, t, rnd_mode);
mpfr_clear (t);
@@ -122,14 +121,3 @@ mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
return mpfr_check_range (y, inexact, rnd_mode);
}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/agm.c b/agm.c
index f96c8340b..f4f8d0ace 100644
--- a/agm.c
+++ b/agm.c
@@ -1,6 +1,6 @@
/* mpfr_agm -- arithmetic-geometric mean of two floating-point numbers
-Copyright 1999, 2000, 2001, 2002 Free Software Foundation.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -27,7 +27,7 @@ MA 02111-1307, USA. */
int
mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode)
{
- int s, go_on, compare;
+ int s, go_on, compare, inexact;
mp_prec_t p, q;
double uo, vo;
mp_limb_t *up, *vp, *tmpp, *tmpup, *tmpvp, *ap, *bp;
@@ -168,12 +168,12 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode)
/* Setting of the result */
- mpfr_set(r,v,rnd_mode);
+ inexact = mpfr_set (r, v, rnd_mode);
/* Let's clean */
TMP_FREE(marker);
- return 1; /* agm(u,v) can be exact for u, v rational only for u=v.
+ return inexact; /* agm(u,v) can be exact for u, v rational only for u=v.
Proof (due to Nicolas Brisebarre): it suffices to consider
u=1 and v<1. Then 1/AGM(1,v) = 2F1(1/2,1/2,1;1-v^2),
and a theorem due to G.V. Chudnovsky states that for x a
diff --git a/config.guess b/config.guess
index 9b1384be4..e8c6fc0c3 100644
--- a/config.guess
+++ b/config.guess
@@ -1,9 +1,9 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-# 2000, 2001, 2002 Free Software Foundation, Inc.
+# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
-timestamp='2002-11-30'
+timestamp='2004-01-05'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@@ -98,14 +98,18 @@ trap 'exit 1' 1 2 15
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
# use `HOST_CC' if defined, but it is deprecated.
-# This shell variable is my proudest work .. or something. --bje
+# Portable tmp directory creation inspired by the Autoconf team.
-set_cc_for_build='tmpdir=${TMPDIR-/tmp}/config-guess-$$ ;
-(old=`umask` && umask 077 && mkdir $tmpdir && umask $old && unset old)
- || (echo "$me: cannot create $tmpdir" >&2 && exit 1) ;
-dummy=$tmpdir/dummy ;
-files="$dummy.c $dummy.o $dummy.rel $dummy" ;
-trap '"'"'rm -f $files; rmdir $tmpdir; exit 1'"'"' 1 2 15 ;
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
case $CC_FOR_BUILD,$HOST_CC,$CC in
,,) echo "int x;" > $dummy.c ;
for c in cc gcc c89 c99 ; do
@@ -113,15 +117,13 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in
CC_FOR_BUILD="$c"; break ;
fi ;
done ;
- rm -f $files ;
if test x"$CC_FOR_BUILD" = x ; then
CC_FOR_BUILD=no_compiler_found ;
fi
;;
,,*) CC_FOR_BUILD=$CC ;;
,*,*) CC_FOR_BUILD=$HOST_CC ;;
-esac ;
-unset files'
+esac ;'
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 1994-08-24)
@@ -219,6 +221,9 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
mvmeppc:OpenBSD:*:*)
echo powerpc-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
+ pegasos:OpenBSD:*:*)
+ echo powerpc-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
pmax:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
@@ -238,68 +243,52 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
if test $UNAME_RELEASE = "V4.0"; then
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
fi
+ # According to Compaq, /usr/sbin/psrinfo has been available on
+ # OSF/1 and Tru64 systems produced since 1995. I hope that
+ # covers most systems running today. This code pipes the CPU
+ # types through head -n 1, so we only detect the type of CPU 0.
+ ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+ case "$ALPHA_CPU_TYPE" in
+ "EV4 (21064)")
+ UNAME_MACHINE="alpha" ;;
+ "EV4.5 (21064)")
+ UNAME_MACHINE="alpha" ;;
+ "LCA4 (21066/21068)")
+ UNAME_MACHINE="alpha" ;;
+ "EV5 (21164)")
+ UNAME_MACHINE="alphaev5" ;;
+ "EV5.6 (21164A)")
+ UNAME_MACHINE="alphaev56" ;;
+ "EV5.6 (21164PC)")
+ UNAME_MACHINE="alphapca56" ;;
+ "EV5.7 (21164PC)")
+ UNAME_MACHINE="alphapca57" ;;
+ "EV6 (21264)")
+ UNAME_MACHINE="alphaev6" ;;
+ "EV6.7 (21264A)")
+ UNAME_MACHINE="alphaev67" ;;
+ "EV6.8CB (21264C)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.8AL (21264B)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.8CX (21264D)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.9A (21264/EV69A)")
+ UNAME_MACHINE="alphaev69" ;;
+ "EV7 (21364)")
+ UNAME_MACHINE="alphaev7" ;;
+ "EV7.9 (21364A)")
+ UNAME_MACHINE="alphaev79" ;;
+ esac
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
- eval $set_cc_for_build
- cat <<EOF >$dummy.s
- .data
-\$Lformat:
- .byte 37,100,45,37,120,10,0 # "%d-%x\n"
-
- .text
- .globl main
- .align 4
- .ent main
-main:
- .frame \$30,16,\$26,0
- ldgp \$29,0(\$27)
- .prologue 1
- .long 0x47e03d80 # implver \$0
- lda \$2,-1
- .long 0x47e20c21 # amask \$2,\$1
- lda \$16,\$Lformat
- mov \$0,\$17
- not \$1,\$18
- jsr \$26,printf
- ldgp \$29,0(\$26)
- mov 0,\$16
- jsr \$26,exit
- .end main
-EOF
- $CC_FOR_BUILD -o $dummy $dummy.s 2>/dev/null
- if test "$?" = 0 ; then
- case `$dummy` in
- 0-0)
- UNAME_MACHINE="alpha"
- ;;
- 1-0)
- UNAME_MACHINE="alphaev5"
- ;;
- 1-1)
- UNAME_MACHINE="alphaev56"
- ;;
- 1-101)
- UNAME_MACHINE="alphapca56"
- ;;
- 2-303)
- UNAME_MACHINE="alphaev6"
- ;;
- 2-307)
- UNAME_MACHINE="alphaev67"
- ;;
- 2-1307)
- UNAME_MACHINE="alphaev68"
- ;;
- 3-1307)
- UNAME_MACHINE="alphaev7"
- ;;
- esac
- fi
- rm -f $dummy.s $dummy && rmdir $tmpdir
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
exit 0 ;;
+ Alpha*:OpenVMS:*:*)
+ echo alpha-hp-vms
+ exit 0 ;;
Alpha\ *:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# Should we change UNAME_MACHINE based on the output of uname instead
@@ -321,6 +310,9 @@ EOF
*:OS/390:*:*)
echo i370-ibm-openedition
exit 0 ;;
+ *:OS400:*:*)
+ echo powerpc-ibm-os400
+ exit 0 ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit 0;;
@@ -338,6 +330,9 @@ EOF
NILE*:*:*:dcosx)
echo pyramid-pyramid-svr4
exit 0 ;;
+ DRS?6000:unix:4.0:6*)
+ echo sparc-icl-nx6
+ exit 0 ;;
DRS?6000:UNIX_SV:4.2*:7*)
case `/usr/bin/uname -p` in
sparc) echo sparc-icl-nx7 && exit 0 ;;
@@ -450,8 +445,7 @@ EOF
EOF
$CC_FOR_BUILD -o $dummy $dummy.c \
&& $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
- && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
- rm -f $dummy.c $dummy && rmdir $tmpdir
+ && exit 0
echo mips-mips-riscos${UNAME_RELEASE}
exit 0 ;;
Motorola:PowerMAX_OS:*:*)
@@ -535,8 +529,7 @@ EOF
exit(0);
}
EOF
- $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
- rm -f $dummy.c $dummy && rmdir $tmpdir
+ $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
echo rs6000-ibm-aix3.2.5
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
@@ -635,10 +628,20 @@ EOF
}
EOF
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
- if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi
- rm -f $dummy.c $dummy && rmdir $tmpdir
+ test -z "$HP_ARCH" && HP_ARCH=hppa
fi ;;
esac
+ if [ ${HP_ARCH} = "hppa2.0w" ]
+ then
+ # avoid double evaluation of $set_cc_for_build
+ test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
+ if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
+ then
+ HP_ARCH="hppa2.0w"
+ else
+ HP_ARCH="hppa64"
+ fi
+ fi
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit 0 ;;
ia64:HP-UX:*:*)
@@ -672,8 +675,7 @@ EOF
exit (0);
}
EOF
- $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
- rm -f $dummy.c $dummy && rmdir $tmpdir
+ $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
echo unknown-hitachi-hiuxwe2
exit 0 ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
@@ -731,21 +733,26 @@ EOF
CRAY*TS:*:*:*)
echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
- CRAY*T3D:*:*:*)
- echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
- exit 0 ;;
CRAY*T3E:*:*:*)
echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
CRAY*SV1:*:*:*)
echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit 0 ;;
+ *:UNICOS/mp:*:*)
+ echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit 0 ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit 0 ;;
+ 5000:UNIX_System_V:4.*:*)
+ FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+ echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+ exit 0 ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
exit 0 ;;
@@ -767,8 +774,10 @@ EOF
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
- rm -f $dummy.c && rmdir $tmpdir
- echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
+ # GNU/KFreeBSD systems have a "k" prefix to indicate we are using
+ # FreeBSD's kernel, but not the complete OS.
+ case ${LIBC} in gnu) kernel_only='k' ;; esac
+ echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
exit 0 ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
@@ -779,8 +788,8 @@ EOF
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit 0 ;;
- x86:Interix*:3*)
- echo i586-pc-interix3
+ x86:Interix*:[34]*)
+ echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
exit 0 ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
@@ -801,14 +810,22 @@ EOF
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
*:GNU:*:*)
+ # the GNU system
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit 0 ;;
+ *:GNU/*:*:*)
+ # other systems with GNU libc and userland
+ echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+ exit 0 ;;
i*86:Minix:*:*)
echo ${UNAME_MACHINE}-pc-minix
exit 0 ;;
arm*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
+ cris:Linux:*:*)
+ echo cris-axis-linux-gnu
+ exit 0 ;;
ia64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
@@ -832,7 +849,6 @@ EOF
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
- rm -f $dummy.c && rmdir $tmpdir
test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
;;
mips64:Linux:*:*)
@@ -852,7 +868,6 @@ EOF
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
- rm -f $dummy.c && rmdir $tmpdir
test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
;;
ppc:Linux:*:*)
@@ -889,6 +904,9 @@ EOF
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux
exit 0 ;;
+ sh64*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit 0 ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit 0 ;;
@@ -946,9 +964,11 @@ EOF
LIBC=gnuaout
#endif
#endif
+ #ifdef __dietlibc__
+ LIBC=dietlibc
+ #endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
- rm -f $dummy.c && rmdir $tmpdir
test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
;;
@@ -977,6 +997,9 @@ EOF
i*86:atheos:*:*)
echo ${UNAME_MACHINE}-unknown-atheos
exit 0 ;;
+ i*86:syllable:*:*)
+ echo ${UNAME_MACHINE}-pc-syllable
+ exit 0 ;;
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
@@ -1048,7 +1071,7 @@ EOF
exit 0 ;;
M68*:*:R3V[567]*:*)
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
- 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0)
+ 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
OS_REL=''
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
@@ -1146,7 +1169,11 @@ EOF
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
exit 0 ;;
*:Darwin:*:*)
- echo `uname -p`-apple-darwin${UNAME_RELEASE}
+ case `uname -p` in
+ *86) UNAME_PROCESSOR=i686 ;;
+ powerpc) UNAME_PROCESSOR=powerpc ;;
+ esac
+ echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
exit 0 ;;
*:procnto*:*:* | *:QNX:[0123456789]*:*)
UNAME_PROCESSOR=`uname -p`
@@ -1159,7 +1186,7 @@ EOF
*:QNX:*:4*)
echo i386-pc-qnx
exit 0 ;;
- NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*)
+ NSR-?:NONSTOP_KERNEL:*:*)
echo nsr-tandem-nsk${UNAME_RELEASE}
exit 0 ;;
*:NonStop-UX:*:*)
@@ -1200,6 +1227,12 @@ EOF
*:ITS:*:*)
echo pdp10-unknown-its
exit 0 ;;
+ SEI:*:*:SEIUX)
+ echo mips-sei-seiux${UNAME_RELEASE}
+ exit 0 ;;
+ *:DRAGONFLY:*:*)
+ echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE}
+ exit 0 ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
@@ -1320,8 +1353,7 @@ main ()
}
EOF
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
-rm -f $dummy.c $dummy && rmdir $tmpdir
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
# Apollos put the system type in the environment.
diff --git a/config.sub b/config.sub
index f0675aa6b..463186dbf 100644
--- a/config.sub
+++ b/config.sub
@@ -1,9 +1,9 @@
#! /bin/sh
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-# 2000, 2001, 2002 Free Software Foundation, Inc.
+# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
-timestamp='2002-11-30'
+timestamp='2004-01-05'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@@ -118,7 +118,8 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
- nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
+ nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
+ kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
@@ -228,13 +229,14 @@ case $basic_machine in
| a29k \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+ | am33_2.0 \
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
- | clipper \
+ | c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
| fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| i370 | i860 | i960 | ia64 \
- | ip2k \
+ | ip2k | iq2000 \
| m32r | m68000 | m68k | m88k | mcore \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
@@ -245,21 +247,24 @@ case $basic_machine in
| mips64vr4300 | mips64vr4300el \
| mips64vr5000 | mips64vr5000el \
| mipsisa32 | mipsisa32el \
+ | mipsisa32r2 | mipsisa32r2el \
| mipsisa64 | mipsisa64el \
+ | mipsisa64r2 | mipsisa64r2el \
| mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \
| mipstx39 | mipstx39el \
| mn10200 | mn10300 \
+ | msp430 \
| ns16k | ns32k \
| openrisc | or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
| pyramid \
- | sh | sh[1234] | sh3e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
+ | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
| strongarm \
- | tahoe | thumb | tic80 | tron \
+ | tahoe | thumb | tic4x | tic80 | tron \
| v850 | v850e \
| we32k \
| x86 | xscale | xstormy16 | xtensa \
@@ -294,7 +299,7 @@ case $basic_machine in
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* \
| bs2000-* \
- | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* \
+ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
| clipper-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
@@ -302,7 +307,7 @@ case $basic_machine in
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| i*86-* | i860-* | i960-* | ia64-* \
- | ip2k-* \
+ | ip2k-* | iq2000-* \
| m32r-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
| m88110-* | m88k-* | mcore-* \
@@ -315,21 +320,26 @@ case $basic_machine in
| mips64vr4300-* | mips64vr4300el-* \
| mips64vr5000-* | mips64vr5000el-* \
| mipsisa32-* | mipsisa32el-* \
+ | mipsisa32r2-* | mipsisa32r2el-* \
| mipsisa64-* | mipsisa64el-* \
+ | mipsisa64r2-* | mipsisa64r2el-* \
| mipsisa64sb1-* | mipsisa64sb1el-* \
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
- | mipstx39 | mipstx39el \
- | none-* | np1-* | ns16k-* | ns32k-* \
+ | mipstx39-* | mipstx39el-* \
+ | msp430-* \
+ | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
| pyramid-* \
| romp-* | rs6000-* \
- | sh-* | sh[1234]-* | sh3e-* | sh[34]eb-* | shbe-* \
+ | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
- | tahoe-* | thumb-* | tic30-* | tic4x-* | tic54x-* | tic80-* | tron-* \
+ | tahoe-* | thumb-* \
+ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+ | tron-* \
| v850-* | v850e-* | vax-* \
| we32k-* \
| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
@@ -367,6 +377,12 @@ case $basic_machine in
basic_machine=a29k-none
os=-bsd
;;
+ amd64)
+ basic_machine=x86_64-pc
+ ;;
+ amd64-*)
+ basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
amdahl)
basic_machine=580-amdahl
os=-sysv
@@ -716,6 +732,10 @@ case $basic_machine in
np1)
basic_machine=np1-gould
;;
+ nv1)
+ basic_machine=nv1-cray
+ os=-unicosmp
+ ;;
nsr-tandem)
basic_machine=nsr-tandem
;;
@@ -727,6 +747,10 @@ case $basic_machine in
basic_machine=or32-unknown
os=-coff
;;
+ os400)
+ basic_machine=powerpc-ibm
+ os=-os400
+ ;;
OSE68000 | ose68000)
basic_machine=m68000-ericsson
os=-ose
@@ -758,18 +782,24 @@ case $basic_machine in
pentiumpro | p6 | 6x86 | athlon | athlon_*)
basic_machine=i686-pc
;;
- pentiumii | pentium2)
+ pentiumii | pentium2 | pentiumiii | pentium3)
basic_machine=i686-pc
;;
+ pentium4)
+ basic_machine=i786-pc
+ ;;
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumpro-* | p6-* | 6x86-* | athlon-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
- pentiumii-* | pentium2-*)
+ pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
+ pentium4-*)
+ basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
pn)
basic_machine=pn-gould
;;
@@ -828,6 +858,10 @@ case $basic_machine in
sb1el)
basic_machine=mipsisa64sb1el-unknown
;;
+ sei)
+ basic_machine=mips-sei
+ os=-seiux
+ ;;
sequent)
basic_machine=i386-sequent
;;
@@ -835,6 +869,9 @@ case $basic_machine in
basic_machine=sh-hitachi
os=-hms
;;
+ sh64)
+ basic_machine=sh64-unknown
+ ;;
sparclite-wrs | simso-wrs)
basic_machine=sparclite-wrs
os=-vxworks
@@ -901,10 +938,6 @@ case $basic_machine in
basic_machine=i386-sequent
os=-dynix
;;
- t3d)
- basic_machine=alpha-cray
- os=-unicos
- ;;
t3e)
basic_machine=alphaev5-cray
os=-unicos
@@ -913,14 +946,18 @@ case $basic_machine in
basic_machine=t90-cray
os=-unicos
;;
- tic4x | c4x*)
- basic_machine=tic4x-unknown
- os=-coff
- ;;
tic54x | c54x*)
basic_machine=tic54x-unknown
os=-coff
;;
+ tic55x | c55x*)
+ basic_machine=tic55x-unknown
+ os=-coff
+ ;;
+ tic6x | c6x*)
+ basic_machine=tic6x-unknown
+ os=-coff
+ ;;
tx39)
basic_machine=mipstx39-unknown
;;
@@ -934,6 +971,10 @@ case $basic_machine in
tower | tower-32)
basic_machine=m68k-ncr
;;
+ tpf)
+ basic_machine=s390x-ibm
+ os=-tpf
+ ;;
udi29k)
basic_machine=a29k-amd
os=-udi
@@ -1023,7 +1064,7 @@ case $basic_machine in
we32k)
basic_machine=we32k-att
;;
- sh3 | sh4 | sh3eb | sh4eb | sh[1234]le | sh3ele)
+ sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
basic_machine=sh-unknown
;;
sh64)
@@ -1102,19 +1143,19 @@ case $os in
| -aos* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
- | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
+ | -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
| -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
- | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
+ | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
- | -powermax* | -dnix*)
+ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
@@ -1138,6 +1179,9 @@ case $os in
-mac*)
os=`echo $os | sed -e 's|mac|macos|'`
;;
+ -linux-dietlibc)
+ os=-linux-dietlibc
+ ;;
-linux*)
os=`echo $os | sed -e 's|linux|linux-gnu|'`
;;
@@ -1150,6 +1194,9 @@ case $os in
-opened*)
os=-openedition
;;
+ -os400*)
+ os=-os400
+ ;;
-wince*)
os=-wince
;;
@@ -1171,6 +1218,9 @@ case $os in
-atheos*)
os=-atheos
;;
+ -syllable*)
+ os=-syllable
+ ;;
-386bsd)
os=-bsd
;;
@@ -1193,6 +1243,9 @@ case $os in
-sinix*)
os=-sysv4
;;
+ -tpf*)
+ os=-tpf
+ ;;
-triton*)
os=-sysv3
;;
@@ -1223,6 +1276,12 @@ case $os in
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
os=-mint
;;
+ -aros*)
+ os=-aros
+ ;;
+ -kaos*)
+ os=-kaos
+ ;;
-none)
;;
*)
@@ -1254,6 +1313,9 @@ case $basic_machine in
arm*-semi)
os=-aout
;;
+ c4x-* | tic4x-*)
+ os=-coff
+ ;;
# This must come before the *-dec entry.
pdp10-*)
os=-tops20
@@ -1432,9 +1494,15 @@ case $basic_machine in
-mvs* | -opened*)
vendor=ibm
;;
+ -os400*)
+ vendor=ibm
+ ;;
-ptx*)
vendor=sequent
;;
+ -tpf*)
+ vendor=ibm
+ ;;
-vxsim* | -vxworks* | -windiss*)
vendor=wrs
;;
diff --git a/const_log2.c b/const_log2.c
index 9e5761203..5b4eef024 100644
--- a/const_log2.c
+++ b/const_log2.c
@@ -59,53 +59,53 @@ mpfr_const_aux_log2 (mpfr_ptr mylog, mp_rnd_t rnd_mode)
mp_prec_t prec;
mpfr_t tmp1, tmp2, result,tmp3;
mpz_t cst;
- int good = 0;
int logn;
mp_prec_t prec_i_want = MPFR_PREC(mylog);
mp_prec_t prec_x;
- int inexact;
+ int inexact = 0; /* here, 0 means not set */
- mpz_init(cst);
- logn = __gmpfr_ceil_log2 ((double) MPFR_PREC(mylog));
+ mpz_init (cst);
+ logn = __gmpfr_ceil_log2 ((double) MPFR_PREC(mylog));
prec_x = prec_i_want + logn;
- while (!good){
- prec = __gmpfr_ceil_log2 ((double) prec_x);
- mpfr_init2(tmp1, prec_x);
- mpfr_init2(result, prec_x);
- mpfr_init2(tmp2, prec_x);
- mpfr_init2(tmp3, prec_x);
- mpz_set_ui(cst, 1);
- mpfr_aux_log2(tmp1, cst, 4, prec-2);
- mpfr_div_2ui(tmp1, tmp1, 4, GMP_RNDD);
- mpfr_mul_ui(tmp1, tmp1, 15, GMP_RNDD);
-
- mpz_set_ui(cst, 3);
- mpfr_aux_log2(tmp2, cst, 7, prec-2);
- mpfr_div_2ui(tmp2, tmp2, 7, GMP_RNDD);
- mpfr_mul_ui(tmp2, tmp2, 5*3, GMP_RNDD);
- mpfr_sub(result, tmp1, tmp2, GMP_RNDD);
-
- mpz_set_ui(cst, 13);
- mpfr_aux_log2(tmp3, cst, 8, prec-2);
- mpfr_div_2ui(tmp3, tmp3, 8, GMP_RNDD);
- mpfr_mul_ui(tmp3, tmp3, 3*13, GMP_RNDD);
- mpfr_sub(result, result, tmp3, GMP_RNDD);
-
- mpfr_clear(tmp1);
- mpfr_clear(tmp2);
- mpfr_clear(tmp3);
- if (mpfr_can_round (result, prec_x, GMP_RNDD, GMP_RNDZ,
- prec_i_want + (rnd_mode == GMP_RNDN)))
- {
- inexact = mpfr_set (mylog, result, rnd_mode);
- good = 1;
- }
- else
- {
- prec_x += logn;
- }
- mpfr_clear (result);
- }
+ while (!inexact)
+ {
+ prec = __gmpfr_ceil_log2 ((double) prec_x);
+ mpfr_init2 (tmp1, prec_x);
+ mpfr_init2 (result, prec_x);
+ mpfr_init2 (tmp2, prec_x);
+ mpfr_init2 (tmp3, prec_x);
+ mpz_set_ui (cst, 1);
+ mpfr_aux_log2 (tmp1, cst, 4, prec-2);
+ mpfr_div_2ui (tmp1, tmp1, 4, GMP_RNDD);
+ mpfr_mul_ui (tmp1, tmp1, 15, GMP_RNDD);
+
+ mpz_set_ui (cst, 3);
+ mpfr_aux_log2 (tmp2, cst, 7, prec-2);
+ mpfr_div_2ui (tmp2, tmp2, 7, GMP_RNDD);
+ mpfr_mul_ui (tmp2, tmp2, 5*3, GMP_RNDD);
+ mpfr_sub (result, tmp1, tmp2, GMP_RNDD);
+
+ mpz_set_ui (cst, 13);
+ mpfr_aux_log2 (tmp3, cst, 8, prec-2);
+ mpfr_div_2ui (tmp3, tmp3, 8, GMP_RNDD);
+ mpfr_mul_ui (tmp3, tmp3, 3*13, GMP_RNDD);
+ mpfr_sub (result, result, tmp3, GMP_RNDD);
+
+ mpfr_clear (tmp1);
+ mpfr_clear (tmp2);
+ mpfr_clear (tmp3);
+ if (mpfr_can_round (result, prec_x, GMP_RNDD, GMP_RNDZ,
+ prec_i_want + (rnd_mode == GMP_RNDN)))
+ {
+ inexact = mpfr_set (mylog, result, rnd_mode);
+ MPFR_ASSERTN (inexact != 0);
+ }
+ else
+ {
+ prec_x += logn;
+ }
+ mpfr_clear (result);
+ }
mpz_clear (cst);
return inexact;
}
@@ -170,7 +170,7 @@ mpfr_const_log2 (mpfr_ptr x, mp_rnd_t rnd_mode)
mpz_add (s, s, u);
}
- mpfr_set_z (x, s, rnd_mode);
+ inexact = mpfr_set_z (x, s, rnd_mode);
MPFR_SET_EXP (x, MPFR_GET_EXP (x) - N);
mpz_clear (s);
mpz_clear (t);
diff --git a/const_pi.c b/const_pi.c
index e97bc02f6..7c7034d0d 100644
--- a/const_pi.c
+++ b/const_pi.c
@@ -19,8 +19,6 @@ 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 <stdio.h>
-#include <stdlib.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
@@ -47,17 +45,17 @@ static int
mpfr_pi_machin3 (mpfr_ptr mylog, mp_rnd_t rnd_mode)
{
int prec, logn, prec_x;
- int prec_i_want=MPFR_PREC(mylog);
- int good = 0;
- mpfr_t tmp1, tmp2, result,tmp3,tmp4,tmp5,tmp6;
+ int prec_i_want;
+ mpfr_t tmp1, tmp2, result, tmp3, tmp4, tmp5, tmp6;
mpz_t cst;
- int inex;
+ int inex = 0; /* here, 0 means not set */
- MPFR_CLEAR_FLAGS(mylog);
- logn = __gmpfr_ceil_log2 ((double) MPFR_PREC(mylog));
+ MPFR_CLEAR_FLAGS (mylog);
+ prec_i_want = MPFR_PREC (mylog);
+ logn = __gmpfr_ceil_log2 ((double) prec_i_want);
prec_x = prec_i_want + logn + 5;
- mpz_init(cst);
- while (!good)
+ mpz_init (cst);
+ while (!inex)
{
prec = __gmpfr_ceil_log2 ((double) prec_x);
@@ -110,7 +108,7 @@ mpfr_pi_machin3 (mpfr_ptr mylog, mp_rnd_t rnd_mode)
prec_i_want + (rnd_mode == GMP_RNDN)))
{
inex = mpfr_set (mylog, result, rnd_mode);
- good = 1;
+ MPFR_ASSERTN (inex != 0);
}
else
{
@@ -218,15 +216,11 @@ mpfr_const_pi (mpfr_ptr x, mp_rnd_t rnd_mode)
mpz_fdiv_q(tmp, tmp, den);
mpz_add(pi, pi, tmp);
}
- mpfr_set_z (x, pi, rnd_mode);
+ inex = mpfr_set_z (x, pi, rnd_mode);
mpfr_init2 (y, mpfr_get_prec(x));
mpz_add_ui (pi, pi, N+1);
mpfr_set_z (y, pi, rnd_mode);
- if (mpfr_cmp (x, y) != 0)
- {
- fprintf(stderr, "does not converge\n");
- exit(1);
- }
+ MPFR_ASSERTN (mpfr_cmp (x, y) == 0);
MPFR_SET_EXP (x, MPFR_GET_EXP(x) - 4*N);
mpz_clear(pi);
mpz_clear(num);
diff --git a/erf.c b/erf.c
index 600e0a6d9..8499ab260 100644
--- a/erf.c
+++ b/erf.c
@@ -29,14 +29,14 @@ MA 02111-1307, USA. */
#define EXP1 2.71828182845904523536 /* exp(1) */
-int mpfr_erf_0 _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
+int mpfr_erf_0 _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
#if 0
-int mpfr_erf_inf _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
+int mpfr_erf_inf _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
int mpfr_erfc_inf _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
#endif
-int
-mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
+int
+mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
double xf;
int sign_x;
@@ -80,11 +80,15 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (xf > n * LOG2) /* |erf x| = 1 or 1- */
{
- mpfr_set_ui (y, 1, rnd2);
- if (rnd2 == GMP_RNDD || rnd2 == GMP_RNDZ)
+ if (rnd2 == GMP_RNDN || rnd2 == GMP_RNDU)
{
- mpfr_sub_one_ulp (y, GMP_RNDZ); /* 1 - 2^(1-n) */
- mpfr_add_one_ulp (y, GMP_RNDU);
+ mpfr_set_ui (y, 1, rnd2);
+ inex = 1;
+ }
+ else
+ {
+ mpfr_setmax (y, 0);
+ inex = -1;
}
}
else /* use Taylor */
@@ -93,9 +97,14 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
}
if (sign_x < 0)
- MPFR_CHANGE_SIGN(y);
-
- return inex;
+ {
+ MPFR_CHANGE_SIGN (y);
+ return - inex;
+ }
+ else
+ {
+ return inex;
+ }
}
/* return x*2^e */
@@ -104,7 +113,7 @@ double mul_2exp (double x, mp_exp_t e)
{
if (e > 0)
{
- while (e--)
+ while (e--)
x *= 2.0;
}
else
@@ -123,8 +132,8 @@ double mul_2exp (double x, mp_exp_t e)
Assumes x is neither NaN nor infinite nor zero.
Assumes also that e*x^2 <= n (target precision).
*/
-int
-mpfr_erf_0 (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd_mode)
+int
+mpfr_erf_0 (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
mp_prec_t n, m;
mp_exp_t nuk, sigmak;
@@ -178,7 +187,7 @@ mpfr_erf_0 (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd_mode)
break;
/* tauk <- 1/2 + tauk * 2^sigmak + (1+8k)*2^nuk */
- tauk = 0.5 + mul_2exp (tauk, sigmak)
+ tauk = 0.5 + mul_2exp (tauk, sigmak)
+ mul_2exp (1.0 + 8.0 * (double) k, nuk);
}
@@ -224,7 +233,7 @@ mpfr_erf_0 (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd_mode)
f(x) >= f(sqrt(2/e)) ~ 0.7142767512, thus the final partial sum
should be > 0.5, and MPFR_EXP(s) should always be >= 0.
*/
-int
+int
mpfr_erfc_inf (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd)
{
mp_prec_t n, m;
@@ -236,7 +245,7 @@ mpfr_erfc_inf (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd)
double xf = mpfr_get_d1 (x);
n = MPFR_PREC(res); /* target precision */
-
+
mpfr_init2 (y, 2);
mpfr_init2 (s, 2);
mpfr_init2 (t, 2);
@@ -286,7 +295,7 @@ mpfr_erfc_inf (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd)
break;
/* tauk <- 1/2 + tauk * 2^sigmak + 2^(2k+2+nuk) */
- tauk = 0.5 + mul_2exp (tauk, sigmak)
+ tauk = 0.5 + mul_2exp (tauk, sigmak)
+ mul_2exp (1.0, 2 * k + 2 + nuk);
}
@@ -301,7 +310,7 @@ mpfr_erfc_inf (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd)
mpfr_sqrt (y, y, GMP_RNDD);
mpfr_mul (t, t, y, GMP_RNDN);
mpfr_div (s, s, t, GMP_RNDN);
-
+
/* final error bound on s */
tauk = mul_2exp (3.0, nuk + 5) + 2.0 * tauk + 115.0;
log2tauk = __gmpfr_ceil_log2 (tauk);
@@ -321,7 +330,7 @@ mpfr_erfc_inf (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd)
Assumes x is neither NaN nor infinite nor zero.
Assumes also that e*x^2 > n (target precision).
*/
-int
+int
mpfr_erf_inf (mpfr_ptr res, mpfr_srcptr x, mp_rnd_t rnd)
{
mp_prec_t n, m;
diff --git a/exp.c b/exp.c
index 9439b8e5e..2e17ff963 100644
--- a/exp.c
+++ b/exp.c
@@ -1,6 +1,6 @@
/* mpfr_exp -- exponential of a floating-point number
-Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation.
Contributed by the Spaces project.
This file is part of the MPFR Library.
@@ -78,14 +78,19 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
/* result is 0 when exp(x) < 1/2*2^(__gmpfr_emin), i.e.
x < (__gmpfr_emin-1) * LOG2 */
if (d < ((double) __gmpfr_emin - 1.0) * LOG2)
- return mpfr_set_underflow (y, rnd_mode, 1);
+ {
+ /* warning: mpfr_set_underflow rounds away for RNDN */
+ if (rnd_mode == GMP_RNDN && d < ((double) __gmpfr_emin - 2.0) * LOG2)
+ rnd_mode = GMP_RNDZ;
+ return mpfr_set_underflow (y, rnd_mode, 1);
+ }
/* if x < 2^(-precy), then exp(x) i.e. gives 1 +/- 1 ulp(1) */
if (expx < -precy)
{
int signx = MPFR_SIGN(x);
- if (signx < 0 && (rnd_mode == GMP_RNDD || rnd_mode == GMP_RNDZ))
+ if (signx < 0 && rnd_mode == GMP_RNDD)
{
MPFR_CLEAR_FLAGS(y);
MPFR_SET_POS(y);
diff --git a/factorial.c b/factorial.c
index 4ee38414b..1c2b71a37 100644
--- a/factorial.c
+++ b/factorial.c
@@ -1,6 +1,6 @@
/* mpfr_fac_ui -- factorial of a non-negative integer
-Copyright 2001 Free Software Foundation, Inc.
+Copyright 2001, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -36,38 +36,40 @@ mpfr_fac_ui (mpfr_ptr y, unsigned long int x , mp_rnd_t rnd_mode)
/****** Declaration ******/
mpfr_t t; /* Variable of Intermediary Calculation*/
- int i;
+ unsigned long i;
int round, inexact = 0;
- int boucle = 1;
+ int loop = 1;
mp_prec_t Ny; /* Precision of output variable */
mp_prec_t Nt; /* Precision of Intermediary Calculation variable */
mp_prec_t err; /* Precision of error */
+ mp_rnd_t rnd;
+
/***** test x = 0 ******/
if (x == 0)
{
- mpfr_set_ui (y, 1, GMP_RNDN); /* 0! = 1 */
- return 0;
+ return mpfr_set_ui (y, 1, GMP_RNDN); /* 0! = 1 */
}
else
{
/* Initialisation of the Precision */
- Ny=MPFR_PREC(y);
+ Ny = MPFR_PREC(y);
- Nt=Ny+2*(int)__gmpfr_ceil_log2((double)x)+10; /*compute the size of intermediary variable */
-
+ /* compute the size of intermediary variable */
+ Nt = Ny + 2 * (int) __gmpfr_ceil_log2 ((double) x) + 10;
- mpfr_init2(t, Nt);/* initialise of intermediary variable */
+ mpfr_init2 (t, Nt); /* initialise of intermediary variable */
- while (boucle)
+ rnd = GMP_RNDZ;
+ while (loop)
{
- inexact = mpfr_set_ui (t, 1, GMP_RNDZ);
+ inexact = mpfr_set_ui (t, 1, rnd);
- for(i=2;i<=x;i++) /* compute factorial */
+ for (i=2; i<=x; i++) /* compute factorial */
{
- round = mpfr_mul_ui (t, t, i, GMP_RNDZ);
+ round = mpfr_mul_ui (t, t, i, rnd);
/* assume the first inexact product gives the sign
of difference: is that always correct? */
if (inexact == 0)
@@ -76,22 +78,41 @@ mpfr_fac_ui (mpfr_ptr y, unsigned long int x , mp_rnd_t rnd_mode)
err = Nt - 1 - (int) __gmpfr_ceil_log2 ((double) Nt);
- round = !inexact || mpfr_can_round (t, err, GMP_RNDZ, GMP_RNDZ,
+ round = !inexact || mpfr_can_round (t, err, rnd, GMP_RNDZ,
Ny + (rnd_mode == GMP_RNDN));
if (round)
{
+ /* If inexact = 0, then t is exactly x!, so round is the
+ correct inexact flag.
+ Otherwise, t != x! since we rounded to zero or away. */
round = mpfr_set (y, t, rnd_mode);
- if (inexact == 0)
+ if (inexact == 0)
+ {
inexact = round;
- boucle = 0;
- }
- else
- {
- Nt = Nt + 10;
- /*initialise of intermediary variable */
- mpfr_set_prec (t, Nt);
- }
+ loop = 0;
+ }
+ else if ((inexact < 0 && round <= 0) ||
+ (inexact > 0 && round >= 0))
+ {
+ loop = 0;
+ }
+ else /* inexact and round have opposite signs: we cannot
+ compute the inexact flag. Restart using the
+ symmetric rounding. */
+ {
+ rnd = (rnd == GMP_RNDZ) ? GMP_RNDU : GMP_RNDZ;
+ Nt = Nt + 10;
+ /*initialise of intermediary variable */
+ mpfr_set_prec (t, Nt);
+ }
+ }
+ else
+ {
+ Nt = Nt + 10;
+ /*initialise of intermediary variable */
+ mpfr_set_prec (t, Nt);
+ }
}
mpfr_clear (t);
diff --git a/frac.c b/frac.c
index fd4e99a7f..c80e04295 100644
--- a/frac.c
+++ b/frac.c
@@ -1,6 +1,6 @@
/* mpfr_frac -- Fractional part of a floating-point number.
-Copyright 2002, 2003 Free Software Foundation, Inc.
+Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -25,6 +25,9 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
+/* Optimization note: it is not a good idea to call mpfr_integer_p,
+ as some cases will take longer (the number may be parsed twice). */
+
int
mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
{
@@ -52,7 +55,7 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
ue = MPFR_GET_EXP (u);
if (ue <= 0) /* |u| < 1 */
- return mpfr_set(r, u, rnd_mode);
+ return mpfr_set (r, u, rnd_mode);
uq = MPFR_PREC(u);
un = (uq - 1) / BITS_PER_MP_LIMB; /* index of most significant limb */
@@ -62,33 +65,40 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
up = MPFR_MANT(u);
sh = ue % BITS_PER_MP_LIMB;
k = up[un] << sh;
+ /* the first bit of the fractional part is the MSB of k */
if (k != 0)
{
int cnt;
count_leading_zeros(cnt, k);
+ /* first bit 1 of the fractional part -> MSB of the number */
re = -cnt;
sh += cnt;
+ MPFR_ASSERTN (sh < BITS_PER_MP_LIMB);
k <<= cnt;
}
else
{
re = sh - BITS_PER_MP_LIMB;
- while ((k = up[--un]) == 0)
+ /* searching for the first bit 1 (exists since u isn't an integer) */
+ while (up[--un] == 0)
re -= BITS_PER_MP_LIMB;
MPFR_ASSERTN(un >= 0);
+ k = up[un];
count_leading_zeros(sh, k);
re -= sh;
k <<= sh;
}
/* The exponent of r will be re */
+ /* un: index of the limb of u that contains the first bit 1 of the FP */
ue -= re; /* number of bits of u to discard */
fq = uq - ue; /* number of bits of the fractional part of u */
- t = fq > MPFR_PREC(r) ?
- (mpfr_init2(tmp, (un + 1) * BITS_PER_MP_LIMB), tmp) : r;
+ /* Temporary fix */
+ t = /* fq > MPFR_PREC(r) */ (MPFR_PREC(r) - 1) / BITS_PER_MP_LIMB < un ?
+ (mpfr_init2 (tmp, (un + 1) * BITS_PER_MP_LIMB), tmp) : r;
/* t has enough precision to contain the fractional part of u */
/* If we use a temporary variable, we take the non-significant bits
of u into account, because of the mpn_lshift below. */
@@ -103,8 +113,8 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
tp = MPFR_MANT(t);
if (sh == 0)
MPN_COPY_DECR(tp + t0, up, un + 1);
- else
- tp[tn] = k | mpn_lshift(tp + t0, up, un, sh);
+ else /* warning: un may be 0 here */
+ tp[tn] = k | ((un) ? mpn_lshift (tp + t0, up, un, sh) : (mp_limb_t) 0);
if (t0 > 0)
MPN_ZERO(tp, t0);
@@ -112,8 +122,8 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
{ /* t is tmp */
int inex;
- inex = mpfr_set(r, t, rnd_mode);
- mpfr_clear(t);
+ inex = mpfr_set (r, t, rnd_mode);
+ mpfr_clear (t);
return inex;
}
else
diff --git a/from_Torbjorn b/from_Torbjorn
deleted file mode 100644
index 147c7b03f..000000000
--- a/from_Torbjorn
+++ /dev/null
@@ -1,28 +0,0 @@
-Return-Path: <tege@matematik.su.se>
-X-Address: Department of Mathematics, Stockholm University
- S-106 91 Stockholm
- SWEDEN
-X-Phone: int+46 8 162000
-X-Fax: int+46 8 6126717
-X-Url: http://www.matematik.su.se
-To: Paul.Zimmermann@loria.fr (Paul Zimmermann)
-Subject: Re: Paul Zimmermann: changing rounding mode on Alpha with gcc
-In-reply-to: Your message of "Wed, 17 Feb 1999 17:44:33 +0100."
- <199902171644.RAA03746@leopold.loria.fr>
-Date: Wed, 17 Feb 1999 19:21:05 +0100
-From: Torbjorn Granlund <tege@matematik.su.se>
-
- I once thought I had found a bug, but it was only the peculiar rounding
- to nearest rule when we are just in the middle of two machine number,
- where we round to the even lsb instead of rounding to infinity as we do
- in math.
-
-Been there... ;-) Note that it is simple to get this right with a single
-logical expression. Perhaps this code,
-
- roundup = (((m >> (EXP_BITS - 1)) & 1)
- & (((m & STICKY_MASK) != 0) | ((m >> EXP_BITS) & 1)));
-
-from my P754 library shows the idea.
-
-Tobjörn
diff --git a/gamma.c b/gamma.c
index 5da283b02..498188e07 100644
--- a/gamma.c
+++ b/gamma.c
@@ -1,6 +1,6 @@
/* mpfr_gamma -- gamma function
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library, and was contributed by Mathieu Dutour.
@@ -50,12 +50,11 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode)
mp_prec_t Prec;
mp_prec_t prec_gamma;
mp_prec_t prec_nec;
- int good = 0;
double C;
mp_prec_t A, N, estimated_cancel;
mp_prec_t realprec;
int compared;
- int k;
+ unsigned long k;
int sign;
int inex;
@@ -96,17 +95,33 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (compared == 0)
return mpfr_set_ui (gamma, 1, rnd_mode);
+ /* if x is an integer that fits into an unsigned long, use mpfr_fac_ui */
+ if (mpfr_integer_p (x))
+ {
+ unsigned long int u;
+ u = mpfr_get_ui (x, GMP_RNDN);
+ /* u = 0 when x is 0 or x does not fit in an unsigned long */
+ if (u != 0)
+ return mpfr_fac_ui (gamma, u - 1, rnd_mode);
+ }
+
realprec = prec_gamma + 10;
mpfr_init2 (xp, 2);
-
- while (!good)
+ /* Initialisation */
+ mpfr_init (tmp);
+ mpfr_init (tmp2);
+ mpfr_init (the_pi);
+ mpfr_init (product);
+ mpfr_init (GammaTrial);
+
+ while (1)
{
/* Precision stuff */
prec_nec = compared < 0 ?
2 + realprec /* We will use the reflexion formula! */
: realprec;
- C = (double)(((double) prec_nec)*CST-0.5);
+ C = (double) (((double) prec_nec) * CST - 0.5);
A = (mp_prec_t) C;
N = A - 1;
#ifdef DEBUG
@@ -130,31 +145,31 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode)
mpfr_sub_ui (xp, x, 1, GMP_RNDN);
}
- /* Initialisation */
- mpfr_init2(tmp, Prec);
- mpfr_init2(tmp2, Prec);
- mpfr_init2(the_pi, Prec);
- mpfr_init2(product, Prec);
- mpfr_init2(GammaTrial, Prec);
+ /* Set prec */
+ mpfr_set_prec (tmp, Prec);
+ mpfr_set_prec (tmp2, Prec);
+ mpfr_set_prec (the_pi, Prec);
+ mpfr_set_prec (product, Prec);
+ mpfr_set_prec (GammaTrial, Prec);
- mpfr_set_ui(GammaTrial, 0, GMP_RNDN);
+ mpfr_set_ui (GammaTrial, 0, GMP_RNDN);
sign = 1;
for (k = 1; k <= N; k++)
{
- mpfr_set_ui(tmp, A-k, GMP_RNDN);
- mpfr_exp(product, tmp, GMP_RNDN);
- mpfr_ui_pow_ui(tmp, A-k, k-1, GMP_RNDN);
- mpfr_mul(product, product, tmp, GMP_RNDN);
- mpfr_sqrt_ui(tmp, A-k, GMP_RNDN);
- mpfr_mul(product, product, tmp, GMP_RNDN);
- mpfr_fac_ui(tmp, k-1, GMP_RNDN);
- mpfr_div(product, product, tmp, GMP_RNDN);
- mpfr_add_ui(tmp, xp, k, GMP_RNDN);
- mpfr_div(product, product, tmp, GMP_RNDN);
+ mpfr_set_ui (tmp, A - k, GMP_RNDN);
+ mpfr_exp (product, tmp, GMP_RNDN);
+ mpfr_ui_pow_ui (tmp, A - k, k - 1, GMP_RNDN);
+ mpfr_mul (product, product, tmp, GMP_RNDN);
+ mpfr_sqrt_ui (tmp, A - k, GMP_RNDN);
+ mpfr_mul (product, product, tmp, GMP_RNDN);
+ mpfr_fac_ui (tmp, k - 1, GMP_RNDN);
+ mpfr_div (product, product, tmp, GMP_RNDN);
+ mpfr_add_ui (tmp, xp, k, GMP_RNDN);
+ mpfr_div (product, product, tmp, GMP_RNDN);
sign = -sign;
if (sign == 1)
{
- mpfr_neg(product, product, GMP_RNDN);
+ mpfr_neg (product, product, GMP_RNDN);
#ifdef DEBUG
/* printf(" k=%u", k);
printf("\n");*/
@@ -194,25 +209,24 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode)
mpfr_out_str (stdout, 10, 0, GammaTrial, GMP_RNDD);
printf ("\n");
#endif
- if (mpfr_can_round (GammaTrial, realprec, GMP_RNDD, GMP_RNDZ,
+ if (!mpfr_can_round (GammaTrial, realprec, GMP_RNDD, GMP_RNDZ,
MPFR_PREC(gamma) + (rnd_mode == GMP_RNDN)))
{
- inex = mpfr_set (gamma, GammaTrial, rnd_mode);
- good = 1;
- }
- else
- {
realprec += __gmpfr_ceil_log2 ((double) realprec);
#ifdef DEBUG
printf("RETRY\n");
#endif
}
- mpfr_clear(tmp);
- mpfr_clear(tmp2);
- mpfr_clear(the_pi);
- mpfr_clear(product);
- mpfr_clear(GammaTrial);
+ else
+ break;
}
+ inex = mpfr_set (gamma, GammaTrial, rnd_mode);
+
+ mpfr_clear(tmp);
+ mpfr_clear(tmp2);
+ mpfr_clear(the_pi);
+ mpfr_clear(product);
+ mpfr_clear(GammaTrial);
mpfr_clear (xp);
diff --git a/gammaPiAGMformula.c b/gammaPiAGMformula.c
deleted file mode 100644
index 82f590c6e..000000000
--- a/gammaPiAGMformula.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/* mpfr_gamma -- gamma function
-
-Copyright 2001 Free Software Foundation.
-
-This file is part of the MPFR Library, and was contributed by Mathieu Dutour.
-
-The 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 2.1 of the License, or (at your
-option) any later version.
-
-The 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 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 <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
-#include "mpfr-impl.h"
-
-int mpfr_gamma _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
-
-/* We use the reflection formula
- Gamma(1+x)Gamma(1-x)=\pi x/(sin(\pi x))
- in order to treat the case x<=1 */
-
-#define CST 0.38 /* CST=ln(2)/(ln(2*pi)) */
-#define zCST 0.26 /* zCST=1/(2*ln(2*pi)) */
-
-
-int
-#if __STDC__
-mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode)
-#else
-mpfr_gamma (gamma, x, rnd_mode)
- mpfr_ptr gamma;
- mpfr_srcptr x;
- mp_rnd_t rnd_mode;
-#endif
-{
- mpfr_t xp;
- mpfr_t product;
- mpfr_t driv;
- mpfr_t xminusone;
- mpfr_t the_pi_constant;
- mpfr_t Csin, Ccos;
- mpfr_t GammaTrial;
- int reflex;
-
- mpfr_t tmp, tmp2;
- int Prec;
- int Prec_nec;
- int prec_gamma;
- int prec_nec;
- int good = 0;
- double C;
- long A, N;
- int realprec;
- int estimated_delta;
- int compared;
- int compar;
- int factorial_case;
- int k;
-
- /* Trivial cases */
- if (MPFR_IS_NAN(x))
- {
- MPFR_SET_NAN(gamma);
- return 1;
- }
- if (!MPFR_NOTZERO(x))
- {
- MPFR_SET_INF(gamma);
- return 1;
- }
- if (MPFR_IS_INF(x))
- {
- MPFR_SET_INF(gamma);
- return 1;
- }
- /* Set x_p=x if x> 1 else set x_p=2-x */
- prec_gamma = MPFR_PREC(gamma);
- compared = mpfr_cmp_ui(x, 1);
- if (compared == 0)
- {
- mpfr_set_ui(gamma, 1, rnd_mode);
- return 1;
- }
- if (compared == -1)
- {
- prec_nec = 2+prec_gamma;
- reflex = 1;
- return 1;
- }
- else
- {
- prec_nec = prec_gamma;
- reflex = 0;
- return 1;
- }
-
- realprec = prec_nec+10;
-
- while (!good){
- C = ((double) realprec)*CST-0.5;
- A = (long) ceil(C-zCST*log(C));
- N = A-1;
- /* Compute the correct estimated_delta as a function of realprec */
- Prec = realprec+estimated_delta;
- mpfr_init2(xp, Prec);
- if (compared == -1)
- {
- mpfr_ui_sub(xp, 2, x, GMP_RNDN);
- }
- else
- {
- mpfr_set(xp, x, GMP_RNDN);
- }
- /* Initialisation */
- mpfr_init2(product, Prec);
- mpfr_init2(driv, Prec);
- mpfr_init2(tmp, Prec);
- mpfr_set(driv, xp, GMP_RNDN);
- mpfr_set_ui(product, 1, GMP_RNDN);
-
- /* We use a naugthy algorithm to reduce to the domain 1<=x <2*/
- while (1)
- {
- compar = mpfr_cmp_ui(driv, 2);
- if (compar == 0) /* the factorial in fact */
- {
- mpfr_mul_ui(GammaTrial, product, 2, GMP_RNDN);
- factorial_case = 1;
- break;
- }
- if (compar == -1)
- {
- factorial_case = 0;
- break;
- }
- mpfr_sub_ui(driv, driv, 1, GMP_RNDN);
- mpfr_mul(product, product, driv, GMP_RNDN);
- }
- /* now we run into the trivial case */
- if (factorial_case == 0 && reflex == 1)
- {
- mpfr_clear(product);
- mpfr_clear(driv);
- mpfr_clear(tmp);
- MPFR_SET_INF(gamma);
- return 1;
- }
- mpfr_init2(GammaTrial, Prec);
- if (factorial_case == 0)
- {
- /* compute the Gamma for 1< driv < 2 */
- mpfr_init2(tmp2, Prec);
-
- mpfr_add_ui(tmp2, driv,6*N, GMP_RNDN);
- mpfr_ui_div(tmp, 1, tmp2, GMP_RNDN);
- for(k=6*N; k>=1; k--)
- {
- mpfr_mul_ui(tmp, tmp, N, GMP_RNDN);
- mpfr_neg(tmp, tmp, GMP_RNDN);
- mpfr_div_ui(tmp, tmp, k, GMP_RNDN);
-
- mpfr_add_ui(tmp2, driv, k-1, GMP_RNDN);
- mpfr_ui_div(tmp2, 1, tmp2, GMP_RNDN);
- mpfr_add(tmp, tmp, tmp2, GMP_RNDN);
- }
- mpfr_set_ui(tmp2, N, GMP_RNDN);
- mpfr_log(tmp2, tmp2, GMP_RNDN);
- mpfr_mul(tmp2, tmp2, driv, GMP_RNDN);
- mpfr_exp(tmp2, tmp2, GMP_RNDN);
- mpfr_mul(tmp, tmp2, tmp, GMP_RNDN);
- mpfr_mul(GammaTrial, tmp, product, GMP_RNDN);
- }
- if (reflex == 1)
- {
- mpfr_init2(xminusone, Prec);
- mpfr_init2(Csin, Prec);
- mpfr_init2(Ccos, Prec);
- mpfr_sub_ui(xminusone, x, 1, GMP_RNDN);
- mpfr_const_pi(the_pi_constant, Prec_nec);
- mpfr_mul(tmp, the_pi_constant, xminusone, GMP_RNDN);
- mpfr_sin(Csin, tmp, GMP_RNDN);
- mpfr_cos(Ccos, tmp, GMP_RNDN);
- mpfr_div(tmp, tmp, Csin, GMP_RNDN);
- mpfr_neg(tmp, tmp, GMP_RNDN);
- mpfr_div(GammaTrial, tmp, GammaTrial, GMP_RNDN);
- }
- if (mpfr_can_round(GammaTrial, realprec, GMP_RNDD, rnd_mode, MPFR_PREC(gamma)))
- {
- mpfr_set(gamma, GammaTrial, rnd_mode);
- good = 1;
- }
- else
- {
- realprec += __gmpfr_ceil_log2 ((double) realprec);
-#ifdef DEBUG
- printf("RETRY\n");
-#endif
- }
- mpfr_clear(tmp);
- mpfr_clear(driv);
- mpfr_clear(product);
- mpfr_clear(GammaTrial);
- if (reflex == 1)
- {
- mpfr_clear(xminusone);
- mpfr_clear(Csin);
- mpfr_clear(Ccos);
- }
- }
-
- mpfr_clear(xp);
-
- return 1; /* inexact result */
-}
-
diff --git a/get_str.c b/get_str.c
index fceaa066b..65ce78f0e 100644
--- a/get_str.c
+++ b/get_str.c
@@ -1,6 +1,6 @@
/* mpfr_get_str -- output a floating-point number to a string
-Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This function was contributed by Alain Delplanque and Paul Zimmermann.
This file is part of the MPFR Library.
@@ -24,20 +24,21 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <limits.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#include "mpfr.h"
#include "mpfr-impl.h"
-static double _mpfr_ceil _PROTO ((double));
+static double mpfr_ceil_double _PROTO ((double));
static int mpfr_get_str_aux _PROTO ((char *, mp_exp_t *, mp_limb_t *,
mp_size_t, mp_exp_t, long, int, size_t, mp_rnd_t));
static mp_exp_t mpfr_get_str_compute_g _PROTO ((int, mp_exp_t));
static char num_to_text[] = "0123456789abcdefghijklmnopqrstuvwxyz";
-/* for 2 <= b <= 36, log_b2[b-2] + log_b2_low[b-2] is a 76-bit upper
+/* for 2 <= b <= 36, log_b2[b-2] + log_b2_low[b-2] is a 76-bit upper
approximation of log(2)/log(b), with log_b2[b-2] having 23 significative
bits only. These approximations were computed with the following program.
@@ -177,9 +178,13 @@ static const double log_b2_low[35] = {
}
static double
-_mpfr_ceil (double x)
+mpfr_ceil_double (double x)
{
- double y = (double) (long int) x;
+ double y;
+ /* Note: this function should be rewritten to avoid the possible
+ overflow. */
+ MPFR_ASSERTN(x >= (double) LONG_MIN && x <= (double) LONG_MAX);
+ y = (double) (long int) x;
return ((y < x) ? y + 1.0 : y);
}
@@ -188,7 +193,7 @@ _mpfr_ceil (double x)
It returns an integer f such that the final error is bounded by 2^f ulps,
that is:
a*2^exp_r <= b^e <= 2^exp_r (a + 2^f),
- where a represents {a, n}, i.e. the integer
+ where a represents {a, n}, i.e. the integer
a[0] + a[1]*B + ... + a[n-1]*B^(n-1) where B=2^BITS_PER_MP_LIMB */
long
mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n)
@@ -285,13 +290,13 @@ mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n)
}
if ((erreur == t) && (c[n - 1] != 0))
erreur = i;
-
+
}
}
TMP_FREE(marker);
- *exp_r = f;
+ *exp_r = f;
if (erreur == t)
return -1; /* exact */
@@ -306,17 +311,17 @@ mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n)
if ((erreur - 1) >= ((n * BITS_PER_MP_LIMB - 1) / 2))
erreur = n * BITS_PER_MP_LIMB; /* completely wrong: this is very
unlikely to happen since erreur is
- at most 5/2*log_2(e), and
+ at most 5/2*log_2(e), and
n * BITS_PER_MP_LIMB is at least
3*log_2(e) */
}
- return erreur;
+ return erreur;
}
/* Input: an approximation r*2^f of an real Y, with |r*2^f-Y| <= 2^(e+f).
- Returns if possible in the string s the mantissa corresponding to
+ Returns if possible in the string s the mantissa corresponding to
the integer nearest to Y, within the direction rnd, and returns the
the exponent in exp.
n is the number of limbs of r.
@@ -325,7 +330,7 @@ mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n)
b is the wanted base (2 <= b <= 36).
m is the number of wanted digits in the mantissa.
rnd is the rounding mode.
- It is assumed that b^(m-1) <= Y < b^(m+1), thus the returned value
+ It is assumed that b^(m-1) <= Y < b^(m+1), thus the returned value
satisfies b^(m-1) <= rnd(Y) < b^(m+1).
Return value:
@@ -416,18 +421,18 @@ mpfr_get_str_aux (char *str, mp_exp_t *exp, mp_limb_t *r, mp_size_t n,
/* if size_s1 = m + 2, necessarily we have b^(m+1) as result,
and the result will not change */
- /* so we have to double-round only when size_s1 = m + 1 and
- (i) the result is inexact
+ /* so we have to double-round only when size_s1 = m + 1 and
+ (i) the result is inexact
(ii) or the last digit is non-zero */
if ((size_s1 == m + 1) && ((dir != 0) || (str1[size_s1 - 1] != 0)))
{
/* rounding mode */
- rnd1 = rnd;
+ rnd1 = rnd;
/* round to nearest case */
- if (rnd == GMP_RNDN)
+ if (rnd == GMP_RNDN)
{
- if (2 * str1[size_s1 - 1] == b)
+ if (2 * str1[size_s1 - 1] == b)
{
if (dir == -1)
rnd1 = GMP_RNDU;
@@ -468,7 +473,7 @@ mpfr_get_str_aux (char *str, mp_exp_t *exp, mp_limb_t *r, mp_size_t n,
}
str1[i]++;
}
- dir = 1;
+ dir = 1;
}
/* round toward zero (truncate) */
else
@@ -486,7 +491,7 @@ mpfr_get_str_aux (char *str, mp_exp_t *exp, mp_limb_t *r, mp_size_t n,
cannot_round:
dir = 2;
}
-
+
TMP_FREE(marker);
return (dir);
@@ -498,12 +503,12 @@ mpfr_get_str_compute_g (int beta, mp_exp_t e)
{
double g0, g1;
mp_exp_t g;
-
+
g0 = (double) e * log_b2[beta - 2];
g1 = (double) e * log_b2_low[beta - 2];
- g = (mp_exp_t) _mpfr_ceil (g0);
+ g = (mp_exp_t) mpfr_ceil_double (g0);
g0 -= (double) g;
- return g + (mp_exp_t) _mpfr_ceil (g0 + g1);
+ return g + (mp_exp_t) mpfr_ceil_double (g0 + g1);
}
/* prints the mantissa of x in the string s, and writes the corresponding
@@ -525,7 +530,7 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
int exact; /* exact result */
mp_exp_t exp, g;
mp_exp_t prec, log_2prec; /* precision of the computation */
- long err;
+ long err;
mp_limb_t *a;
mp_exp_t exp_a;
mp_limb_t *result;
@@ -547,8 +552,25 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
if (m == 0)
{
- m = (size_t) _mpfr_ceil (__mp_bases[b].chars_per_bit_exactly
- * (double) MPFR_PREC(x));
+
+ m = MPFR_PREC(x);
+ if (IS_POW2(b) && b >= 4)
+ /* when the base is a power of two, we can compute exactly the number
+ of digits sufficient to print the number exactly.
+ Warning: we may loose some bits in the first digit.
+ If EXP(x)=0, no bit is lost.
+ If EXP(x)=-1, one bit is lost... */
+ {
+ int k, lost;
+
+ count_leading_zeros (k, (mp_limb_t) b);
+ k = BITS_PER_MP_LIMB - k - 1; /* b = 2^k */
+ lost = (-MPFR_EXP(x)) % k;
+ if (lost < 0)
+ lost += k;
+ m += lost;
+ }
+ m = (size_t) mpfr_ceil_double (__mp_bases[b].chars_per_bit_exactly * (double) m);
if (m < 2)
m = 2;
}
@@ -590,16 +612,6 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
return s0; /* strlen(s0) = neg + m */
}
- /* si x < 0, on se ram`ene au cas x > 0 */
- if (neg)
- {
- switch (rnd)
- {
- case GMP_RNDU : rnd = GMP_RNDD; break;
- case GMP_RNDD : rnd = GMP_RNDU; break;
- }
- }
-
if (s == NULL)
s = (char*) (*__gmp_allocate_func) (neg + m + 1);
s0 = s;
@@ -618,7 +630,7 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
count_leading_zeros (pow2, (mp_limb_t) b);
pow2 = BITS_PER_MP_LIMB - pow2 - 1; /* base = 2^pow2 */
-
+
/* set MPFR_EXP(x) = f*pow2 + r, 1 <= r <= pow2 */
f = (MPFR_GET_EXP (x) - 1) / pow2;
r = MPFR_GET_EXP (x) - f * pow2;
@@ -651,7 +663,7 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
else /* 2^prec needs still m digits, but x1 may need n+1 limbs */
n ++;
}
-
+
/* it remains to shift x1 by nb limbs to the right, since mpn_get_str
expects a right-normalized number */
if (nb != 0)
@@ -661,7 +673,7 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
if (x1[n - 1] == 0)
n --;
}
-
+
mpn_get_str ((unsigned char*) s, b, x1, n);
for (i=0; i<m; i++)
s[i] = num_to_text[(int) s[i]];
@@ -675,9 +687,13 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
return (s0);
}
+ /* if x < 0, reduce to x > 0 */
+ if (neg)
+ rnd = (rnd == GMP_RNDU ? GMP_RNDD : (rnd == GMP_RNDD ? GMP_RNDU : rnd));
+
g = mpfr_get_str_compute_g (b, MPFR_GET_EXP (x) - 1);
exact = 1;
- prec = (mp_exp_t) _mpfr_ceil ((double) m / log_b2[b-2]) + 1;
+ prec = (mp_exp_t) mpfr_ceil_double ((double) m / log_b2[b-2]) + 1;
exp = ((mp_exp_t) m < g) ? g - (mp_exp_t) m : (mp_exp_t) m - g;
log_2prec = (mp_exp_t) __gmpfr_ceil_log2 ((double) prec);
prec += log_2prec; /* number of guard bits */
@@ -720,13 +736,13 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd
/* test si exact */
if (nx > n)
- exact = (exact &&
+ exact = (exact &&
((mpn_scan1 (xp, 0) >= (nx - n) * BITS_PER_MP_LIMB)));
/* we loose one more bit in the multiplication,
except when err=0 where we loose two bits */
err = (err <= 0) ? 2 : err + 1;
-
+
/* result = a * x */
result = (mp_limb_t*) TMP_ALLOC ((n + nx1) * sizeof (mp_limb_t));
mpn_mul (result, a, n, x1, nx1);
diff --git a/gmp_op.c b/gmp_op.c
index d675db8e9..a911e3b35 100644
--- a/gmp_op.c
+++ b/gmp_op.c
@@ -1,6 +1,6 @@
-/* mpfr_cos -- cosine of a floating-point number
+/* Implementations of operations between mpfr and mpz/mpq data
-Copyright 2001 Free Software Foundation, Inc.
+Copyright 2001, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -19,104 +19,206 @@ 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 <stdio.h>
+#include <stddef.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "mpfr.h"
#include "mpfr-impl.h"
-int
-mpfr_mul_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z,mp_rnd_t rnd_mode)
+int
+mpfr_mul_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z,mp_rnd_t rnd_mode)
{
mpfr_t t;
int res;
- mpfr_init(t);
- mpfr_set_z(t,z,rnd_mode);
- res=mpfr_mul(y,x,t,rnd_mode);
+ mpfr_init2(t, mpz_sizeinbase(z, 2) );
+ res = mpfr_set_z(t, z, rnd_mode);
+ MPFR_ASSERTD(res == 0);
+ res = mpfr_mul(y, x, t, rnd_mode);
mpfr_clear(t);
return(res);
}
-int
-mpfr_div_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z, mp_rnd_t rnd_mode)
+int
+mpfr_div_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z, mp_rnd_t rnd_mode)
{
mpfr_t t;
int res;
- mpfr_init(t);
- mpfr_set_z(t,z,rnd_mode);
- res=mpfr_div(y,x,t,rnd_mode);
+ mpfr_init2(t, mpz_sizeinbase(z, 2) );
+ res = mpfr_set_z(t, z, rnd_mode);
+ MPFR_ASSERTD(res == 0);
+ res = mpfr_div(y, x, t, rnd_mode);
mpfr_clear(t);
return(res);
}
-int
-mpfr_add_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z, mp_rnd_t rnd_mode)
+int
+mpfr_add_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z, mp_rnd_t rnd_mode)
{
mpfr_t t;
int res;
- mpfr_init(t);
- mpfr_set_z(t,z,rnd_mode);
- res=mpfr_add(y,x,t,rnd_mode);
+ mpfr_init2(t, mpz_sizeinbase(z, 2) );
+ res = mpfr_set_z(t, z, rnd_mode);
+ MPFR_ASSERTD(res == 0);
+ res = mpfr_add(y, x, t, rnd_mode);
mpfr_clear(t);
return(res);
}
-int
-mpfr_sub_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z,mp_rnd_t rnd_mode)
+int
+mpfr_sub_z (mpfr_ptr y, mpfr_srcptr x, mpz_srcptr z,mp_rnd_t rnd_mode)
{
mpfr_t t;
int res;
- mpfr_init(t);
- mpfr_set_z(t,z,rnd_mode);
- res=mpfr_sub(y,x,t,rnd_mode);
+ mpfr_init2(t, mpz_sizeinbase(z, 2) );
+ res = mpfr_set_z(t, z, rnd_mode);
+ MPFR_ASSERTD(res == 0);
+ res=mpfr_sub(y, x, t, rnd_mode);
mpfr_clear(t);
return(res);
}
-int
-mpfr_mul_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode)
+int
+mpfr_mul_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode)
{
- mpfr_t t;
+ mpfr_t tmp;
int res;
- mpfr_init(t);
- mpfr_set_q(t,z,rnd_mode);
- res=mpfr_mul(y,x,t,rnd_mode);
- mpfr_clear(t);
+
+ mpfr_init2 (tmp, MPFR_PREC(x) + mpz_sizeinbase(mpq_numref(z), 2) );
+ res = mpfr_mul_z (tmp, x, mpq_numref(z), GMP_RNDN );
+ MPFR_ASSERTD( res == 0 );
+ res = mpfr_div_z (y, tmp, mpq_denref(z), rnd_mode);
+ mpfr_clear(tmp);
return(res);
}
-int
-mpfr_div_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z, mp_rnd_t rnd_mode)
+int
+mpfr_div_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z, mp_rnd_t rnd_mode)
{
- mpfr_t t;
+ mpfr_t tmp;
int res;
- mpfr_init(t);
- mpfr_set_q(t,z,rnd_mode);
- res=mpfr_div(y,x,t,rnd_mode);
- mpfr_clear(t);
+
+ mpfr_init2 (tmp, MPFR_PREC(x) + mpz_sizeinbase(mpq_denref(z), 2) );
+ res = mpfr_mul_z (tmp, x, mpq_denref(z), GMP_RNDN );
+ MPFR_ASSERTD( res == 0 );
+ res = mpfr_div_z (y, tmp, mpq_numref(z), rnd_mode);
+ mpfr_clear(tmp);
return(res);
}
-int
-mpfr_add_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z, mp_rnd_t rnd_mode)
+int
+mpfr_add_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z, mp_rnd_t rnd_mode)
{
- mpfr_t t;
+ mpfr_t t,q;
+ mp_prec_t p = MPFR_PREC(y)+10;
+ mp_exp_t err;
int res;
- mpfr_init(t);
- mpfr_set_q(t,z,rnd_mode);
- res=mpfr_add(y,x,t,rnd_mode);
- mpfr_clear(t);
- return(res);
+
+ if (MPFR_IS_NAN(x))
+ {
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
+ }
+ else if (MPFR_IS_INF(x))
+ {
+ MPFR_CLEAR_NAN (y);
+ MPFR_SET_INF (y);
+ MPFR_SET_SAME_SIGN (y, x);
+ MPFR_RET (0);
+ }
+ else if (MPFR_IS_ZERO(x))
+ {
+ return mpfr_set_q (y, z, rnd_mode);
+ }
+
+ mpfr_inits(t, q, NULL);
+ for(;;)
+ {
+ mpfr_set_prec(t, p);
+ mpfr_set_prec(q, p);
+
+ res = mpfr_set_q(q, z, GMP_RNDN); /* Error <= 1/2 ulp(q) */
+ if (res == 0) /* Result is exact so we can add it directly!*/
+ {
+ res = mpfr_add(y, x, q, rnd_mode);
+ break;
+ }
+ mpfr_add(t, x, q, GMP_RNDN); /* Error <= 1/2 ulp(t) */
+ /* Error / ulp(t) <= 1/2 + 1/2 * 2^(EXP(q)-EXP(t))
+ If EXP(q)-EXP(t)>0, <= 2^(EXP(q)-EXP(t)-1)*(1+2^-(EXP(q)-EXP(t)))
+ <= 2^(EXP(q)-EXP(t))
+ If EXP(q)-EXP(t)<0, <= 2^0 */
+ err = (mp_exp_t) p - 1 - MAX(MPFR_GET_EXP(q)-MPFR_GET_EXP(t), 0);
+ res = mpfr_can_round (t, err, GMP_RNDN, GMP_RNDZ,
+ MPFR_PREC(y) + (rnd_mode == GMP_RNDN) );
+ p += BITS_PER_MP_LIMB; /* Next precision if we continue */
+ if (res != 0) /* We can round! */
+ {
+ res = mpfr_set(y, t, rnd_mode);
+ break;
+ }
+ }
+ mpfr_clears(t, q, NULL);
+ return res;
}
-int
-mpfr_sub_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode)
+int
+mpfr_sub_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode)
{
- mpfr_t t;
+ mpfr_t t,q;
+ mp_prec_t p = MPFR_PREC(y)+10;
int res;
- mpfr_init(t);
- mpfr_set_q(t,z,rnd_mode);
- res=mpfr_sub(y,x,t,rnd_mode);
- mpfr_clear(t);
- return(res);
+ mp_exp_t err;
+
+ if (MPFR_IS_NAN(x))
+ {
+ MPFR_SET_NAN (y);
+ MPFR_RET_NAN;
+ }
+ else if (MPFR_IS_INF(x))
+ {
+ MPFR_CLEAR_NAN (y);
+ MPFR_SET_INF (y);
+ MPFR_SET_SAME_SIGN (y, x);
+ MPFR_RET (0);
+ }
+ else if (MPFR_IS_ZERO(x))
+ {
+ if (rnd_mode == GMP_RNDU)
+ rnd_mode = GMP_RNDD;
+ else if (rnd_mode == GMP_RNDD)
+ rnd_mode = GMP_RNDU;
+ res = mpfr_set_q (y, z, rnd_mode);
+ MPFR_CHANGE_SIGN (y);
+ return -res;
+ }
+
+ mpfr_inits(t, q, NULL);
+ for(;;)
+ {
+ mpfr_set_prec(t, p);
+ mpfr_set_prec(q, p);
+
+ res = mpfr_set_q(q, z, GMP_RNDN); /* Error <= 1/2 ulp(q) */
+ if (res == 0) /* Result is exact so we can add it directly!*/
+ {
+ res = mpfr_sub(y, x, q, rnd_mode);
+ break;
+ }
+ mpfr_sub(t, x, q, GMP_RNDN); /* Error <= 1/2 ulp(t) */
+ /* Error / ulp(t) <= 1/2 + 1/2 * 2^(EXP(q)-EXP(t))
+ If EXP(q)-EXP(t)>0, <= 2^(EXP(q)-EXP(t)-1)*(1+2^-(EXP(q)-EXP(t)))
+ <= 2^(EXP(q)-EXP(t))
+ If EXP(q)-EXP(t)<0, <= 2^0 */
+ err = (mp_exp_t) p - 1 - MAX(MPFR_GET_EXP(q)-MPFR_GET_EXP(t), 0);
+ res = mpfr_can_round (t, err, GMP_RNDN, GMP_RNDZ,
+ MPFR_PREC(y) + (rnd_mode == GMP_RNDN) );
+ p += BITS_PER_MP_LIMB; /* Next precision if we continue */
+ if (res != 0) /* We can round! */
+ {
+ res = mpfr_set(y, t, rnd_mode);
+ break;
+ }
+ }
+ mpfr_clears(t, q, NULL);
+ return res;
}
diff --git a/hypot.c b/hypot.c
index 10cc75f06..cf07ffa72 100644
--- a/hypot.c
+++ b/hypot.c
@@ -1,6 +1,6 @@
/* mpfr_hypot -- Euclidean distance
-Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -89,9 +89,11 @@ mpfr_hypot (mpfr_ptr z, mpfr_srcptr x , mpfr_srcptr y , mp_rnd_t rnd_mode)
y does not overlap with the result when
x^2+y^2 < (|x| + 1/2*ulp(x,Nz))^2 = x^2 + |x|*ulp(x,Nz) + 1/4*ulp(x,Nz)^2,
i.e. a sufficient condition is y^2 < |x|*ulp(x,Nz),
- or 2^(2*Ey) <= 2^(2*Ex-1-Nz), i.e. 2*diff_exp > Nz
+ or 2^(2*Ey) <= 2^(2*Ex-1-Nz), i.e. 2*diff_exp > Nz.
+ Warning: this is true only for Nx <= Nz, otherwise the trailing bits
+ of x may be already very close to 1/2*ulp(x,Nz)!
*/
- if (diff_exp > Nz / 2) /* result is |x| or |x|+ulp(|x|,Nz) */
+ if (MPFR_PREC(x) <= Nz && diff_exp > Nz / 2) /* result is |x| or |x|+ulp(|x|,Nz) */
{
if (rnd_mode == GMP_RNDU)
{
diff --git a/log1p.c b/log1p.c
index 7bd641f7a..f655bf5a2 100644
--- a/log1p.c
+++ b/log1p.c
@@ -34,9 +34,9 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
int comp, inexact = 0;
- if (MPFR_IS_NAN(x))
+ if (MPFR_IS_NAN(x))
{
- MPFR_SET_NAN(y);
+ MPFR_SET_NAN(y);
MPFR_RET_NAN;
}
@@ -60,7 +60,7 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
comp = mpfr_cmp_si(x,-1);
/* x<-1 undefined */
- if (comp < 0)
+ if (comp < 0)
{
MPFR_SET_NAN(y);
MPFR_RET_NAN;
@@ -70,7 +70,7 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
MPFR_SET_INF(y);
MPFR_SET_POS(y);
- MPFR_RET_NAN;
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
@@ -90,10 +90,10 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
/* Declaration of the size variable */
mp_prec_t Nx = MPFR_PREC(x); /* Precision of input variable */
mp_prec_t Ny = MPFR_PREC(y); /* Precision of input variable */
-
+
mp_prec_t Nt; /* Precision of the intermediary variable */
long int err; /* Precision of error */
-
+
/* compute the precision of intermediary variable */
Nt = MAX(Nx,Ny);
/* the optimal number of bits : see algorithms.ps */
@@ -107,7 +107,7 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
/* reactualisation of the precision */
mpfr_set_prec (t, Nt);
-
+
/* compute log1p */
mpfr_add_ui (t, x, 1, GMP_RNDN); /* 1+x */
mpfr_log (t, t, GMP_RNDN); /* log(1+x)*/
diff --git a/minmax.c b/minmax.c
index cc1dfd895..7c2dc72ce 100644
--- a/minmax.c
+++ b/minmax.c
@@ -1,6 +1,6 @@
/* mpfr_min -- min and max of x, y
-Copyright 2001 Free Software Foundation, Inc.
+Copyright 2001, 20003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
diff --git a/mpf2mpfr.h b/mpf2mpfr.h
index 8aa09d6ce..eaf970935 100644
--- a/mpf2mpfr.h
+++ b/mpf2mpfr.h
@@ -1,6 +1,6 @@
/* mpf2mpfr.h -- Compatibility include file with mpf.
-Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -83,8 +83,8 @@ MA 02111-1307, USA. */
#define mpf_div_2exp(x,y,z) \
mpfr_div_2exp(x,y,z,__gmpfr_default_rounding_mode)
#undef mpf_dump
-#define mpf_dump(x,y,z) \
- mpfr_dump(x,y,z,__gmpfr_default_rounding_mode)
+#define mpf_dump(x) \
+ mpfr_dump(x,__gmpfr_default_rounding_mode)
#undef mpf_fits_slong_p
#define mpf_fits_slong_p(x) mpfr_fits_ulong_p(x,__gmpfr_default_rounding_mode)
#undef mpf_fits_ulong_p
diff --git a/mpfi.c b/mpfi.c
deleted file mode 100644
index 6596f4297..000000000
--- a/mpfi.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/* mpfi.c -- Implementation of mpfi.
-
-Copyright 1999 Free Software Foundation.
-
-This file is part of the MPFR Library.
-
-The 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 2.1 of the License, or (at your
-option) any later version.
-
-The 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 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 "mpfi.h"
-
-/* *********************************************************** */
-/* MPFI */
-/* *********************************************************** */
-
-#define MPFR_SIGN_PART(x) mpfr_cmp_ui_2exp(x,0,0)
-
-#define MPFI_ISPOS(x) ((MPFR_SIGN_PART((&(x->left)))>=0) && (MPFR_SIGN_PART((&(x->right)))>0))
-#define MPFI_MPFR_ISNEG(x) ((MPFR_SIGN_PART((&(x->left)))<0) && (MPFR_SIGN_PART((&(x->right)))<=0))
-#define MPFI_ISNULL(x) ((MPFR_SIGN_PART((&(x->left)))==0) && (MPFR_SIGN_PART((&(x->right)))==0))
-#define MPFI_HASZERO(x) ((MPFR_SIGN_PART((&(x->left)))<0) && (MPFR_SIGN_PART((&(x->right)))>0))
-
-
-void mpfi_set_prec(const unsigned int p)
-{
- mpfr_set_default_prec(p);
-}
-
-int mpfi_cmp_default (mpfi_srcptr a,mpfi_srcptr b)
-{
- return((mpfr_cmp(&(a->right),&(b->left))<0) ? -1 :(mpfr_cmp(&(b->right),&(a->left))>0));
-}
-
-int (*mpfi_cmp)(mpfi_srcptr,mpfi_srcptr)=mpfi_cmp_default;
-
-int mpfi_comp_d (mpfi_srcptr a,const double b)
-{
- mpfi_t tmp;
- mpfi_set_d(tmp,b);
- return(mpfi_cmp(a,tmp));
-}
-
-int mpfi_comp_ui (mpfi_srcptr a,const unsigned long b)
-{
- mpfi_t tmp;
- mpfi_set_ui(tmp,b);
- return(mpfi_cmp(a,tmp));
-}
-
-int mpfi_comp_si (mpfi_srcptr a,const unsigned long b)
-{
- mpfi_t tmp;
- mpfi_set_si(tmp,b);
- return(mpfi_cmp(a,tmp));
-}
-
-int mpfi_is_pos_default(mpfi_srcptr a)
-{
- return((MPFR_SIGN_PART(&(a->left))>0));
-}
-
-int mpfi_is_neg_default(mpfi_srcptr a)
-{
- return((MPFR_SIGN_PART(&(a->right))<0));
-}
-
-int mpfi_is_zero_default(mpfi_srcptr a)
-{
- return((MPFR_SIGN_PART(&(a->right))==0) &&
- (MPFR_SIGN_PART(&(a->left))==0));
-}
-
-int (*mpfi_is_pos) (mpfi_srcptr)=mpfi_is_pos_default;
-int (*mpfi_is_neg) (mpfi_srcptr)=mpfi_is_neg_default;
-int (*mpfi_is_zero) (mpfi_srcptr)=mpfi_is_zero_default;
-
-
-/* interval manipulation */
-
-static int mpfi_error=0;
-
-#define MPFI_ERROR(s) \
-{\
-if(!mpfi_error) mpfi_error=1;\
-}
-
-#define MPFI_CHECK_ERROR_INT(x,s) \
-{\
-if ((MPFI_HASZERO(x))) MPFI_ERROR(s);\
-}
-
-#ifdef MPFI_USE_CHECK_ERROR
-#define MPFI_CHECK_ERROR(x,s) MPFI_CHECK_ERROR_INT(x,s)
-#else
-#define MPFI_CHECK_ERROR(x,s) {}
-#endif
-
-#ifdef MPFI_USE_CHECK_ERROR
-void mpfi_reset_error()
-{
- mpfi_error=0;
-}
-
-int mpfi_is_error()
-{
- return(mpfi_error==1);
-}
-#endif
-
-void mpfi_init (mpfi_t x)
-{
- mpfr_init(&(x->left));
- mpfr_init(&(x->right));
-}
-
-void mpfi_init2 (mpfi_t x, mp_prec_t p)
-{
- mpfr_init2 (&(x->left), p);
- mpfr_init2 (&(x->right), p);
-}
-
-void mpfi_set(mpfi_ptr a, mpfi_srcptr b)
-{
- mpfr_set(&(a->left),&(b->left),MPFI_RNDD);
- mpfr_set(&(a->right),&(b->right),MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_set");
-}
-
-void mpfi_set_si(mpfi_ptr a,const long b)
-{
- mpfr_set_si(&(a->left),b,MPFI_RNDD);
- mpfr_set_si(&(a->right),b,MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_set_si");
-}
-
-void mpfi_set_ui(mpfi_ptr a,const unsigned long b)
-{
- mpfr_set_ui(&(a->left),b,MPFI_RNDD);
- mpfr_set_ui(&(a->right),b,MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_set_ui");
-}
-
-void mpfi_set_d(mpfi_ptr a, const double b)
-{
- mpfr_set_d(&(a->left),b,MPFI_RNDD);
- mpfr_set_d(&(a->right),b,MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_set_ui");
-}
-
-void mpfi_add (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c)
-{
- if (MPFI_ISNULL(c)) {
- mpfi_set (a, b);
- }
- else {
- if (MPFI_ISNULL(b)) {
- mpfi_set (a, c);
- }
- else {
- mpfr_add (&(a->left), &(b->left), &(c->left), MPFI_RNDD);
- mpfr_add (&(a->right), &(b->right), &(c->right), MPFI_RNDU);
- }
- }
- MPFI_CHECK_ERROR(a,"mpfi_add");
-}
-
-void mpfi_sub (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c)
-{
- /* if using temporary variables: check that their precision agrees
- with that of input! */
- mpfr_sub (&(a->left), &(b->left), &(c->left), MPFI_RNDD);
- mpfr_sub (&(a->right), &(b->right), &(c->right), MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_sub");
-}
-
-void mpfi_mul (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c)
-{
- mpfr_t u, v;
- int in_place;
-
- if (MPFI_ISNULL(b) || MPFI_ISNULL(c)) {
- mpfi_set_ui (a, 0);
- }
- else {
- if (MPFI_ISPOS(c) || MPFI_ISPOS(b)) {
- /* works here even if a = b or a = c */
- mpfr_mul(&(a->left), &(b->left), &(c->left), MPFI_RNDD);
- mpfr_mul(&(a->right), &(b->right), &(c->right), MPFI_RNDU);
- }
- else {
- if (MPFI_MPFR_ISNEG(c)) {
- in_place = (b->right)._mp_d == (a->right)._mp_d;
- if (!in_place) u[0] = b->right;
- else {
- mpfr_init2 (u, MPFR_PREC(&(b->right)));
- mpfr_set (u, &(b->right), GMP_RNDD);
- }
- mpfr_mul (&(a->right), &(b->left), &(c->right), MPFI_RNDU);
- mpfr_mul (&(a->left), u, &(c->left), MPFI_RNDD);
- if (in_place) mpfr_clear (u);
- }
- else {
- fprintf (stderr, "mpfi_mul: not yet implemented\n");
- exit (1);
- }
- }
- }
- MPFI_CHECK_ERROR(a,"mpfi_mul");
-}
-
-void mpfi_div (mpfi_ptr a, mpfi_srcptr u, mpfi_srcptr c)
-{
- mpfi_t b;
- int in_place;
-
- in_place = (u->left)._mp_d == (a->left)._mp_d;
-
- if (!in_place) {
- b[0]=(*u);
- }
- else {
- mpfi_init(b);
- mpfi_set(b,u);
- }
- if (!(MPFI_ISNULL(b))) {
- if (MPFI_ISPOS(c)) {
- mpfr_div(&(a->left),&(b->left),&(c->right),MPFI_RNDD);
- mpfr_div(&(a->right),&(b->right),&(c->left),MPFI_RNDU);
- }
- else {
- if (MPFI_MPFR_ISNEG(c)) {
- mpfr_div(&(a->right),&(b->left),&(c->left),MPFI_RNDU);
- mpfr_div(&(a->left),&(b->right),&(c->right),MPFI_RNDD);
- }
- else {
- /* zero dans l'intervalle .... */
- MPFI_ERROR("mpfi_div : division by zero");
- }
- }
- }
- MPFI_CHECK_ERROR(a,"mpfi_div");
- if (in_place) mpfi_clear (b);
-}
-
-void mpfi_add_d(mpfi_ptr a, mpfi_srcptr b, const double c)
-{
- mpfi_t tmp;
- mpfi_set_d(tmp,c);
- mpfi_add(a,b,tmp);
-}
-
-void mpfi_sub_d(mpfi_ptr a, mpfi_srcptr b, const double c)
-{
- mpfi_t tmp;
- mpfi_set_d(tmp,c);
- mpfi_sub(a,b,tmp);
-}
-
-void mpfi_mul_d(mpfi_ptr a, mpfi_srcptr b, const double c)
-{
- mpfi_t tmp;
- mpfi_set_d(tmp,c);
- mpfi_mul(a,b,tmp);
-}
-
-void mpfi_mul_ui (mpfi_ptr a, mpfi_srcptr b, unsigned int c)
-{
- mpfr_mul_ui (&(a->left), &(b->left), c, GMP_RNDD);
- mpfr_mul_ui (&(a->right), &(b->right), c, GMP_RNDU);
-}
-
-void mpfi_sub_ui (mpfi_ptr a, mpfi_srcptr b, unsigned int c)
-{
- mpfr_sub_ui (&(a->left), &(b->left), c, GMP_RNDD);
- mpfr_sub_ui (&(a->right), &(b->right), c, GMP_RNDU);
-}
-
-void mpfi_ui_div (mpfi_ptr a, unsigned int b, mpfi_srcptr c)
-{
- if (MPFI_ISPOS(c) || MPFI_MPFR_ISNEG(c)) {
- mpfr_t tmp;
- int in_place = (a->left)._mp_d == (c->left)._mp_d;
- if (in_place) {
- mpfr_init2 (tmp, MPFR_PREC(&(a->left)));
- mpfr_set (tmp, &(a->left), GMP_RNDN);
- }
- else tmp[0] = a->left;
- mpfr_ui_div (&(a->left), b, &(c->right), GMP_RNDD);
- mpfr_ui_div (&(a->right), b, tmp, GMP_RNDU);
- if (in_place) mpfr_clear (tmp);
- }
- else
- MPFI_ERROR("mpfi_ui_div : division by zero");
-}
-
-void mpfi_div_d (mpfi_ptr a, mpfi_srcptr b, const double c)
-{
- mpfi_t tmp;
- mpfi_set_d(tmp,c);
- mpfi_div(a,b,tmp);
-}
-
-void mpfi_dadd(mpfi_ptr a,mpfi_srcptr b)
-{
- mpfi_add(a,a,b);
-}
-
-void mpfi_dsub(mpfi_ptr a,mpfi_srcptr b)
-{
- mpfi_sub(a,a,b);
-}
-
-void mpfi_dmul(mpfi_ptr a,mpfi_srcptr b)
-{
- mpfi_mul(a,a,b);
-}
-
-void mpfi_ddiv(mpfi_ptr a,mpfi_srcptr b)
-{
- mpfi_div(a,a,b);
-}
-
-void mpfi_mul_2exp(mpfi_ptr a, mpfi_srcptr b,unsigned long c)
-{
- mpfr_mul_2exp(&(a->left),&(b->left),c,MPFI_RNDD);
- mpfr_mul_2exp(&(a->right),&(b->right),c,MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_mul_2exp");
-}
-
-void mpfi_div_2exp(mpfi_ptr a, mpfi_srcptr b,unsigned long c)
-{
- mpfr_div_2exp(&(a->left),&(b->left),c,MPFI_RNDD);
- mpfr_div_2exp(&(a->right),&(b->right),c,MPFI_RNDU);
- MPFI_CHECK_ERROR(a,"mpfi_mul_2exp");
-}
-
-void mpfi_neg(mpfi_ptr a, mpfi_srcptr b)
-{
- mpfr_t tmp;
-
- mpfr_init2 (tmp, MPFR_PREC(&(b->left)));
- mpfr_set (tmp, &(b->left), MPFI_RNDD);
- mpfr_neg (&(a->left), &(b->right), MPFI_RNDD);
- mpfr_neg (&(a->right), tmp, MPFI_RNDU);
- MPFI_CHECK_ERROR (a,"mpfi_neg");
- mpfr_clear (tmp);
-}
-
-void mpfi_inv(mpfi_ptr a, mpfi_srcptr b)
-{
- mpfi_ui_div(a, 1, b);
-}
-
-void mpfi_set_left (mpfi_ptr a, mpfr_srcptr b)
-{
- mpfr_set(&(a->left),b,MPFI_RNDD);
-}
-
-void mpfi_set_right (mpfi_ptr a, mpfr_srcptr b)
-{
- mpfr_set(&(a->right),b,MPFI_RNDU);
-}
-
-void mpfi_get_left (mpfi_srcptr a, mpfr_ptr b)
-{
- mpfr_set(b,&(a->left),MPFI_RNDD);
-}
-
-void mpfi_get_right (mpfi_srcptr a, mpfr_ptr b)
-{
- mpfr_set(b,&(a->right),MPFI_RNDU);
-}
-
-void mpfi_clear(mpfi_ptr a)
-{
- mpfr_clear(&(a->right));
- mpfr_clear(&(a->left));
-
-}
-
-void mpfi_out_str (FILE *stream, int base, size_t n_digits, mpfi_srcptr op)
-{
- fprintf (stream, "[");
- mpfr_out_str (stream, base, n_digits, &(op->left), GMP_RNDD);
- fprintf (stream, ",");
- mpfr_out_str (stream, base, n_digits, &(op->right), GMP_RNDU);
- fprintf (stream, "]");
-}
diff --git a/mpfi.h b/mpfi.h
deleted file mode 100644
index 595cc3f95..000000000
--- a/mpfi.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/* mpfi.h -- Include file for mpfi.
-
-Copyright 1999 Free Software Foundation.
-Contributed by the Spaces project, INRIA Lorraine.
-
-This file is part of the MPFR Library.
-
-The 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 2.1 of the License, or (at your
-option) any later version.
-
-The 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 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. */
-
-#ifndef _mpfi_h
-#define _mpfi_h
-
-#define MPFI_RNDD GMP_RNDD
-#define MPFI_RNDU GMP_RNDU
-
-#include <math.h>
-
-/* Machine dependant implementations */
-
-#include "gmp.h"
-#include "mpfr.h"
-
-typedef struct {
- __mpfr_struct left;
- __mpfr_struct right;
-}__mpfi_struct;
-
-typedef __mpfi_struct mpfi_t[1];
-typedef __mpfi_struct *mpfi_ptr;
-typedef __gmp_const __mpfi_struct *mpfi_srcptr;
-
-/* Gestion de la precision */
-
-void mpfi_set_prec(const unsigned int);
-
-unsigned int mpfi_get_prec();
-
-/* Gestion de memoire */
-
-void mpfi_clear(mpfi_ptr);
-
-/* initializations */
-
-void mpfi_init (mpfi_ptr);
-void mpfi_set (mpfi_ptr, mpfi_srcptr);
-void mpfi_set_si (mpfi_ptr, const long);
-void mpfi_set_ui (mpfi_ptr, const unsigned long);
-void mpfi_set_d (mpfi_ptr, const double);
-
-
-/* void mpfi_set_str (mpfi_ptr, const char *); */
-
-/* arithmetic operations */
-
-void mpfi_add (mpfi_ptr, mpfi_srcptr, mpfi_srcptr);
-void mpfi_sub (mpfi_ptr, mpfi_srcptr, mpfi_srcptr);
-void mpfi_mul (mpfi_ptr, mpfi_srcptr, mpfi_srcptr);
-void mpfi_div (mpfi_ptr, mpfi_srcptr, mpfi_srcptr);
-
-void mpfi_add_d (mpfi_ptr, mpfi_srcptr, const double);
-void mpfi_sub_d (mpfi_ptr, mpfi_srcptr, const double);
-void mpfi_mul_d (mpfi_ptr, mpfi_srcptr, const double);
-void mpfi_div_d (mpfi_ptr, mpfi_srcptr, const double);
-
-#define mpfi_add_si(a,b,c) mpfi_add_d(a,b,(double) c);
-#define mpfi_sub_si(a,b,c) mpfi_sub_d(a,b,(double) c);
-#define mpfi_mul_si(a,b,c) mpfi_mul_d(a,b,(double) c);
-#define mpfi_div_si(a,b,c) mpfi_div_d(a,b,(double) c);
-
-/* destructive arithmetic operations */
-
-void mpfi_dadd (mpfi_ptr, mpfi_srcptr);
-void mpfi_dsub (mpfi_ptr, mpfi_srcptr);
-void mpfi_dmul (mpfi_ptr, mpfi_srcptr);
-void mpfi_ddiv (mpfi_ptr, mpfi_srcptr);
-
-void mpfi_dadd_d (mpfi_ptr, const double);
-void mpfi_dsub_d (mpfi_ptr, const double);
-void mpfi_dmul_d (mpfi_ptr, const double);
-void mpfi_ddiv_d (mpfi_ptr, const double);
-
-#define mpfi_dadd_si(a,c) mpfi_dadd_d(a,(double) c);
-#define mpfi_dsub_si(a,c) mpfi_dsub_d(a,(double) c);
-#define mpfi_dmul_si(a,c) mpfi_dmul_d(a,(double) c);
-#define mpfi_ddiv_si(a,c) mpfi_ddiv_d(a,(double) c);
-
-/* destructive composite arithmetic operations */
-
-
-/* various operations */
-
-void mpfi_neg(mpfi_ptr, mpfi_srcptr);
-void mpfi_inv(mpfi_ptr, mpfi_srcptr);
-void mpfi_mul_2exp(mpfi_ptr, mpfi_srcptr,unsigned long);
-
-/* interval manipulation */
-
-void mpfi_set_left (mpfi_ptr, mpfr_srcptr);
-void mpfi_set_right (mpfi_ptr, mpfr_srcptr);
-void mpfi_get_left (mpfi_srcptr, mpfr_ptr);
-void mpfi_get_right (mpfi_srcptr, mpfr_ptr);
-
-
-/* customizable comparison functions */
-
-int (*mpfi_cmp) (mpfi_srcptr,mpfi_srcptr);
-int (*mpfi_cmp_d) (mpfi_srcptr,const double);
-int (*mpfi_cmp_ui) (mpfi_srcptr,const unsigned long);
-int (*mpfi_cmp_si) (mpfi_srcptr,const long);
-
-int (*mpfi_is_pos) (mpfi_srcptr);
-int (*mpfi_is_neg) (mpfi_srcptr);
-int (*mpfi_is_zero) (mpfi_srcptr);
-
-
-/* Customizable error handling */
-
-#ifdef MPFI_USE_CHECK_ERROR
-int reset_error();
-int get_error();
-char * get_error_str();
-#endif
-
-#endif
diff --git a/mpfr-test.h b/mpfr-test.h
index d13533891..055612cab 100644
--- a/mpfr-test.h
+++ b/mpfr-test.h
@@ -1,6 +1,6 @@
/* auxiliary functions for MPFR tests.
-Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -68,3 +68,5 @@ double Ulp _PROTO ((double));
int Isnan _PROTO ((double));
void d_trace _PROTO ((const char *, double));
void ld_trace _PROTO ((const char *, long double));
+
+#define mpfr_set_str1(x,s) mpfr_set_str(x,s,10,GMP_RNDN)
diff --git a/mpfr.h b/mpfr.h
index f8e18594c..f28838511 100644
--- a/mpfr.h
+++ b/mpfr.h
@@ -336,7 +336,7 @@ int mpfr_unordered_p _PROTO ((mpfr_srcptr, mpfr_srcptr));
#define mpfr_inexflag_p() \
((int) (__gmpfr_flags & MPFR_FLAGS_INEXACT))
-#define mpfr_round(a,b) mpfr_rint((a), (b), GMP_RNDN)
+#define mpfr_round(a,b) mpfr_rint((a), (b), -1)
#define mpfr_trunc(a,b) mpfr_rint((a), (b), GMP_RNDZ)
#define mpfr_ceil(a,b) mpfr_rint((a), (b), GMP_RNDU)
#define mpfr_floor(a,b) mpfr_rint((a), (b), GMP_RNDD)
diff --git a/mpfr.texi b/mpfr.texi
index f7ea1dfa4..9e0d41f62 100644
--- a/mpfr.texi
+++ b/mpfr.texi
@@ -2,8 +2,8 @@
@c %**start of header
@setfilename mpfr.info
@documentencoding ISO-8859-1
-@set VERSION 2.0.2
-@set UPDATED-MONTH October 2003
+@set VERSION 2.0.3
+@set UPDATED-MONTH February 2004
@settitle MPFR @value{VERSION}
@synindex tp fn
@iftex
@@ -16,7 +16,7 @@ This manual documents how to install and use the Multiple Precision
Floating-Point Reliable Library, version @value{VERSION}.
Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-2003 Free Software Foundation, Inc.
+2003, 2004 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under
the terms of the GNU Free Documentation License, Version 1.1 or any later
@@ -367,7 +367,7 @@ MPFR suffers from all bugs from the GNU MP library, plus many many more.
Please report other problems to @samp{mpfr@@loria.fr}.
@xref{Reporting Bugs}.
Some bug fixes are available on the MPFR web page
-@url{http://www.loria.fr/projets/mpfr/} or @url{http://www.mpfr.org/}.
+@url{http://www.mpfr.org/}.
@node Reporting Bugs, MPFR Basics, Installing MPFR, Top
@@ -376,8 +376,7 @@ Some bug fixes are available on the MPFR web page
@cindex Reporting bugs
If you think you have found a bug in the MPFR library, first have a look on the
-MPFR web page @url{http://www.mpfr.org/} or
-@url{http://www.loria.fr/projets/mpfr/}: perhaps this bug is already known,
+MPFR web page @url{http://www.mpfr.org/}: perhaps this bug is already known,
in which case you may find there a workaround for it.
Otherwise, please investigate
and report it. We have made this library available to you, and it is not to ask
@@ -431,8 +430,8 @@ for such objects is @code{mpfr_t}. A floating-point number can have
three special values: Not-a-Number (NaN) or plus or minus Infinity. NaN
represents an uninitialized object, the result of an invalid operation
(like 0 divided by 0), or a value that cannot be determined (like
-+Infinity minus +Infinity). Moreover, like in the IEEE 754-1985
-standard, zero is signed, i.e.@: there are both +0 and -0; the behavior
++Infinity minus +Infinity). Moreover, like in the IEEE 754-1985 standard,
+zero is signed, i.e.@: there are both +0 and @minus{}0; the behavior
is the same as in the IEEE 754-1985 standard and it is generalized to
the other functions supported by MPFR.
@@ -440,7 +439,7 @@ the other functions supported by MPFR.
@cindex Precision
@tindex @code{mp_prec_t}
@noindent
-The @dfn{Precision} is the number of bits used to represent the mantissa
+The @dfn{precision} is the number of bits used to represent the mantissa
of a floating-point number;
the corresponding C data type is @code{mp_prec_t}.
The precision can be any integer between @code{MPFR_PREC_MIN} and
@@ -622,6 +621,8 @@ the ternary value is usually positive, except when the result is exact, in
which case it is zero. In the case of an infinite result, it is considered
as inexact when it was obtained by overflow, and exact otherwise. A NaN
result (Not-a-Number) always corresponds to an exact return value.
+The opposite of a returned ternary value is guaranteed to be representable
+in an @code{int}.
@deftypefun void mpfr_set_default_rounding_mode (mp_rnd_t @var{rnd})
Sets the default rounding mode to @var{rnd}.
@@ -642,7 +643,7 @@ direction. In both cases, the precision of @var{x} is changed to @var{prec}.
[This function is obsolete. Please use @code{mpfr_prec_round} instead.]
@end deftypefun
-@deftypefun {char *} mpfr_print_rnd_mode (mp_rnd_t @var{rnd})
+@deftypefun {const char *} mpfr_print_rnd_mode (mp_rnd_t @var{rnd})
Returns the input string (GMP_RNDD, GMP_RNDU, GMP_RNDN, GMP_RNDZ)
corresponding to the rounding mode @var{rnd} or a null pointer if
@var{rnd} is an invalid rounding mode.
@@ -827,6 +828,9 @@ These functions assign new values to already initialized floats
@deftypefunx int mpfr_set_f (mpfr_t @var{rop}, mpf_t @var{op}, mp_rnd_t @var{rnd})
Set the value of @var{rop} from @var{op}, rounded
towards the given direction @var{rnd}.
+Note that the input 0 is converted to +0 by @code{mpfr_set_ui},
+@code{mpfr_set_si}, @code{mpfr_set_z}, @code{mpfr_set_q} and
+@code{mpfr_set_f}, regardless of the rounding mode.
@end deftypefun
@deftypefun int mpfr_set_str (mpfr_t @var{x}, const char *@var{s}, int @var{base}, mp_rnd_t @var{rnd})
@@ -1010,6 +1014,8 @@ direction @var{rnd}.
@deftypefunx int mpfr_div_z (mpfr_t @var{rop}, mpfr_t @var{op1}, mpz_t @var{op2}, mp_rnd_t @var{rnd})
@deftypefunx int mpfr_div_q (mpfr_t @var{rop}, mpfr_t @var{op1}, mpq_t @var{op2}, mp_rnd_t @var{rnd})
Set @var{rop} to @math{@var{op1}/@var{op2}} rounded in the direction @var{rnd}.
+When a result is zero, its sign is the product of the signs of the operands
+(for types having no signed zero, it is considered positive).
@end deftypefun
@deftypefun int mpfr_sqrt (mpfr_t @var{rop}, mpfr_t @var{op}, mp_rnd_t @var{rnd})
@@ -1033,7 +1039,7 @@ rounded in the direction @var{rnd}.
Set @var{rop} to @m{@var{op1}^{op2}, @var{op1} raised to @var{op2}},
rounded in the direction @var{rnd}.
Special values are currently handled as described in the ISO C99 standard
-for the @code{pow} function:
+for the @code{pow} function (note this may change in future versions):
@itemize @bullet
@item @code{pow(@pom{}0, @var{y})} returns plus or minus infinity for @var{y} a negative odd integer.
@item @code{pow(@pom{}0, @var{y})} returns plus infinity for @var{y} negative and not an odd integer.
@@ -1185,7 +1191,7 @@ compared), zero otherwise.
@section Special Functions
@cindex Special functions
-All those functions, except explicitely stated, return zero for an
+All those functions, except explicitly stated, return zero for an
exact return value, a positive value for a return value larger than the
exact result, and a negative value otherwise.
@@ -1367,19 +1373,27 @@ Return the number of bytes read, or if an error occurred, return 0.
@deftypefunx int mpfr_floor (mpfr_t @var{rop}, mpfr_t @var{op})
@deftypefunx int mpfr_round (mpfr_t @var{rop}, mpfr_t @var{op})
@deftypefunx int mpfr_trunc (mpfr_t @var{rop}, mpfr_t @var{op})
-Set @var{rop} to @var{op} rounded to an integer. @code{mpfr_ceil} rounds
+Set @var{rop} to @var{op} rounded to an integer.
+@code{mpfr_rint} rounds to the nearest representable integer in the
+given rounding mode, @code{mpfr_ceil} rounds
to the next higher or equal representable integer, @code{mpfr_floor} to
the next lower or equal representable integer, @code{mpfr_round} to the
nearest representable integer, rounding halfway cases away from zero,
and @code{mpfr_trunc} to the next representable integer towards zero.
-@code{mpfr_rint} behaves like one of these four functions, depending
-on the rounding mode.
+
The returned value is zero when the result is exact, positive when it is
greater than the original value of @var{op}, and negative when it is smaller.
More precisely, the returned value is 0 when @var{op} is an integer
representable in @var{rop}, 1 or @minus{}1 when @var{op} is an integer
that is not representable in @var{rop}, 2 or @minus{}2 when @var{op} is
not an integer.
+
+Note that @code{mpfr_round} is different from @code{mpfr_rint} called with
+the rounding to the nearest mode (where halfway cases are rounded to an even
+integer or mantissa). Note also that no double rounding is performed; for
+instance, 4.5 (100.1 in binary) is rounded by @code{mpfr_round} to 4 (100
+in binary) in 2-bit precision, though @code{round(4.5)} is equal to 5 and
+5 (101 in binary) is rounded to 6 (110 in binary) in 2-bit precision.
@end deftypefun
@deftypefun int mpfr_frac (mpfr_t @var{rop}, mpfr_t @var{op}, mp_rnd_t @var{rnd})
@@ -1411,6 +1425,22 @@ Equivalent to @code{mpfr_nexttoward} where @var{y} is plus infinity.
Equivalent to @code{mpfr_nexttoward} where @var{y} is minus infinity.
@end deftypefun
+@deftypefun int mpfr_min (mpfr_t @var{rop}, mpfr_t @var{op1}, mpfr_t @var{op2}, mp_rnd_t @var{rnd})
+Set @var{rop} to the minimum of @var{op1} and @var{op2}. If @var{op1}
+and @var{op2} are both NaN, then @var{rop} is set to NaN. If @var{op1}
+or @var{op2} is NaN, then @var{rop} is set to the numeric value. If
+@var{op1} and @var{op2} are zeros of different signs, then @var{rop}
+is set to @minus{}0.
+@end deftypefun
+
+@deftypefun int mpfr_max (mpfr_t @var{rop}, mpfr_t @var{op1}, mpfr_t @var{op2}, mp_rnd_t @var{rnd})
+Set @var{rop} to the maximum of @var{op1} and @var{op2}. If @var{op1}
+and @var{op2} are both NaN, then @var{rop} is set to NaN. If @var{op1}
+or @var{op2} is NaN, then @var{rop} is set to the numeric value. If
+@var{op1} and @var{op2} are zeros of different signs, then @var{rop}
+is set to +0.
+@end deftypefun
+
@deftypefun int mpfr_urandomb (mpfr_t @var{rop}, gmp_randstate_t @var{state})
Generate a uniformly distributed random float in the interval
@math{0 @le{} @var{rop} < 1}.
@@ -1432,6 +1462,7 @@ This function is useful for
testing functions and algorithms, since this kind of random numbers have
proven to be more likely to trigger corner-case bugs.
Negative random numbers are generated when @var{size} is negative.
+Put +0 in @var{rop} when size if zero.
@end deftypefun
@c @deftypefun size_t mpfr_size (mpfr_t @var{op})
@@ -1522,7 +1553,7 @@ number.
@deftypefun int mpfr_set_exp (mpfr_t @var{x}, mp_exp_t @var{e})
Set the exponent of @var{x} if @var{e} is in the current exponent range,
and return 0 (even if @var{x} is not a non-zero ordinary number);
-otherwise, return 1.
+otherwise, return a non-zero value.
@end deftypefun
@deftypefun void mpfr_set_str_binary (mpfr_t @var{x}, const char *@var{s})
diff --git a/neg.c b/neg.c
index 185a836c1..181c7f9cf 100644
--- a/neg.c
+++ b/neg.c
@@ -1,6 +1,6 @@
/* mpfr_neg -- change the sign of a floating-point number
-Copyright 1999, 2000, 2001 Free Software Foundation.
+Copyright 1999, 2000, 2001, 2004 Free Software Foundation.
This file is part of the MPFR Library.
Contributed by the Spaces project (LORIA/LIP6).
@@ -29,6 +29,10 @@ mpfr_neg (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
{
if (a != b)
return mpfr_set4 (a, b, rnd_mode, -MPFR_SIGN(b));
+ else if (MPFR_IS_NAN(b))
+ {
+ MPFR_RET_NAN;
+ }
else
{
MPFR_CHANGE_SIGN(a);
diff --git a/pow.c b/pow.c
index 27244593c..784893e89 100644
--- a/pow.c
+++ b/pow.c
@@ -147,7 +147,7 @@ is_odd (mpfr_srcptr y)
int
mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode)
{
- int inexact = 0;
+ int inexact = 1;
/* pow(x, ±0) returns 1 for any x, even a NaN. */
if (MPFR_IS_FP(y) && MPFR_IS_ZERO(y))
@@ -317,6 +317,7 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode)
/* compute the precision of intermediary variable */
Nt = MAX(Nx, Ny);
+ Nt = MAX(Nt, Nz); /* take account of the output precision too! */
/* the optimal number of bits : see algorithms.ps */
Nt = Nt + 5 + __gmpfr_ceil_log2 (Nt);
@@ -354,11 +355,18 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode)
/* check exact power */
if (ok == 0 && loop == 1)
- ok = mpfr_pow_is_exact (x, y);
+ {
+ ok = mpfr_pow_is_exact (x, y);
+ if (ok)
+ inexact = 0;
+ }
}
while (err < 0 || ok == 0);
- inexact = mpfr_set (z, t, rnd_mode);
+ if (inexact)
+ inexact = mpfr_set (z, t, rnd_mode);
+ else /* result is exact: round to nearest and return inexact=0 */
+ mpfr_set (z, t, GMP_RNDN);
mpfr_clear (t);
mpfr_clear (ti);
diff --git a/pow_si.c b/pow_si.c
index df49f48c5..adc0cc042 100644
--- a/pow_si.c
+++ b/pow_si.c
@@ -74,8 +74,10 @@ mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode)
/* detect exact powers: x^(-n) is exact iff x is a power of 2 */
if (mpfr_cmp_si_2exp (x, MPFR_SIGN(x), MPFR_EXP(x) - 1) == 0)
{
+ mp_exp_t expx = MPFR_EXP(x); /* warning: x and y may be the same
+ variable */
mpfr_set_si (y, (n % 2) ? MPFR_SIGN(x) : 1, rnd_mode);
- MPFR_EXP(y) += n * (MPFR_EXP(x) - 1);
+ MPFR_EXP(y) += n * (expx - 1);
return 0;
}
diff --git a/pow_ui.c b/pow_ui.c
index aa8db2020..1c2051702 100644
--- a/pow_ui.c
+++ b/pow_ui.c
@@ -29,10 +29,9 @@ MA 02111-1307, USA. */
int
mpfr_pow_ui (mpfr_ptr x, mpfr_srcptr y, unsigned long int n, mp_rnd_t rnd)
{
- long int i, err;
unsigned long m;
mpfr_t res;
- mp_prec_t prec;
+ mp_prec_t prec, err;
int inexact;
mp_rnd_t rnd1;
@@ -79,33 +78,35 @@ mpfr_pow_ui (mpfr_ptr x, mpfr_srcptr y, unsigned long int n, mp_rnd_t rnd)
do
{
+ int i;
+
prec += 3;
- for (m=n, i=0; m; i++, m>>=1, prec++);
+ for (m = n, i = 0; m; i++, m >>= 1, prec++)
+ ;
mpfr_set_prec (res, prec);
inexact = mpfr_set (res, y, rnd1);
- err = 1;
+ err = prec <= i ? 0 : prec - i;
+ MPFR_ASSERTD (i >= 1);
/* now 2^(i-1) <= n < 2^i */
- for (i-=2; i>=0; i--)
- {
- if (mpfr_mul (res, res, res, GMP_RNDU))
- inexact = 1;
- err++;
- if (n & (1UL << i))
- if (mpfr_mul (res, res, y, rnd1))
- inexact = 1;
- }
+ for (i -= 2; i >= 0; i--)
+ {
+ if (mpfr_mul (res, res, res, GMP_RNDU))
+ inexact = 1;
+ if (n & (1UL << i))
+ if (mpfr_mul (res, res, y, rnd1))
+ inexact = 1;
+ }
+ /* FIXME: infinity and 0 should be checked too. */
+ MPFR_ASSERTN (MPFR_IS_FP (res));
+ MPFR_ASSERTN (MPFR_NOTZERO (res));
/* check underflow */
- if (MPFR_EXP(res) <= (double) __gmpfr_emin)
+ if (MPFR_GET_EXP (res) <= __gmpfr_emin)
{
mpfr_clear (res);
mpfr_restore_emin_emax ();
return mpfr_set_underflow (x, rnd, (n % 2) ? MPFR_SIGN(y) : 1);
}
-
- err = prec - err;
- if (err < 0)
- err = 0;
}
while (inexact && !mpfr_can_round (res, err, GMP_RNDN, GMP_RNDZ,
MPFR_PREC(x) + (rnd == GMP_RNDN)));
diff --git a/rint.c b/rint.c
index fcc0c88b2..2c2fa461f 100644
--- a/rint.c
+++ b/rint.c
@@ -24,10 +24,16 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
+/* This may be a standard rounding mode in the future. */
+#define NEAREST_AWAY ((mp_rnd_t) -1)
+
+/* Merge the following mpfr_rint code with mpfr_round_raw_generic? */
+
int
mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
{
int sign;
+ int rnd_away;
mp_exp_t exp;
if (MPFR_IS_NAN(u))
@@ -56,12 +62,24 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
sign = MPFR_SIGN(u);
exp = MPFR_GET_EXP (u);
- /* Single out the case where |u| < 1. */
- if (exp <= 0) /* 0 < |u| < 1 */
+ rnd_away =
+ rnd_mode == GMP_RNDD ? sign < 0 :
+ rnd_mode == GMP_RNDU ? sign > 0 :
+ rnd_mode == GMP_RNDZ ? 0 : -1;
+
+ /* rnd_away:
+ 1 if round away from zero,
+ 0 if round to zero,
+ -1 if not decided yet.
+ */
+
+ if (exp <= 0) /* 0 < |u| < 1 ==> round |u| to 0 or 1 */
{
- if ((rnd_mode == GMP_RNDD && sign < 0) ||
- (rnd_mode == GMP_RNDU && sign > 0) ||
- (rnd_mode == GMP_RNDN && exp == 0))
+ /* Note: in the GMP_RNDN mode, 0.5 must be rounded to 0. */
+ if (rnd_away != 0 &&
+ (rnd_away > 0 ||
+ (exp == 0 && (rnd_mode == NEAREST_AWAY ||
+ !mpfr_powerof2_raw (u)))))
{
mp_limb_t *rp;
mp_size_t rm;
@@ -106,13 +124,14 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
{
ui = un;
idiff = 0;
- uflags = 0; /* u is an integer */
+ uflags = 0; /* u is an integer, representable or not in r */
}
else
{
mp_size_t uj;
ui = (exp - 1) / BITS_PER_MP_LIMB + 1; /* #limbs of the int part */
+ MPFR_ASSERTN (un >= ui);
uj = un - ui; /* lowest limb of the integer part */
idiff = exp % BITS_PER_MP_LIMB; /* #int-part bits in up[uj] or 0 */
@@ -128,16 +147,49 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
if (ui > rn)
{
+ /* More limbs in the integer part of u than in r.
+ Just round u with the precision of r. */
MPFR_ASSERTN(rp != up && un > rn);
MPN_COPY(rp, up + (un - rn), rn);
- /* In the rounding to the nearest mode, if the rounding bit
- is 0, change the rounding mode to GMP_RNDZ. */
- if (rnd_mode == GMP_RNDN &&
- ((sh != 0 && (rp[0] & (MP_LIMB_T_ONE << (sh - 1))) == 0) ||
- (sh == 0 && (up[un - rn - 1] & MPFR_LIMB_HIGHBIT) == 0)))
- rnd_mode = GMP_RNDZ;
+ if (rnd_away < 0)
+ {
+ /* This is a rounding to nearest mode.
+ Decide the rounding direction here. */
+ if (rnd_mode == GMP_RNDN &&
+ (rp[0] & (MP_LIMB_T_ONE << sh)) == 0)
+ { /* halfway cases rounded towards zero */
+ mp_limb_t a, b;
+ /* a: rounding bit and some of the following bits */
+ /* b: boundary for a (weight of the rounding bit in a) */
+ if (sh != 0)
+ {
+ a = rp[0] & ((MP_LIMB_T_ONE << sh) - 1);
+ b = MP_LIMB_T_ONE << (sh - 1);
+ }
+ else
+ {
+ a = up[un - rn - 1];
+ b = MPFR_LIMB_HIGHBIT;
+ }
+ rnd_away = a > b;
+ if (a == b)
+ {
+ mp_size_t i;
+ for (i = un - rn - 1 - (sh == 0); i >= 0; i--)
+ if (up[i] != 0)
+ {
+ rnd_away = 1;
+ break;
+ }
+ }
+ }
+ else /* halfway cases rounded away from zero */
+ rnd_away = /* rounding bit */
+ ((sh != 0 && (rp[0] & (MP_LIMB_T_ONE << (sh - 1))) != 0) ||
+ (sh == 0 && (up[un - rn - 1] & MPFR_LIMB_HIGHBIT) != 0));
+ }
if (uflags == 0)
- { /* u is an integer; determine if it is representable */
+ { /* u is an integer; determine if it is representable in r */
if (sh != 0 && rp[0] << (BITS_PER_MP_LIMB - sh) != 0)
uflags = 1; /* u is not representable in r */
else
@@ -151,10 +203,8 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
}
}
}
- if (sh != 0)
- rp[0] &= MP_LIMB_T_MAX << sh;
}
- else
+ else /* ui <= rn */
{
mp_size_t uj, rj;
int ush;
@@ -167,50 +217,77 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
if (rp != up)
MPN_COPY(rp + rj, up + uj, ui);
+ /* Ignore the lowest rj limbs, all equal to zero. */
rp += rj;
rn = ui;
+ /* number of fractional bits in whole rp[0] */
ush = idiff == 0 ? 0 : BITS_PER_MP_LIMB - idiff;
+
if (rj == 0 && ush < sh)
{
- /* In the rounding to the nearest mode, if the rounding bit
- is 0, change the rounding mode to GMP_RNDZ. */
- if (rnd_mode == GMP_RNDN &&
- (rp[0] & (MP_LIMB_T_ONE << (sh - 1))) == 0)
- rnd_mode = GMP_RNDZ; /* rounding bit is 0 */
- if (uflags == 0)
- { /* u is an integer; determine if it is representable */
- mp_limb_t mask;
- mask = (MP_LIMB_T_ONE << sh) - (MP_LIMB_T_ONE << ush);
- if ((rp[0] & mask) != 0)
- uflags = 1; /* u is not representable in r */
- }
+ /* If u is an integer (uflags == 0), we need to determine
+ if it is representable in r, i.e. if its sh - ush bits
+ in the non-significant part of r are all 0. */
+ if (uflags == 0 && (rp[0] & ((MP_LIMB_T_ONE << sh) -
+ (MP_LIMB_T_ONE << ush))) != 0)
+ uflags = 1; /* u is an integer not representable in r */
}
- else
+ else /* The integer part of u fits in r, we'll round to it. */
+ sh = ush;
+
+ if (rnd_away < 0)
{
- sh = ush;
- if (rnd_mode == GMP_RNDN &&
- ((ush != 0 &&
- (up[uj] & (MP_LIMB_T_ONE << (ush - 1))) == 0) ||
- (ush == 0 &&
- (uj == 0 || (up[uj - 1] & MPFR_LIMB_HIGHBIT) == 0))))
- rnd_mode = GMP_RNDZ; /* rounding bit is 0 */
+ /* This is a rounding to nearest mode.
+ Decide the rounding direction here. */
+ if (uj == 0 && sh == 0)
+ rnd_away = 0; /* rounding bit = 0 (not represented in u) */
+ else if (rnd_mode == GMP_RNDN &&
+ (rp[0] & (MP_LIMB_T_ONE << sh)) == 0)
+ { /* halfway cases rounded towards zero */
+ mp_limb_t a, b;
+ /* a: rounding bit and some of the following bits */
+ /* b: boundary for a (weight of the rounding bit in a) */
+ if (sh != 0)
+ {
+ a = rp[0] & ((MP_LIMB_T_ONE << sh) - 1);
+ b = MP_LIMB_T_ONE << (sh - 1);
+ }
+ else
+ {
+ MPFR_ASSERTN (uj >= 1); /* see above */
+ a = up[uj - 1];
+ b = MPFR_LIMB_HIGHBIT;
+ }
+ rnd_away = a > b;
+ if (a == b)
+ {
+ mp_size_t i;
+ for (i = uj - 1 - (sh == 0); i >= 0; i--)
+ if (up[i] != 0)
+ {
+ rnd_away = 1;
+ break;
+ }
+ }
+ }
+ else /* halfway cases rounded away from zero */
+ rnd_away = /* rounding bit */
+ ((sh != 0 && (rp[0] & (MP_LIMB_T_ONE << (sh - 1))) != 0) ||
+ (sh == 0 && (MPFR_ASSERTN (uj >= 1),
+ up[uj - 1] & MPFR_LIMB_HIGHBIT) != 0));
}
- if (sh != 0)
- rp[0] &= MP_LIMB_T_MAX << sh;
}
+ if (sh != 0)
+ rp[0] &= MP_LIMB_T_MAX << sh;
+
+ /* If u is a representable integer, there is no rounding. */
if (uflags == 0)
MPFR_RET(0);
- /* Note: if rnd_mode == GMP_RNDN, then round away from 0 (if
- the rounding bit was 0 and rnd_mode == GMP_RNDN, rnd_mode
- has been changed to GMP_RNDZ). */
-
- if ((rnd_mode == GMP_RNDN ||
- (rnd_mode == GMP_RNDD && sign < 0) ||
- (rnd_mode == GMP_RNDU && sign > 0))
- && mpn_add_1(rp, rp, rn, MP_LIMB_T_ONE << sh))
+ MPFR_ASSERTN (rnd_away >= 0); /* rounding direction is defined */
+ if (rnd_away && mpn_add_1(rp, rp, rn, MP_LIMB_T_ONE << sh))
{
if (exp == __gmpfr_emax)
return mpfr_set_overflow(r, rnd_mode, MPFR_SIGN(r)) >= 0 ?
@@ -222,9 +299,7 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
}
}
- MPFR_RET(rnd_mode == GMP_RNDU ||
- (rnd_mode == GMP_RNDZ && sign < 0) ||
- (rnd_mode == GMP_RNDN && sign > 0) ? uflags : -uflags);
+ MPFR_RET (rnd_away ^ (sign < 0) ? uflags : -uflags);
} /* exp > 0, |u| >= 1 */
}
@@ -233,7 +308,7 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
int
mpfr_round (mpfr_ptr r, mpfr_srcptr u)
{
- return mpfr_rint(r, u, GMP_RNDN);
+ return mpfr_rint(r, u, NEAREST_AWAY);
}
#undef mpfr_trunc
diff --git a/set_f.c b/set_f.c
index 65fe42110..e32980b36 100644
--- a/set_f.c
+++ b/set_f.c
@@ -1,6 +1,6 @@
/* mpfr_set_f -- set a MPFR number from a GNU MPF number
-Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -31,53 +31,60 @@ mpfr_set_f (mpfr_ptr y, mpf_srcptr x, mp_rnd_t rnd_mode)
{
mp_limb_t *my, *mx, *tmp;
unsigned long cnt, sx, sy;
- int inexact;
+ int inexact, carry = 0;
TMP_DECL(marker);
+ sx = ABS(SIZ(x)); /* number of limbs of the mantissa of x */
+
+ if (sx == 0) /* x is zero */
+ {
+ MPFR_CLEAR_FLAGS (y);
+ MPFR_SET_ZERO(y);
+ MPFR_SET_POS(y);
+ return 0; /* 0 is exact */
+ }
+
if (SIZ(x) * MPFR_SIGN(y) < 0)
MPFR_CHANGE_SIGN (y);
MPFR_CLEAR_FLAGS (y);
- sx = ABS(SIZ(x)); /* number of limbs of the mantissa of x */
sy = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB;
my = MPFR_MANT(y);
mx = PTR(x);
- if (sx == 0) /* x is zero */
- {
- MPFR_SET_ZERO(y);
- return 0; /* 0 is exact */
- }
-
- count_leading_zeros(cnt, mx[sx - 1]);
+ count_leading_zeros(cnt, mx[sx - 1]);
if (sy <= sx) /* we may have to round even when sy = sx */
{
unsigned long xprec = sx * BITS_PER_MP_LIMB;
TMP_MARK(marker);
- tmp = (mp_limb_t*) TMP_ALLOC(xprec);
+ tmp = (mp_limb_t*) TMP_ALLOC(sx * BYTES_PER_MP_LIMB);
if (cnt)
- mpn_lshift(tmp, mx, sx, cnt);
+ mpn_lshift (tmp, mx, sx, cnt);
else
- MPN_COPY(tmp, mx, sx);
- mpfr_round_raw (my, tmp, xprec, (SIZ(x)<0), MPFR_PREC(y), rnd_mode,
- &inexact);
+ /* FIXME: we may avoid the copy here, and directly call mpfr_round_raw
+ on mx instead of tmp */
+ MPN_COPY (tmp, mx, sx);
+ carry = mpfr_round_raw (my, tmp, xprec, (SIZ(x) < 0), MPFR_PREC(y),
+ rnd_mode, &inexact);
+ if (carry) /* result is a power of two */
+ my[sy - 1] = MPFR_LIMB_HIGHBIT;
TMP_FREE(marker);
}
else
{
if (cnt)
- mpn_lshift(my + sy - sx, mx, sx, cnt);
+ mpn_lshift (my + sy - sx, mx, sx, cnt);
else
- MPN_COPY(my + sy - sx, mx, sy);
+ MPN_COPY (my + sy - sx, mx, sx);
MPN_ZERO(my, sy - sx);
/* no rounding necessary, since y has a larger mantissa */
inexact = 0;
}
-
- MPFR_SET_EXP(y, EXP(x) * BITS_PER_MP_LIMB - cnt);
+
+ MPFR_SET_EXP(y, EXP(x) * BITS_PER_MP_LIMB - cnt + carry);
return inexact;
}
diff --git a/sqrt.c b/sqrt.c
index a8483cd3e..27c07a06a 100644
--- a/sqrt.c
+++ b/sqrt.c
@@ -1,6 +1,6 @@
/* mpfr_sqrt -- square root of a floating-point number
-Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -264,7 +264,7 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
/* Is a shift necessary here? Isn't the result 1.0000...? */
mpn_rshift (rp, rp, rrsize, 1);
rp[rrsize-1] |= MPFR_LIMB_HIGHBIT;
- MPFR_SET_EXP (r, MPFR_GET_EXP (r) + 1);
+ MPFR_SET_EXP (r, MPFR_EXP (r) + 1);
}
fin:
diff --git a/sub1.c b/sub1.c
index 6c12e3877..eca9c97c3 100644
--- a/sub1.c
+++ b/sub1.c
@@ -1,6 +1,6 @@
/* mpfr_sub1 -- internal function to perform a "real" subtraction
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
Contributed by the Spaces project, INRIA Lorraine.
This file is part of the MPFR Library.
@@ -83,6 +83,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode,
if (shift_b)
shift_b = BITS_PER_MP_LIMB - shift_b;
cancel1 = (cancel + shift_b) / BITS_PER_MP_LIMB;
+
/* the high cancel1 limbs from b should not be taken into account */
if (shift_b == 0)
bp = MPFR_MANT(b); /* no need of an extra space */
@@ -261,42 +262,46 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode,
for (k = 0; (bn > 0) || (cn > 0); k = 1)
{
+ /* get next limbs */
bb = (bn > 0) ? bp[--bn] : 0;
if ((cn > 0) && (cn-- <= cn0))
cc = cp[cn];
else
cc = 0;
+ /* down is set when low(b) < low(c) */
if (down == 0)
down = (bb < cc);
- if ((rnd_mode == GMP_RNDN) && !k && sh == 0)
+ /* the case rounding to nearest with sh=0 is special since one couldn't
+ subtract above 1/2 ulp in the trailing limb of the result */
+ if ((rnd_mode == GMP_RNDN) && sh == 0 && k == 0)
{
- mp_limb_t half = MPFR_LIMB_HIGHBIT;
-
- is_exact = (bb == cc);
-
- /* add one ulp if bb > cc + half
- truncate if cc - half < bb < cc + half
- sub one ulp if bb < cc - half
- */
-
- if (down)
- {
- if (cc >= half)
- cc -= half;
- else
- bb += half;
- }
- else /* bb >= cc */
- {
- if (cc < half)
- cc += half;
- else
- bb -= half;
- }
+ mp_limb_t half = MPFR_LIMB_HIGHBIT;
+
+ is_exact = (bb == cc);
+
+ /* add one ulp if bb > cc + half
+ truncate if cc - half < bb < cc + half
+ sub one ulp if bb < cc - half
+ */
+
+ if (down)
+ {
+ if (cc >= half)
+ cc -= half;
+ else
+ bb += half;
+ }
+ else /* bb >= cc */
+ {
+ if (cc < half)
+ cc += half;
+ else
+ bb -= half;
+ }
}
-
+
#ifdef DEBUG
printf(" bb=%lu cc=%lu down=%d is_exact=%d\n", bb, cc, down, is_exact);
#endif
@@ -309,12 +314,19 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode,
inexact = 1;
goto truncate;
}
- else /* round to nearest */
+ else /* round to nearest: special case here since for sh=k=0
+ bb = bb0 - MPFR_LIMB_HIGHBIT */
{
if (is_exact && sh == 0)
{
- inexact = 0;
- goto truncate;
+ /* For k=0 we can't decide exactness since it may depend
+ from low order bits.
+ For k=1, the first low limbs matched: low(b)-low(c)<0. */
+ if (k)
+ {
+ inexact = 1;
+ goto truncate;
+ }
}
else if (down && sh == 0)
goto sub_one_ulp;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2f8b43723..4c6f5b1b9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,7 @@
AUTOMAKE_OPTIONS = gnu
-check_PROGRAMS = tinits reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui teq texp tfrac tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc trint tisnan tget_d tget_d_2exp tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos tgamma tset_ld tcbrt tsin_cos mpf_compat mpfr_compat tzeta tcmp_d terf tnext tcomparisons
+check_PROGRAMS = tinits reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui teq texp tfrac tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc trint tisnan tget_d tget_d_2exp tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos tgamma tset_ld tcbrt tsin_cos mpf_compat mpfr_compat tzeta tcmp_d terf tnext tcomparisons tgmpop
+
EXTRA_DIST = tgeneric.c mpf_compat.h
LDADD = libfrtests.a $(MPFR_LIBM) $(top_builddir)/libmpfr.a @LDADD@
diff --git a/tests/Makefile.in b/tests/Makefile.in
deleted file mode 100644
index 4cdbe3005..000000000
--- a/tests/Makefile.in
+++ /dev/null
@@ -1,920 +0,0 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
-
-# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-
-SHELL = @SHELL@
-
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-VPATH = @srcdir@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-
-bindir = @bindir@
-sbindir = @sbindir@
-libexecdir = @libexecdir@
-datadir = @datadir@
-sysconfdir = @sysconfdir@
-sharedstatedir = @sharedstatedir@
-localstatedir = @localstatedir@
-libdir = @libdir@
-infodir = @infodir@
-mandir = @mandir@
-includedir = @includedir@
-oldincludedir = /usr/include
-
-DESTDIR =
-
-pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-
-top_builddir = ..
-
-ACLOCAL = @ACLOCAL@
-AUTOCONF = @AUTOCONF@
-AUTOMAKE = @AUTOMAKE@
-AUTOHEADER = @AUTOHEADER@
-
-INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-transform = @program_transform_name@
-
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-CC = @CC@
-CFLAGS = @CFLAGS@
-LDFLAGS = @LDFLAGS@
-MAKEINFO = @MAKEINFO@
-MISCFLAGS = @MISCFLAGS@
-PACKAGE = @PACKAGE@
-RANLIB = @RANLIB@
-VERSION = @VERSION@
-
-check_PROGRAMS = reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui tdump teq texp tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc trint tisnan tget_d tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos
-EXTRA_DIST = tgeneric.c
-
-LDADD = $(top_builddir)/libmpfr.a @LDADD@
-INCLUDES = -I$(top_srcdir) @INCLUDES@
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_CLEAN_FILES =
-
-DEFS = @DEFS@ -I. -I$(srcdir)
-CPPFLAGS = @CPPFLAGS@
-LIBS = @LIBS@
-reuse_SOURCES = reuse.c
-reuse_OBJECTS = reuse.o
-reuse_LDADD = $(LDADD)
-reuse_DEPENDENCIES = $(top_builddir)/libmpfr.a
-reuse_LDFLAGS =
-tabs_SOURCES = tabs.c
-tabs_OBJECTS = tabs.o
-tabs_LDADD = $(LDADD)
-tabs_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tabs_LDFLAGS =
-tadd_SOURCES = tadd.c
-tadd_OBJECTS = tadd.o
-tadd_LDADD = $(LDADD)
-tadd_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tadd_LDFLAGS =
-tagm_SOURCES = tagm.c
-tagm_OBJECTS = tagm.o
-tagm_LDADD = $(LDADD)
-tagm_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tagm_LDFLAGS =
-tcan_round_SOURCES = tcan_round.c
-tcan_round_OBJECTS = tcan_round.o
-tcan_round_LDADD = $(LDADD)
-tcan_round_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tcan_round_LDFLAGS =
-tcmp_SOURCES = tcmp.c
-tcmp_OBJECTS = tcmp.o
-tcmp_LDADD = $(LDADD)
-tcmp_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tcmp_LDFLAGS =
-tcmp2_SOURCES = tcmp2.c
-tcmp2_OBJECTS = tcmp2.o
-tcmp2_LDADD = $(LDADD)
-tcmp2_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tcmp2_LDFLAGS =
-tcmp_ui_SOURCES = tcmp_ui.c
-tcmp_ui_OBJECTS = tcmp_ui.o
-tcmp_ui_LDADD = $(LDADD)
-tcmp_ui_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tcmp_ui_LDFLAGS =
-tdiv_SOURCES = tdiv.c
-tdiv_OBJECTS = tdiv.o
-tdiv_LDADD = $(LDADD)
-tdiv_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tdiv_LDFLAGS =
-tdiv_ui_SOURCES = tdiv_ui.c
-tdiv_ui_OBJECTS = tdiv_ui.o
-tdiv_ui_LDADD = $(LDADD)
-tdiv_ui_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tdiv_ui_LDFLAGS =
-tdump_SOURCES = tdump.c
-tdump_OBJECTS = tdump.o
-tdump_LDADD = $(LDADD)
-tdump_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tdump_LDFLAGS =
-teq_SOURCES = teq.c
-teq_OBJECTS = teq.o
-teq_LDADD = $(LDADD)
-teq_DEPENDENCIES = $(top_builddir)/libmpfr.a
-teq_LDFLAGS =
-texp_SOURCES = texp.c
-texp_OBJECTS = texp.o
-texp_LDADD = $(LDADD)
-texp_DEPENDENCIES = $(top_builddir)/libmpfr.a
-texp_LDFLAGS =
-tget_str_SOURCES = tget_str.c
-tget_str_OBJECTS = tget_str.o
-tget_str_LDADD = $(LDADD)
-tget_str_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tget_str_LDFLAGS =
-tlog_SOURCES = tlog.c
-tlog_OBJECTS = tlog.o
-tlog_LDADD = $(LDADD)
-tlog_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tlog_LDFLAGS =
-tconst_log2_SOURCES = tconst_log2.c
-tconst_log2_OBJECTS = tconst_log2.o
-tconst_log2_LDADD = $(LDADD)
-tconst_log2_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tconst_log2_LDFLAGS =
-tmul_SOURCES = tmul.c
-tmul_OBJECTS = tmul.o
-tmul_LDADD = $(LDADD)
-tmul_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tmul_LDFLAGS =
-tmul_2exp_SOURCES = tmul_2exp.c
-tmul_2exp_OBJECTS = tmul_2exp.o
-tmul_2exp_LDADD = $(LDADD)
-tmul_2exp_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tmul_2exp_LDFLAGS =
-tmul_ui_SOURCES = tmul_ui.c
-tmul_ui_OBJECTS = tmul_ui.o
-tmul_ui_LDADD = $(LDADD)
-tmul_ui_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tmul_ui_LDFLAGS =
-tout_str_SOURCES = tout_str.c
-tout_str_OBJECTS = tout_str.o
-tout_str_LDADD = $(LDADD)
-tout_str_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tout_str_LDFLAGS =
-tconst_pi_SOURCES = tconst_pi.c
-tconst_pi_OBJECTS = tconst_pi.o
-tconst_pi_LDADD = $(LDADD)
-tconst_pi_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tconst_pi_LDFLAGS =
-tpow_SOURCES = tpow.c
-tpow_OBJECTS = tpow.o
-tpow_LDADD = $(LDADD)
-tpow_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tpow_LDFLAGS =
-trandom_SOURCES = trandom.c
-trandom_OBJECTS = trandom.o
-trandom_LDADD = $(LDADD)
-trandom_DEPENDENCIES = $(top_builddir)/libmpfr.a
-trandom_LDFLAGS =
-tround_prec_SOURCES = tround_prec.c
-tround_prec_OBJECTS = tround_prec.o
-tround_prec_LDADD = $(LDADD)
-tround_prec_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tround_prec_LDFLAGS =
-tset_d_SOURCES = tset_d.c
-tset_d_OBJECTS = tset_d.o
-tset_d_LDADD = $(LDADD)
-tset_d_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_d_LDFLAGS =
-tset_f_SOURCES = tset_f.c
-tset_f_OBJECTS = tset_f.o
-tset_f_LDADD = $(LDADD)
-tset_f_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_f_LDFLAGS =
-tset_q_SOURCES = tset_q.c
-tset_q_OBJECTS = tset_q.o
-tset_q_LDADD = $(LDADD)
-tset_q_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_q_LDFLAGS =
-tset_si_SOURCES = tset_si.c
-tset_si_OBJECTS = tset_si.o
-tset_si_LDADD = $(LDADD)
-tset_si_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_si_LDFLAGS =
-tset_str_SOURCES = tset_str.c
-tset_str_OBJECTS = tset_str.o
-tset_str_LDADD = $(LDADD)
-tset_str_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_str_LDFLAGS =
-tset_z_SOURCES = tset_z.c
-tset_z_OBJECTS = tset_z.o
-tset_z_LDADD = $(LDADD)
-tset_z_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_z_LDFLAGS =
-tsqrt_SOURCES = tsqrt.c
-tsqrt_OBJECTS = tsqrt.o
-tsqrt_LDADD = $(LDADD)
-tsqrt_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tsqrt_LDFLAGS =
-tsqrt_ui_SOURCES = tsqrt_ui.c
-tsqrt_ui_OBJECTS = tsqrt_ui.o
-tsqrt_ui_LDADD = $(LDADD)
-tsqrt_ui_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tsqrt_ui_LDFLAGS =
-tui_div_SOURCES = tui_div.c
-tui_div_OBJECTS = tui_div.o
-tui_div_LDADD = $(LDADD)
-tui_div_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tui_div_LDFLAGS =
-tui_sub_SOURCES = tui_sub.c
-tui_sub_OBJECTS = tui_sub.o
-tui_sub_LDADD = $(LDADD)
-tui_sub_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tui_sub_LDFLAGS =
-tswap_SOURCES = tswap.c
-tswap_OBJECTS = tswap.o
-tswap_LDADD = $(LDADD)
-tswap_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tswap_LDFLAGS =
-ttrunc_SOURCES = ttrunc.c
-ttrunc_OBJECTS = ttrunc.o
-ttrunc_LDADD = $(LDADD)
-ttrunc_DEPENDENCIES = $(top_builddir)/libmpfr.a
-ttrunc_LDFLAGS =
-trint_SOURCES = trint.c
-trint_OBJECTS = trint.o
-trint_LDADD = $(LDADD)
-trint_DEPENDENCIES = $(top_builddir)/libmpfr.a
-trint_LDFLAGS =
-tisnan_SOURCES = tisnan.c
-tisnan_OBJECTS = tisnan.o
-tisnan_LDADD = $(LDADD)
-tisnan_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tisnan_LDFLAGS =
-tget_d_SOURCES = tget_d.c
-tget_d_OBJECTS = tget_d.o
-tget_d_LDADD = $(LDADD)
-tget_d_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tget_d_LDFLAGS =
-tatan_SOURCES = tatan.c
-tatan_OBJECTS = tatan.o
-tatan_LDADD = $(LDADD)
-tatan_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tatan_LDFLAGS =
-tcosh_SOURCES = tcosh.c
-tcosh_OBJECTS = tcosh.o
-tcosh_LDADD = $(LDADD)
-tcosh_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tcosh_LDFLAGS =
-tsinh_SOURCES = tsinh.c
-tsinh_OBJECTS = tsinh.o
-tsinh_LDADD = $(LDADD)
-tsinh_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tsinh_LDFLAGS =
-ttanh_SOURCES = ttanh.c
-ttanh_OBJECTS = ttanh.o
-ttanh_LDADD = $(LDADD)
-ttanh_DEPENDENCIES = $(top_builddir)/libmpfr.a
-ttanh_LDFLAGS =
-tacosh_SOURCES = tacosh.c
-tacosh_OBJECTS = tacosh.o
-tacosh_LDADD = $(LDADD)
-tacosh_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tacosh_LDFLAGS =
-tasinh_SOURCES = tasinh.c
-tasinh_OBJECTS = tasinh.o
-tasinh_LDADD = $(LDADD)
-tasinh_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tasinh_LDFLAGS =
-tatanh_SOURCES = tatanh.c
-tatanh_OBJECTS = tatanh.o
-tatanh_LDADD = $(LDADD)
-tatanh_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tatanh_LDFLAGS =
-thyperbolic_SOURCES = thyperbolic.c
-thyperbolic_OBJECTS = thyperbolic.o
-thyperbolic_LDADD = $(LDADD)
-thyperbolic_DEPENDENCIES = $(top_builddir)/libmpfr.a
-thyperbolic_LDFLAGS =
-texp2_SOURCES = texp2.c
-texp2_OBJECTS = texp2.o
-texp2_LDADD = $(LDADD)
-texp2_DEPENDENCIES = $(top_builddir)/libmpfr.a
-texp2_LDFLAGS =
-tfactorial_SOURCES = tfactorial.c
-tfactorial_OBJECTS = tfactorial.o
-tfactorial_LDADD = $(LDADD)
-tfactorial_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tfactorial_LDFLAGS =
-tsub_SOURCES = tsub.c
-tsub_OBJECTS = tsub.o
-tsub_LDADD = $(LDADD)
-tsub_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tsub_LDFLAGS =
-tasin_SOURCES = tasin.c
-tasin_OBJECTS = tasin.o
-tasin_LDADD = $(LDADD)
-tasin_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tasin_LDFLAGS =
-tconst_euler_SOURCES = tconst_euler.c
-tconst_euler_OBJECTS = tconst_euler.o
-tconst_euler_LDADD = $(LDADD)
-tconst_euler_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tconst_euler_LDFLAGS =
-tcos_SOURCES = tcos.c
-tcos_OBJECTS = tcos.o
-tcos_LDADD = $(LDADD)
-tcos_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tcos_LDFLAGS =
-tsin_SOURCES = tsin.c
-tsin_OBJECTS = tsin.o
-tsin_LDADD = $(LDADD)
-tsin_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tsin_LDFLAGS =
-ttan_SOURCES = ttan.c
-ttan_OBJECTS = ttan.o
-ttan_LDADD = $(LDADD)
-ttan_DEPENDENCIES = $(top_builddir)/libmpfr.a
-ttan_LDFLAGS =
-tsub_ui_SOURCES = tsub_ui.c
-tsub_ui_OBJECTS = tsub_ui.o
-tsub_ui_LDADD = $(LDADD)
-tsub_ui_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tsub_ui_LDFLAGS =
-tset_SOURCES = tset.c
-tset_OBJECTS = tset.o
-tset_LDADD = $(LDADD)
-tset_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tset_LDFLAGS =
-tlog1p_SOURCES = tlog1p.c
-tlog1p_OBJECTS = tlog1p.o
-tlog1p_LDADD = $(LDADD)
-tlog1p_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tlog1p_LDFLAGS =
-texpm1_SOURCES = texpm1.c
-texpm1_OBJECTS = texpm1.o
-texpm1_LDADD = $(LDADD)
-texpm1_DEPENDENCIES = $(top_builddir)/libmpfr.a
-texpm1_LDFLAGS =
-tlog2_SOURCES = tlog2.c
-tlog2_OBJECTS = tlog2.o
-tlog2_LDADD = $(LDADD)
-tlog2_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tlog2_LDFLAGS =
-tlog10_SOURCES = tlog10.c
-tlog10_OBJECTS = tlog10.o
-tlog10_LDADD = $(LDADD)
-tlog10_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tlog10_LDFLAGS =
-tui_pow_SOURCES = tui_pow.c
-tui_pow_OBJECTS = tui_pow.o
-tui_pow_LDADD = $(LDADD)
-tui_pow_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tui_pow_LDFLAGS =
-tpow3_SOURCES = tpow3.c
-tpow3_OBJECTS = tpow3.o
-tpow3_LDADD = $(LDADD)
-tpow3_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tpow3_LDFLAGS =
-tadd_ui_SOURCES = tadd_ui.c
-tadd_ui_OBJECTS = tadd_ui.o
-tadd_ui_LDADD = $(LDADD)
-tadd_ui_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tadd_ui_LDFLAGS =
-texceptions_SOURCES = texceptions.c
-texceptions_OBJECTS = texceptions.o
-texceptions_LDADD = $(LDADD)
-texceptions_DEPENDENCIES = $(top_builddir)/libmpfr.a
-texceptions_LDFLAGS =
-tfma_SOURCES = tfma.c
-tfma_OBJECTS = tfma.o
-tfma_LDADD = $(LDADD)
-tfma_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tfma_LDFLAGS =
-thypot_SOURCES = thypot.c
-thypot_OBJECTS = thypot.o
-thypot_LDADD = $(LDADD)
-thypot_DEPENDENCIES = $(top_builddir)/libmpfr.a
-thypot_LDFLAGS =
-tacos_SOURCES = tacos.c
-tacos_OBJECTS = tacos.o
-tacos_LDADD = $(LDADD)
-tacos_DEPENDENCIES = $(top_builddir)/libmpfr.a
-tacos_LDFLAGS =
-COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
-DIST_COMMON = Makefile.am Makefile.in
-
-
-DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-
-TAR = gtar
-GZIP_ENV = --best
-DEP_FILES = .deps/reuse.P .deps/tabs.P .deps/tacos.P .deps/tacosh.P \
-.deps/tadd.P .deps/tadd_ui.P .deps/tagm.P .deps/tasin.P .deps/tasinh.P \
-.deps/tatan.P .deps/tatanh.P .deps/tcan_round.P .deps/tcmp.P \
-.deps/tcmp2.P .deps/tcmp_ui.P .deps/tconst_euler.P .deps/tconst_log2.P \
-.deps/tconst_pi.P .deps/tcos.P .deps/tcosh.P .deps/tdiv.P \
-.deps/tdiv_ui.P .deps/tdump.P .deps/teq.P .deps/texceptions.P \
-.deps/texp.P .deps/texp2.P .deps/texpm1.P .deps/tfactorial.P \
-.deps/tfma.P .deps/tget_d.P .deps/tget_str.P .deps/thyperbolic.P \
-.deps/thypot.P .deps/tisnan.P .deps/tlog.P .deps/tlog10.P \
-.deps/tlog1p.P .deps/tlog2.P .deps/tmul.P .deps/tmul_2exp.P \
-.deps/tmul_ui.P .deps/tout_str.P .deps/tpow.P .deps/tpow3.P \
-.deps/trandom.P .deps/trint.P .deps/tround_prec.P .deps/tset.P \
-.deps/tset_d.P .deps/tset_f.P .deps/tset_q.P .deps/tset_si.P \
-.deps/tset_str.P .deps/tset_z.P .deps/tsin.P .deps/tsinh.P \
-.deps/tsqrt.P .deps/tsqrt_ui.P .deps/tsub.P .deps/tsub_ui.P \
-.deps/tswap.P .deps/ttan.P .deps/ttanh.P .deps/ttrunc.P .deps/tui_div.P \
-.deps/tui_pow.P .deps/tui_sub.P
-SOURCES = reuse.c tabs.c tadd.c tagm.c tcan_round.c tcmp.c tcmp2.c tcmp_ui.c tdiv.c tdiv_ui.c tdump.c teq.c texp.c tget_str.c tlog.c tconst_log2.c tmul.c tmul_2exp.c tmul_ui.c tout_str.c tconst_pi.c tpow.c trandom.c tround_prec.c tset_d.c tset_f.c tset_q.c tset_si.c tset_str.c tset_z.c tsqrt.c tsqrt_ui.c tui_div.c tui_sub.c tswap.c ttrunc.c trint.c tisnan.c tget_d.c tatan.c tcosh.c tsinh.c ttanh.c tacosh.c tasinh.c tatanh.c thyperbolic.c texp2.c tfactorial.c tsub.c tasin.c tconst_euler.c tcos.c tsin.c ttan.c tsub_ui.c tset.c tlog1p.c texpm1.c tlog2.c tlog10.c tui_pow.c tpow3.c tadd_ui.c texceptions.c tfma.c thypot.c tacos.c
-OBJECTS = reuse.o tabs.o tadd.o tagm.o tcan_round.o tcmp.o tcmp2.o tcmp_ui.o tdiv.o tdiv_ui.o tdump.o teq.o texp.o tget_str.o tlog.o tconst_log2.o tmul.o tmul_2exp.o tmul_ui.o tout_str.o tconst_pi.o tpow.o trandom.o tround_prec.o tset_d.o tset_f.o tset_q.o tset_si.o tset_str.o tset_z.o tsqrt.o tsqrt_ui.o tui_div.o tui_sub.o tswap.o ttrunc.o trint.o tisnan.o tget_d.o tatan.o tcosh.o tsinh.o ttanh.o tacosh.o tasinh.o tatanh.o thyperbolic.o texp2.o tfactorial.o tsub.o tasin.o tconst_euler.o tcos.o tsin.o ttan.o tsub_ui.o tset.o tlog1p.o texpm1.o tlog2.o tlog10.o tui_pow.o tpow3.o tadd_ui.o texceptions.o tfma.o thypot.o tacos.o
-
-all: all-redirect
-.SUFFIXES:
-.SUFFIXES: .S .c .o .s
-$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
- cd $(top_srcdir) && $(AUTOMAKE) --gnu tests/Makefile
-
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
- cd $(top_builddir) \
- && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-
-mostlyclean-checkPROGRAMS:
-
-clean-checkPROGRAMS:
- -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS)
-
-distclean-checkPROGRAMS:
-
-maintainer-clean-checkPROGRAMS:
-
-.s.o:
- $(COMPILE) -c $<
-
-.S.o:
- $(COMPILE) -c $<
-
-mostlyclean-compile:
- -rm -f *.o core *.core
-
-clean-compile:
-
-distclean-compile:
- -rm -f *.tab.c
-
-maintainer-clean-compile:
-
-reuse: $(reuse_OBJECTS) $(reuse_DEPENDENCIES)
- @rm -f reuse
- $(LINK) $(reuse_LDFLAGS) $(reuse_OBJECTS) $(reuse_LDADD) $(LIBS)
-
-tabs: $(tabs_OBJECTS) $(tabs_DEPENDENCIES)
- @rm -f tabs
- $(LINK) $(tabs_LDFLAGS) $(tabs_OBJECTS) $(tabs_LDADD) $(LIBS)
-
-tadd: $(tadd_OBJECTS) $(tadd_DEPENDENCIES)
- @rm -f tadd
- $(LINK) $(tadd_LDFLAGS) $(tadd_OBJECTS) $(tadd_LDADD) $(LIBS)
-
-tagm: $(tagm_OBJECTS) $(tagm_DEPENDENCIES)
- @rm -f tagm
- $(LINK) $(tagm_LDFLAGS) $(tagm_OBJECTS) $(tagm_LDADD) $(LIBS)
-
-tcan_round: $(tcan_round_OBJECTS) $(tcan_round_DEPENDENCIES)
- @rm -f tcan_round
- $(LINK) $(tcan_round_LDFLAGS) $(tcan_round_OBJECTS) $(tcan_round_LDADD) $(LIBS)
-
-tcmp: $(tcmp_OBJECTS) $(tcmp_DEPENDENCIES)
- @rm -f tcmp
- $(LINK) $(tcmp_LDFLAGS) $(tcmp_OBJECTS) $(tcmp_LDADD) $(LIBS)
-
-tcmp2: $(tcmp2_OBJECTS) $(tcmp2_DEPENDENCIES)
- @rm -f tcmp2
- $(LINK) $(tcmp2_LDFLAGS) $(tcmp2_OBJECTS) $(tcmp2_LDADD) $(LIBS)
-
-tcmp_ui: $(tcmp_ui_OBJECTS) $(tcmp_ui_DEPENDENCIES)
- @rm -f tcmp_ui
- $(LINK) $(tcmp_ui_LDFLAGS) $(tcmp_ui_OBJECTS) $(tcmp_ui_LDADD) $(LIBS)
-
-tdiv: $(tdiv_OBJECTS) $(tdiv_DEPENDENCIES)
- @rm -f tdiv
- $(LINK) $(tdiv_LDFLAGS) $(tdiv_OBJECTS) $(tdiv_LDADD) $(LIBS)
-
-tdiv_ui: $(tdiv_ui_OBJECTS) $(tdiv_ui_DEPENDENCIES)
- @rm -f tdiv_ui
- $(LINK) $(tdiv_ui_LDFLAGS) $(tdiv_ui_OBJECTS) $(tdiv_ui_LDADD) $(LIBS)
-
-tdump: $(tdump_OBJECTS) $(tdump_DEPENDENCIES)
- @rm -f tdump
- $(LINK) $(tdump_LDFLAGS) $(tdump_OBJECTS) $(tdump_LDADD) $(LIBS)
-
-teq: $(teq_OBJECTS) $(teq_DEPENDENCIES)
- @rm -f teq
- $(LINK) $(teq_LDFLAGS) $(teq_OBJECTS) $(teq_LDADD) $(LIBS)
-
-texp: $(texp_OBJECTS) $(texp_DEPENDENCIES)
- @rm -f texp
- $(LINK) $(texp_LDFLAGS) $(texp_OBJECTS) $(texp_LDADD) $(LIBS)
-
-tget_str: $(tget_str_OBJECTS) $(tget_str_DEPENDENCIES)
- @rm -f tget_str
- $(LINK) $(tget_str_LDFLAGS) $(tget_str_OBJECTS) $(tget_str_LDADD) $(LIBS)
-
-tlog: $(tlog_OBJECTS) $(tlog_DEPENDENCIES)
- @rm -f tlog
- $(LINK) $(tlog_LDFLAGS) $(tlog_OBJECTS) $(tlog_LDADD) $(LIBS)
-
-tconst_log2: $(tconst_log2_OBJECTS) $(tconst_log2_DEPENDENCIES)
- @rm -f tconst_log2
- $(LINK) $(tconst_log2_LDFLAGS) $(tconst_log2_OBJECTS) $(tconst_log2_LDADD) $(LIBS)
-
-tmul: $(tmul_OBJECTS) $(tmul_DEPENDENCIES)
- @rm -f tmul
- $(LINK) $(tmul_LDFLAGS) $(tmul_OBJECTS) $(tmul_LDADD) $(LIBS)
-
-tmul_2exp: $(tmul_2exp_OBJECTS) $(tmul_2exp_DEPENDENCIES)
- @rm -f tmul_2exp
- $(LINK) $(tmul_2exp_LDFLAGS) $(tmul_2exp_OBJECTS) $(tmul_2exp_LDADD) $(LIBS)
-
-tmul_ui: $(tmul_ui_OBJECTS) $(tmul_ui_DEPENDENCIES)
- @rm -f tmul_ui
- $(LINK) $(tmul_ui_LDFLAGS) $(tmul_ui_OBJECTS) $(tmul_ui_LDADD) $(LIBS)
-
-tout_str: $(tout_str_OBJECTS) $(tout_str_DEPENDENCIES)
- @rm -f tout_str
- $(LINK) $(tout_str_LDFLAGS) $(tout_str_OBJECTS) $(tout_str_LDADD) $(LIBS)
-
-tconst_pi: $(tconst_pi_OBJECTS) $(tconst_pi_DEPENDENCIES)
- @rm -f tconst_pi
- $(LINK) $(tconst_pi_LDFLAGS) $(tconst_pi_OBJECTS) $(tconst_pi_LDADD) $(LIBS)
-
-tpow: $(tpow_OBJECTS) $(tpow_DEPENDENCIES)
- @rm -f tpow
- $(LINK) $(tpow_LDFLAGS) $(tpow_OBJECTS) $(tpow_LDADD) $(LIBS)
-
-trandom: $(trandom_OBJECTS) $(trandom_DEPENDENCIES)
- @rm -f trandom
- $(LINK) $(trandom_LDFLAGS) $(trandom_OBJECTS) $(trandom_LDADD) $(LIBS)
-
-tround_prec: $(tround_prec_OBJECTS) $(tround_prec_DEPENDENCIES)
- @rm -f tround_prec
- $(LINK) $(tround_prec_LDFLAGS) $(tround_prec_OBJECTS) $(tround_prec_LDADD) $(LIBS)
-
-tset_d: $(tset_d_OBJECTS) $(tset_d_DEPENDENCIES)
- @rm -f tset_d
- $(LINK) $(tset_d_LDFLAGS) $(tset_d_OBJECTS) $(tset_d_LDADD) $(LIBS)
-
-tset_f: $(tset_f_OBJECTS) $(tset_f_DEPENDENCIES)
- @rm -f tset_f
- $(LINK) $(tset_f_LDFLAGS) $(tset_f_OBJECTS) $(tset_f_LDADD) $(LIBS)
-
-tset_q: $(tset_q_OBJECTS) $(tset_q_DEPENDENCIES)
- @rm -f tset_q
- $(LINK) $(tset_q_LDFLAGS) $(tset_q_OBJECTS) $(tset_q_LDADD) $(LIBS)
-
-tset_si: $(tset_si_OBJECTS) $(tset_si_DEPENDENCIES)
- @rm -f tset_si
- $(LINK) $(tset_si_LDFLAGS) $(tset_si_OBJECTS) $(tset_si_LDADD) $(LIBS)
-
-tset_str: $(tset_str_OBJECTS) $(tset_str_DEPENDENCIES)
- @rm -f tset_str
- $(LINK) $(tset_str_LDFLAGS) $(tset_str_OBJECTS) $(tset_str_LDADD) $(LIBS)
-
-tset_z: $(tset_z_OBJECTS) $(tset_z_DEPENDENCIES)
- @rm -f tset_z
- $(LINK) $(tset_z_LDFLAGS) $(tset_z_OBJECTS) $(tset_z_LDADD) $(LIBS)
-
-tsqrt: $(tsqrt_OBJECTS) $(tsqrt_DEPENDENCIES)
- @rm -f tsqrt
- $(LINK) $(tsqrt_LDFLAGS) $(tsqrt_OBJECTS) $(tsqrt_LDADD) $(LIBS)
-
-tsqrt_ui: $(tsqrt_ui_OBJECTS) $(tsqrt_ui_DEPENDENCIES)
- @rm -f tsqrt_ui
- $(LINK) $(tsqrt_ui_LDFLAGS) $(tsqrt_ui_OBJECTS) $(tsqrt_ui_LDADD) $(LIBS)
-
-tui_div: $(tui_div_OBJECTS) $(tui_div_DEPENDENCIES)
- @rm -f tui_div
- $(LINK) $(tui_div_LDFLAGS) $(tui_div_OBJECTS) $(tui_div_LDADD) $(LIBS)
-
-tui_sub: $(tui_sub_OBJECTS) $(tui_sub_DEPENDENCIES)
- @rm -f tui_sub
- $(LINK) $(tui_sub_LDFLAGS) $(tui_sub_OBJECTS) $(tui_sub_LDADD) $(LIBS)
-
-tswap: $(tswap_OBJECTS) $(tswap_DEPENDENCIES)
- @rm -f tswap
- $(LINK) $(tswap_LDFLAGS) $(tswap_OBJECTS) $(tswap_LDADD) $(LIBS)
-
-ttrunc: $(ttrunc_OBJECTS) $(ttrunc_DEPENDENCIES)
- @rm -f ttrunc
- $(LINK) $(ttrunc_LDFLAGS) $(ttrunc_OBJECTS) $(ttrunc_LDADD) $(LIBS)
-
-trint: $(trint_OBJECTS) $(trint_DEPENDENCIES)
- @rm -f trint
- $(LINK) $(trint_LDFLAGS) $(trint_OBJECTS) $(trint_LDADD) $(LIBS)
-
-tisnan: $(tisnan_OBJECTS) $(tisnan_DEPENDENCIES)
- @rm -f tisnan
- $(LINK) $(tisnan_LDFLAGS) $(tisnan_OBJECTS) $(tisnan_LDADD) $(LIBS)
-
-tget_d: $(tget_d_OBJECTS) $(tget_d_DEPENDENCIES)
- @rm -f tget_d
- $(LINK) $(tget_d_LDFLAGS) $(tget_d_OBJECTS) $(tget_d_LDADD) $(LIBS)
-
-tatan: $(tatan_OBJECTS) $(tatan_DEPENDENCIES)
- @rm -f tatan
- $(LINK) $(tatan_LDFLAGS) $(tatan_OBJECTS) $(tatan_LDADD) $(LIBS)
-
-tcosh: $(tcosh_OBJECTS) $(tcosh_DEPENDENCIES)
- @rm -f tcosh
- $(LINK) $(tcosh_LDFLAGS) $(tcosh_OBJECTS) $(tcosh_LDADD) $(LIBS)
-
-tsinh: $(tsinh_OBJECTS) $(tsinh_DEPENDENCIES)
- @rm -f tsinh
- $(LINK) $(tsinh_LDFLAGS) $(tsinh_OBJECTS) $(tsinh_LDADD) $(LIBS)
-
-ttanh: $(ttanh_OBJECTS) $(ttanh_DEPENDENCIES)
- @rm -f ttanh
- $(LINK) $(ttanh_LDFLAGS) $(ttanh_OBJECTS) $(ttanh_LDADD) $(LIBS)
-
-tacosh: $(tacosh_OBJECTS) $(tacosh_DEPENDENCIES)
- @rm -f tacosh
- $(LINK) $(tacosh_LDFLAGS) $(tacosh_OBJECTS) $(tacosh_LDADD) $(LIBS)
-
-tasinh: $(tasinh_OBJECTS) $(tasinh_DEPENDENCIES)
- @rm -f tasinh
- $(LINK) $(tasinh_LDFLAGS) $(tasinh_OBJECTS) $(tasinh_LDADD) $(LIBS)
-
-tatanh: $(tatanh_OBJECTS) $(tatanh_DEPENDENCIES)
- @rm -f tatanh
- $(LINK) $(tatanh_LDFLAGS) $(tatanh_OBJECTS) $(tatanh_LDADD) $(LIBS)
-
-thyperbolic: $(thyperbolic_OBJECTS) $(thyperbolic_DEPENDENCIES)
- @rm -f thyperbolic
- $(LINK) $(thyperbolic_LDFLAGS) $(thyperbolic_OBJECTS) $(thyperbolic_LDADD) $(LIBS)
-
-texp2: $(texp2_OBJECTS) $(texp2_DEPENDENCIES)
- @rm -f texp2
- $(LINK) $(texp2_LDFLAGS) $(texp2_OBJECTS) $(texp2_LDADD) $(LIBS)
-
-tfactorial: $(tfactorial_OBJECTS) $(tfactorial_DEPENDENCIES)
- @rm -f tfactorial
- $(LINK) $(tfactorial_LDFLAGS) $(tfactorial_OBJECTS) $(tfactorial_LDADD) $(LIBS)
-
-tsub: $(tsub_OBJECTS) $(tsub_DEPENDENCIES)
- @rm -f tsub
- $(LINK) $(tsub_LDFLAGS) $(tsub_OBJECTS) $(tsub_LDADD) $(LIBS)
-
-tasin: $(tasin_OBJECTS) $(tasin_DEPENDENCIES)
- @rm -f tasin
- $(LINK) $(tasin_LDFLAGS) $(tasin_OBJECTS) $(tasin_LDADD) $(LIBS)
-
-tconst_euler: $(tconst_euler_OBJECTS) $(tconst_euler_DEPENDENCIES)
- @rm -f tconst_euler
- $(LINK) $(tconst_euler_LDFLAGS) $(tconst_euler_OBJECTS) $(tconst_euler_LDADD) $(LIBS)
-
-tcos: $(tcos_OBJECTS) $(tcos_DEPENDENCIES)
- @rm -f tcos
- $(LINK) $(tcos_LDFLAGS) $(tcos_OBJECTS) $(tcos_LDADD) $(LIBS)
-
-tsin: $(tsin_OBJECTS) $(tsin_DEPENDENCIES)
- @rm -f tsin
- $(LINK) $(tsin_LDFLAGS) $(tsin_OBJECTS) $(tsin_LDADD) $(LIBS)
-
-ttan: $(ttan_OBJECTS) $(ttan_DEPENDENCIES)
- @rm -f ttan
- $(LINK) $(ttan_LDFLAGS) $(ttan_OBJECTS) $(ttan_LDADD) $(LIBS)
-
-tsub_ui: $(tsub_ui_OBJECTS) $(tsub_ui_DEPENDENCIES)
- @rm -f tsub_ui
- $(LINK) $(tsub_ui_LDFLAGS) $(tsub_ui_OBJECTS) $(tsub_ui_LDADD) $(LIBS)
-
-tset: $(tset_OBJECTS) $(tset_DEPENDENCIES)
- @rm -f tset
- $(LINK) $(tset_LDFLAGS) $(tset_OBJECTS) $(tset_LDADD) $(LIBS)
-
-tlog1p: $(tlog1p_OBJECTS) $(tlog1p_DEPENDENCIES)
- @rm -f tlog1p
- $(LINK) $(tlog1p_LDFLAGS) $(tlog1p_OBJECTS) $(tlog1p_LDADD) $(LIBS)
-
-texpm1: $(texpm1_OBJECTS) $(texpm1_DEPENDENCIES)
- @rm -f texpm1
- $(LINK) $(texpm1_LDFLAGS) $(texpm1_OBJECTS) $(texpm1_LDADD) $(LIBS)
-
-tlog2: $(tlog2_OBJECTS) $(tlog2_DEPENDENCIES)
- @rm -f tlog2
- $(LINK) $(tlog2_LDFLAGS) $(tlog2_OBJECTS) $(tlog2_LDADD) $(LIBS)
-
-tlog10: $(tlog10_OBJECTS) $(tlog10_DEPENDENCIES)
- @rm -f tlog10
- $(LINK) $(tlog10_LDFLAGS) $(tlog10_OBJECTS) $(tlog10_LDADD) $(LIBS)
-
-tui_pow: $(tui_pow_OBJECTS) $(tui_pow_DEPENDENCIES)
- @rm -f tui_pow
- $(LINK) $(tui_pow_LDFLAGS) $(tui_pow_OBJECTS) $(tui_pow_LDADD) $(LIBS)
-
-tpow3: $(tpow3_OBJECTS) $(tpow3_DEPENDENCIES)
- @rm -f tpow3
- $(LINK) $(tpow3_LDFLAGS) $(tpow3_OBJECTS) $(tpow3_LDADD) $(LIBS)
-
-tadd_ui: $(tadd_ui_OBJECTS) $(tadd_ui_DEPENDENCIES)
- @rm -f tadd_ui
- $(LINK) $(tadd_ui_LDFLAGS) $(tadd_ui_OBJECTS) $(tadd_ui_LDADD) $(LIBS)
-
-texceptions: $(texceptions_OBJECTS) $(texceptions_DEPENDENCIES)
- @rm -f texceptions
- $(LINK) $(texceptions_LDFLAGS) $(texceptions_OBJECTS) $(texceptions_LDADD) $(LIBS)
-
-tfma: $(tfma_OBJECTS) $(tfma_DEPENDENCIES)
- @rm -f tfma
- $(LINK) $(tfma_LDFLAGS) $(tfma_OBJECTS) $(tfma_LDADD) $(LIBS)
-
-thypot: $(thypot_OBJECTS) $(thypot_DEPENDENCIES)
- @rm -f thypot
- $(LINK) $(thypot_LDFLAGS) $(thypot_OBJECTS) $(thypot_LDADD) $(LIBS)
-
-tacos: $(tacos_OBJECTS) $(tacos_DEPENDENCIES)
- @rm -f tacos
- $(LINK) $(tacos_LDFLAGS) $(tacos_OBJECTS) $(tacos_LDADD) $(LIBS)
-
-tags: TAGS
-
-ID: $(HEADERS) $(SOURCES) $(LISP)
- list='$(SOURCES) $(HEADERS)'; \
- unique=`for i in $$list; do echo $$i; done | \
- awk ' { files[$$0] = 1; } \
- END { for (i in files) print i; }'`; \
- here=`pwd` && cd $(srcdir) \
- && mkid -f$$here/ID $$unique $(LISP)
-
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
- tags=; \
- here=`pwd`; \
- list='$(SOURCES) $(HEADERS)'; \
- unique=`for i in $$list; do echo $$i; done | \
- awk ' { files[$$0] = 1; } \
- END { for (i in files) print i; }'`; \
- test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
- || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
-
-mostlyclean-tags:
-
-clean-tags:
-
-distclean-tags:
- -rm -f TAGS ID
-
-maintainer-clean-tags:
-
-distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
-
-subdir = tests
-
-distdir: $(DISTFILES)
- here=`cd $(top_builddir) && pwd`; \
- top_distdir=`cd $(top_distdir) && pwd`; \
- distdir=`cd $(distdir) && pwd`; \
- cd $(top_srcdir) \
- && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu tests/Makefile
- @for file in $(DISTFILES); do \
- d=$(srcdir); \
- if test -d $$d/$$file; then \
- cp -pr $$d/$$file $(distdir)/$$file; \
- else \
- test -f $(distdir)/$$file \
- || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
- || cp -p $$d/$$file $(distdir)/$$file || :; \
- fi; \
- done
-
-DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-
--include $(DEP_FILES)
-
-mostlyclean-depend:
-
-clean-depend:
-
-distclean-depend:
- -rm -rf .deps
-
-maintainer-clean-depend:
-
-%.o: %.c
- @echo '$(COMPILE) -c $<'; \
- $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
- @-cp .deps/$(*F).pp .deps/$(*F).P; \
- tr ' ' '\012' < .deps/$(*F).pp \
- | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
- >> .deps/$(*F).P; \
- rm .deps/$(*F).pp
-
-%.lo: %.c
- @echo '$(LTCOMPILE) -c $<'; \
- $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
- @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
- < .deps/$(*F).pp > .deps/$(*F).P; \
- tr ' ' '\012' < .deps/$(*F).pp \
- | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
- >> .deps/$(*F).P; \
- rm -f .deps/$(*F).pp
-info-am:
-info: info-am
-dvi-am:
-dvi: dvi-am
-check-am: all-am
- $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
-check: check-am
-installcheck-am:
-installcheck: installcheck-am
-install-exec-am:
-install-exec: install-exec-am
-
-install-data-am:
-install-data: install-data-am
-
-install-am: all-am
- @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-install: install-am
-uninstall-am:
-uninstall: uninstall-am
-all-am: Makefile
-all-redirect: all-am
-install-strip:
- $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
-installdirs:
-
-
-mostlyclean-generic:
-
-clean-generic:
-
-distclean-generic:
- -rm -f Makefile $(CONFIG_CLEAN_FILES)
- -rm -f config.cache config.log stamp-h stamp-h[0-9]*
-
-maintainer-clean-generic:
-mostlyclean-am: mostlyclean-checkPROGRAMS mostlyclean-compile \
- mostlyclean-tags mostlyclean-depend mostlyclean-generic
-
-mostlyclean: mostlyclean-am
-
-clean-am: clean-checkPROGRAMS clean-compile clean-tags clean-depend \
- clean-generic mostlyclean-am
-
-clean: clean-am
-
-distclean-am: distclean-checkPROGRAMS distclean-compile distclean-tags \
- distclean-depend distclean-generic clean-am
-
-distclean: distclean-am
-
-maintainer-clean-am: maintainer-clean-checkPROGRAMS \
- maintainer-clean-compile maintainer-clean-tags \
- maintainer-clean-depend maintainer-clean-generic \
- distclean-am
- @echo "This command is intended for maintainers to use;"
- @echo "it deletes files that may require special tools to rebuild."
-
-maintainer-clean: maintainer-clean-am
-
-.PHONY: mostlyclean-checkPROGRAMS distclean-checkPROGRAMS \
-clean-checkPROGRAMS maintainer-clean-checkPROGRAMS mostlyclean-compile \
-distclean-compile clean-compile maintainer-clean-compile tags \
-mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \
-distdir mostlyclean-depend distclean-depend clean-depend \
-maintainer-clean-depend info-am info dvi-am dvi check check-am \
-installcheck-am installcheck install-exec-am install-exec \
-install-data-am install-data install-am install uninstall-am uninstall \
-all-redirect all-am all installdirs mostlyclean-generic \
-distclean-generic clean-generic maintainer-clean-generic clean \
-mostlyclean distclean maintainer-clean
-
-
-../libmpfr.a:
- cd $(top_srcdir); make libmpfr.a
-
-check: all
- for i in $(check_PROGRAMS); do echo Testing $$i ; ./$$i || echo "### $$i failed ###"; done
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
diff --git a/tests/tacosh.c b/tests/tacosh.c
index fec59cf5c..37e9ef5ee 100644
--- a/tests/tacosh.c
+++ b/tests/tacosh.c
@@ -32,17 +32,39 @@ MA 02111-1307, USA. */
#define RAND_FUNCTION(x) (mpfr_random (x), mpfr_ui_div (x, 1, x, GMP_RNDN))
#include "tgeneric.c"
+static
+void check_inf(void)
+{
+ mpfr_t x,y;
+ mpfr_init(x);
+ mpfr_init(y);
+ MPFR_SET_INF(x);
+ mpfr_set_ui(y, 1, GMP_RNDN);
+ mpfr_acosh(x, y, GMP_RNDN);
+ if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) )
+ {
+ printf("Inf flag not clears in acosh!\n");
+ exit(1);
+ }
+ MPFR_SET_NAN(x);
+ mpfr_acosh(x, y, GMP_RNDN);
+ if (MPFR_IS_NAN(x) || MPFR_IS_INF(x) )
+ {
+ printf("NAN flag not clears in acosh!\n");
+ exit(1);
+ }
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
int
main (int argc, char *argv[])
{
tests_start_mpfr ();
test_generic (2, 100, 25);
+ check_inf ();
tests_end_mpfr ();
return 0;
}
-
-
-
-
diff --git a/tests/tagm.c b/tests/tagm.c
index 904a9ad6a..f3ec4996a 100644
--- a/tests/tagm.c
+++ b/tests/tagm.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_agm.
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -63,6 +63,7 @@ static void
check_large (void)
{
mpfr_t a, b, agm;
+ int inex;
mpfr_init2 (a, 82);
mpfr_init2 (b, 82);
@@ -87,6 +88,24 @@ check_large (void)
mpfr_set_str (b, "703.93543315330225238487279020523738740563816490895994499256063816906728642622316", 10, GMP_RNDN);
mpfr_agm (agm, a, b, GMP_RNDN);
+ mpfr_set_prec (a, 18);
+ mpfr_set_prec (b, 70);
+ mpfr_set_prec (agm, 67);
+ mpfr_set_str_binary (a, "0.111001111100101000e8");
+ mpfr_set_str_binary (b, "0.1101110111100100010100110000010111011011011100110100111001010100100001e10");
+ inex = mpfr_agm (agm, a, b, GMP_RNDN);
+ mpfr_set_str_binary (b, "0.1111110010011101101100010101011011010010010000001010100011000110011e9");
+ if (mpfr_cmp (agm, b))
+ {
+ printf ("Error in mpfr_agm (1)\n");
+ exit (1);
+ }
+ if (inex >= 0)
+ {
+ printf ("Wrong flag for mpfr_agm (1)\n");
+ exit (1);
+ }
+
mpfr_clear (a);
mpfr_clear (b);
mpfr_clear (agm);
diff --git a/tests/tasin.c b/tests/tasin.c
index 2aef35121..bba0c5221 100644
--- a/tests/tasin.c
+++ b/tests/tasin.c
@@ -23,7 +23,9 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include "gmp.h"
+#include "gmp-impl.h"
#include "mpfr.h"
+#include "mpfr-impl.h"
#include "mpfr-test.h"
#define TEST_FUNCTION mpfr_asin
diff --git a/tests/terf.c b/tests/terf.c
index a159864ec..64c1cca72 100644
--- a/tests/terf.c
+++ b/tests/terf.c
@@ -36,6 +36,7 @@ int
main (int argc, char *argv[])
{
mpfr_t x, y;
+ int inex;
tests_start_mpfr ();
@@ -159,6 +160,44 @@ main (int argc, char *argv[])
exit (1);
}
+ mpfr_set_prec (x, 8);
+ mpfr_set_prec (y, 8);
+ mpfr_set_ui (x, 50, GMP_RNDN);
+ inex = mpfr_erf (y, x, GMP_RNDN);
+ if (mpfr_cmp_ui (y, 1))
+ {
+ printf ("mpfr_erf failed for x=50, rnd=GMP_RNDN\n");
+ printf ("expected 1, got ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
+ exit (1);
+ }
+ if (inex <= 0)
+ {
+ printf ("mpfr_erf failed for x=50, rnd=GMP_RNDN: wrong ternary value\n"
+ "expected positive, got %d\n", inex);
+ exit (1);
+ }
+ inex = mpfr_erf (x, x, GMP_RNDZ);
+ mpfr_nextbelow (y);
+ if (mpfr_cmp (x, y))
+ {
+ printf ("mpfr_erf failed for x=50, rnd=GMP_RNDZ\n");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
+ printf ("got ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
+ exit (1);
+ }
+ if (inex >= 0)
+ {
+ printf ("mpfr_erf failed for x=50, rnd=GMP_RNDN: wrong ternary value\n"
+ "expected negative, got %d\n", inex);
+ exit (1);
+ }
+
mpfr_clear (x);
mpfr_clear (y);
diff --git a/tests/tests.c b/tests/tests.c
index 4b26d1ef2..6aabacee5 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -93,7 +93,10 @@ tests_rand_start (void)
printf ("ie. ensure that function is called before the first use of RANDS.\n");
abort ();
}
- rands = RANDS;
+
+ gmp_randinit_default (__gmp_rands);
+ __gmp_rands_initialized = 1;
+ rands = __gmp_rands;
perform_seed = getenv ("GMP_CHECK_RANDOMIZE");
if (perform_seed != NULL)
diff --git a/tests/texp.c b/tests/texp.c
index fa1320b6c..cce394394 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_exp.
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -68,47 +68,6 @@ check3 (double d, mp_rnd_t rnd, double e)
return u;
}
-/* computes n bits of exp(d) */
-static int
-check_large (double d, int n, mp_rnd_t rnd)
-{
- mpfr_t x, y;
-
- mpfr_init2 (x, n);
- mpfr_init2 (y, n);
- if (d == 0.0)
- { /* try exp(Pi*sqrt(163)/3)-640320 */
- mpfr_set_d (x, 163.0, rnd);
- mpfr_sqrt (x, x, rnd);
- mpfr_const_pi (y, rnd);
- mpfr_mul (x, x, y, rnd);
- mpfr_div_ui (x, x, 3, rnd);
- }
- else
- mpfr_set_d (x, d, rnd);
- mpfr_exp (y, x, rnd);
- if (d == 0.0)
- {
- mpfr_set_d (x, 640320.0, rnd);
- mpfr_sub (y, y, x, rnd);
- printf ("exp(Pi*sqrt(163)/3)-640320=");
- }
- else
- printf ("exp(%1.20e)=", d);
- mpfr_out_str (stdout, 10, 0, y, rnd);
- puts ("");
- printf (" =");
- mpfr_print_binary (y);
- puts ("");
- if (n == 53)
- printf (" =%1.20e\n", mpfr_get_d1 (y));
-
- mpfr_clear (x);
- mpfr_clear (y);
-
- return 0;
-}
-
/* expx is the value of exp(X) rounded towards -infinity */
static int
check_worst_case (double X, double expx)
@@ -178,6 +137,17 @@ check_worst_cases (void)
exit (1);
}
+ mpfr_set_prec (x, 13001);
+ mpfr_set_prec (y, 13001);
+ mpfr_random (x);
+ mpfr_exp (y, x, GMP_RNDN);
+ mpfr_exp_2 (x, x, GMP_RNDN);
+ if (mpfr_cmp (x, y))
+ {
+ printf ("mpfr_exp_2 and mpfr_exp3 differ for prec=13001\n");
+ exit (1);
+ }
+
mpfr_clear (x);
mpfr_clear (y);
return 0;
@@ -191,7 +161,7 @@ compare_exp2_exp3 (int n)
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
- for (prec=20; prec<=n; prec++)
+ for (prec = 20; prec <= n; prec++)
{
mpfr_set_prec (x, prec);
mpfr_set_prec (y, prec);
@@ -227,15 +197,102 @@ static void
check_special ()
{
mpfr_t x, y, z;
+ mp_exp_t emin, emax;
+
+ mpfr_init (x);
+ mpfr_init (y);
+ mpfr_init (z);
+
+ /* check exp(NaN) = NaN */
+ mpfr_set_nan (x);
+ mpfr_exp (y, x, GMP_RNDN);
+ if (!mpfr_nan_p (y))
+ {
+ printf ("Error for exp(NaN)\n");
+ exit (1);
+ }
+
+ /* check exp(+inf) = +inf */
+ mpfr_set_inf (x, 1);
+ mpfr_exp (y, x, GMP_RNDN);
+ if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
+ {
+ printf ("Error for exp(+inf)\n");
+ exit (1);
+ }
+
+ /* check exp(-inf) = +0 */
+ mpfr_set_inf (x, -1);
+ mpfr_exp (y, x, GMP_RNDN);
+ if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
+ {
+ printf ("Error for exp(-inf)\n");
+ exit (1);
+ }
+
+ /* check overflow */
+ emax = mpfr_get_emax ();
+ mpfr_set_emax (10);
+ mpfr_set_ui (x, 7, GMP_RNDN);
+ mpfr_exp (y, x, GMP_RNDN);
+ if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
+ {
+ printf ("Error for exp(7) for emax=10\n");
+ exit (1);
+ }
+ mpfr_set_emax (emax);
+
+ /* check underflow */
+ emin = mpfr_get_emin ();
+ mpfr_set_emin (-10);
+ mpfr_set_si (x, -9, GMP_RNDN);
+ mpfr_exp (y, x, GMP_RNDN);
+ if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
+ {
+ printf ("Error for exp(-9) for emin=-10\n");
+ printf ("Expected +0\n");
+ printf ("Got "); mpfr_print_binary (y); puts ("");
+ exit (1);
+ }
+ mpfr_set_emin (emin);
+
+ /* check case EXP(x) < -precy */
+ mpfr_set_prec (y, 2);
+ mpfr_set_str_binary (x, "-0.1E-3");
+ mpfr_exp (y, x, GMP_RNDD);
+ if (mpfr_cmp_ui_2exp (y, 3, -2))
+ {
+ printf ("Error for exp(-1/16), prec=2, RNDD\n");
+ exit (1);
+ }
+ mpfr_exp (y, x, GMP_RNDZ);
+ if (mpfr_cmp_ui (y, 1))
+ {
+ printf ("Error for exp(-1/16), prec=2, RNDZ\n");
+ exit (1);
+ }
+ mpfr_set_str_binary (x, "0.1E-3");
+ mpfr_exp (y, x, GMP_RNDN);
+ if (mpfr_cmp_ui (y, 1))
+ {
+ printf ("Error for exp(1/16), prec=2, RNDN\n");
+ exit (1);
+ }
+ mpfr_exp (y, x, GMP_RNDU);
+ if (mpfr_cmp_ui_2exp (y, 3, -1))
+ {
+ printf ("Error for exp(1/16), prec=2, RNDU\n");
+ exit (1);
+ }
/* bug reported by Franky Backeljauw, 28 Mar 2003 */
- mpfr_init2 (x, 53);
- mpfr_init2 (y, 53);
+ mpfr_set_prec (x, 53);
+ mpfr_set_prec (y, 53);
mpfr_set_str_binary (x, "1.1101011000111101011110000111010010101001101001110111e28");
mpfr_exp (y, x, GMP_RNDN);
mpfr_set_prec (x, 153);
- mpfr_init2 (z, 153);
+ mpfr_set_prec (z, 153);
mpfr_set_str_binary (x, "1.1101011000111101011110000111010010101001101001110111e28");
mpfr_exp (z, x, GMP_RNDN);
mpfr_prec_round (z, 53, GMP_RNDN);
@@ -246,6 +303,12 @@ check_special ()
exit (1);
}
+ /* corner cases in mpfr_exp3 */
+ mpfr_set_prec (x, 2);
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ mpfr_set_prec (y, 2);
+ mpfr_exp3 (y, x, GMP_RNDN);
+
mpfr_clear (x);
mpfr_clear (y);
mpfr_clear (z);
@@ -281,15 +344,8 @@ main (int argc, char *argv[])
tests_start_mpfr ();
check_inexact ();
-
check_special ();
- if (argc == 4)
- {
- check_large (atof(argv[1]), atoi(argv[2]), atoi(argv[3]));
- exit (0);
- }
-
test_generic (2, 100, 100);
compare_exp2_exp3(500);
diff --git a/tests/tfactorial.c b/tests/tfactorial.c
index cacc4374f..3fcaff377 100644
--- a/tests/tfactorial.c
+++ b/tests/tfactorial.c
@@ -1,7 +1,6 @@
/* Test file for mpfr_factorial.
-Copyright 2001, 2002, 2003 Free Software Foundation.
-Adapted from tarctan.c.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -30,6 +29,43 @@ MA 02111-1307, USA. */
#define TEST_FUNCTION mpfr_fac_ui
+static void
+special (void)
+{
+ mpfr_t x, y;
+ int inex;
+
+ mpfr_init (x);
+ mpfr_init (y);
+
+ mpfr_set_prec (x, 21);
+ mpfr_set_prec (y, 21);
+ mpfr_fac_ui (x, 119, GMP_RNDZ);
+ mpfr_set_str_binary (y, "0.101111101110100110110E654");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_fac_ui (119)\n");
+ exit (1);
+ }
+
+ mpfr_set_prec (y, 206);
+ inex = mpfr_fac_ui (y, 767, GMP_RNDN);
+ mpfr_set_prec (x, 206);
+ mpfr_set_str_binary (x, "0.110111100001000001101010010001000111000100000100111000010011100011011111001100011110101000111101101100110001001100110100001001111110000101010000100100011100010011101110000001000010001100010000101001111E6250");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_fac_ui (767)\n");
+ exit (1);
+ }
+ if (inex <= 0)
+ {
+ printf ("Wrong flag for mpfr_fac_ui (767)\n");
+ exit (1);
+ }
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
int
main (int argc, char *argv[])
{
@@ -40,6 +76,8 @@ main (int argc, char *argv[])
tests_start_mpfr ();
+ special ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
diff --git a/tests/tfrac.c b/tests/tfrac.c
index b6b3a581b..4229e3180 100644
--- a/tests/tfrac.c
+++ b/tests/tfrac.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_frac.
-Copyright 2002, 2003 Free Software Foundation.
+Copyright 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -22,7 +22,9 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include "gmp.h"
+#include "gmp-impl.h"
#include "mpfr.h"
+#include "mpfr-impl.h"
#include "mpfr-test.h"
#define PIP 70
@@ -129,6 +131,38 @@ check1 (mpfr_ptr ip, mpfr_ptr fp)
}
}
+static void
+special (void)
+{
+ mpfr_t z, t;
+
+ mpfr_init2 (z, 6);
+ mpfr_init2 (t, 3);
+
+ mpfr_set_str_binary (z, "0.101101E3");
+ mpfr_frac (t, z, GMP_RNDN);
+ mpfr_set_str_binary (z, "0.101");
+ if (mpfr_cmp (t, z))
+ {
+ printf ("Error in frac(0.101101E3)\n");
+ exit (1);
+ }
+
+ mpfr_set_prec (z, 34);
+ mpfr_set_prec (t, 26);
+ mpfr_set_str_binary (z, "0.101101010000010011110011001101E9");
+ mpfr_frac (t, z, GMP_RNDN);
+ mpfr_set_str_binary (z, "0.000010011110011001101");
+ if (mpfr_cmp (t, z))
+ {
+ printf ("Error in frac(0.101101010000010011110011001101E9)\n");
+ exit (1);
+ }
+
+ mpfr_clear (z);
+ mpfr_clear (t);
+}
+
int
main (void)
{
@@ -137,6 +171,8 @@ main (void)
tests_start_mpfr ();
+ special ();
+
mpfr_init2 (ip, PIP);
mpfr_init2 (fp, PFP);
diff --git a/tests/tgamma.c b/tests/tgamma.c
index c3179e32b..9eba47462 100644
--- a/tests/tgamma.c
+++ b/tests/tgamma.c
@@ -1,6 +1,6 @@
/* mpfr_tgamma -- test file for gamma function
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library, and was contributed by Mathieu Dutour.
@@ -22,7 +22,9 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#include "gmp.h"
+#include "gmp-impl.h"
#include "mpfr.h"
+#include "mpfr-impl.h"
#include "mpfr-test.h"
int mpfr_gamma (mpfr_ptr, mpfr_srcptr, mp_rnd_t);
@@ -30,13 +32,12 @@ int mpfr_gamma (mpfr_ptr, mpfr_srcptr, mp_rnd_t);
#define TEST_FUNCTION mpfr_gamma
#include "tgeneric.c"
-int
-main (void)
+static void
+special (void)
{
mpfr_t x, y;
double xd, yd;
-
- tests_start_mpfr ();
+ int inex;
mpfr_init (x);
mpfr_init (y);
@@ -63,10 +64,61 @@ main (void)
exit (1);
}
- test_generic (2, 100, 2);
+ mpfr_set_prec (x, 8);
+ mpfr_set_prec (y, 175);
+ mpfr_set_ui (x, 33, GMP_RNDN);
+ mpfr_gamma (y, x, GMP_RNDU);
+ mpfr_set_prec (x, 175);
+ mpfr_set_str_binary (x, "0.110010101011010101101000010101010111000110011101001000101011000001100010111001101001011E118");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_gamma (1)\n");
+ exit (1);
+ }
+
+ mpfr_set_prec (x, 21);
+ mpfr_set_prec (y, 8);
+ mpfr_set_ui (y, 120, GMP_RNDN);
+ mpfr_gamma (x, y, GMP_RNDZ);
+ mpfr_set_prec (y, 21);
+ mpfr_set_str_binary (y, "0.101111101110100110110E654");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_gamma (120)\n");
+ printf ("Expected "); mpfr_print_binary (y); puts ("");
+ printf ("Got "); mpfr_print_binary (x); puts ("");
+ exit (1);
+ }
+
+ mpfr_set_prec (x, 3);
+ mpfr_set_prec (y, 206);
+ mpfr_set_str_binary (x, "0.110e10");
+ inex = mpfr_gamma (y, x, GMP_RNDN);
+ mpfr_set_prec (x, 206);
+ mpfr_set_str_binary (x, "0.110111100001000001101010010001000111000100000100111000010011100011011111001100011110101000111101101100110001001100110100001001111110000101010000100100011100010011101110000001000010001100010000101001111E6250");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_gamma (768)\n");
+ exit (1);
+ }
+ if (inex <= 0)
+ {
+ printf ("Wrong flag for mpfr_gamma (768)\n");
+ exit (1);
+ }
mpfr_clear (x);
mpfr_clear (y);
+}
+
+int
+main (void)
+{
+ tests_start_mpfr ();
+
+ special ();
+
+ test_generic (2, 100, 2);
tests_end_mpfr ();
return 0;
diff --git a/tests/tget_str.c b/tests/tget_str.c
index 7352cc133..973107816 100644
--- a/tests/tget_str.c
+++ b/tests/tget_str.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_get_str.
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -188,6 +188,26 @@ check_small (void)
}
(*__gmp_free_func) (s, strlen (s) + 1);
+ mpfr_set_prec (x, 145);
+ mpfr_set_str_binary (x, "-0.1000110011000001011000010101101010110110101100101110100011111100011110011001001001010000100001000011000011000000010111011001000111101001110100110e6");
+ s = mpfr_get_str (NULL, &e, 4, 53, x, GMP_RNDU);
+ if (strcmp (s, "-20303001120111222312230232203330132121021100201003003") || (e != 3))
+ {
+ printf ("Error in mpfr_get_str (5): s=%s e=%d\n", s, (int) e);
+ exit (1);
+ }
+ (*__gmp_free_func) (s, strlen (s) + 1);
+
+ mpfr_set_prec (x, 45);
+ mpfr_set_str_binary (x, "-0.00100111010110010001011001110111010001010010010");
+ s = mpfr_get_str (NULL, &e, 32, 9, x, GMP_RNDN);
+ if (strcmp (s, "-4tchctq54") || (e != 0))
+ {
+ printf ("Error in mpfr_get_str (6): s=%s e=%d\n", s, (int) e);
+ exit (1);
+ }
+ (*__gmp_free_func) (s, strlen (s) + 1);
+
mpfr_clear (x);
}
@@ -444,6 +464,35 @@ check_special (int b, mp_prec_t p)
mpfr_clear (x);
}
+static void
+check_bug_base2k(void)
+{
+ /*
+ * -2.63b22b55697e800000000000@130
+ * +-0.1001100011101100100010101101010101011010010111111010000000000000000000000000+00000000000000000000001E522
+ */
+ mpfr_t xx,yy,zz;
+ char *s;
+ mp_exp_t e;
+
+ mpfr_init2(xx,107);
+ mpfr_init2(yy,79);
+ mpfr_init2(zz,99);
+
+ mpfr_set_str(xx, "-1.90e8c3e525d7c0000000000000@-18", 16, GMP_RNDN);
+ mpfr_set_str(yy, "-2.63b22b55697e8000000@130", 16, GMP_RNDN);
+ mpfr_add(zz, xx, yy, GMP_RNDD);
+ s = mpfr_get_str(NULL, &e, 16, 0, zz, GMP_RNDN);
+ if (strcmp(s, "-263b22b55697e8000000000008"))
+ {
+ printf(
+"Error for get_str base 16\nGot %s expected -263b22b55697e8000000000008\n", s);
+ exit(1);
+ }
+ (*__gmp_free_func) (s, strlen (s) + 1);
+ mpfr_clears(xx,yy,zz,NULL);
+}
+
#define ITER 1000
int
@@ -502,6 +551,7 @@ main (int argc, char *argv[])
check3 (6.7274500420134077e-87, GMP_RNDU, "67275");
check3 (6.7274500420134077e-87, GMP_RNDD, "67274");
+ check_bug_base2k();
tests_end_mpfr ();
return 0;
}
diff --git a/tests/tgmpop.c b/tests/tgmpop.c
new file mode 100644
index 000000000..efcd95611
--- /dev/null
+++ b/tests/tgmpop.c
@@ -0,0 +1,361 @@
+/* Test file for mpfr_add_[q,z], mpfr_sub_[q,z], mpfr_div_[q,z], mpfr_mul_[q,z]
+
+Copyright 2004 Free Software Foundation.
+
+This file is part of the MPFR Library.
+
+The 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 2.1 of the License, or (at your
+option) any later version.
+
+The 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 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 <stdio.h>
+#include <stdlib.h>
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "mpfr.h"
+#include "mpfr-impl.h"
+#include "mpfr-test.h"
+
+static void
+special (void)
+{
+ mpfr_t x, y;
+ mpq_t z;
+ int res;
+
+ mpfr_init (x);
+ mpfr_init (y);
+ mpq_init (z);
+
+ /* cancellation in mpfr_add_q */
+ mpfr_set_prec (x, 60);
+ mpfr_set_prec (y, 20);
+ mpz_set_str (mpq_numref (z), "-187207494", 10);
+ mpz_set_str (mpq_denref (z), "5721", 10);
+ mpfr_set_str_binary (x, "11111111101001011011100101100011011110010011100010000100001E-44");
+ mpfr_add_q (y, x, z, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui_2exp (y, 256783, -64) == 0);
+
+ mpfr_set_prec (x, 19);
+ mpfr_set_str_binary (x, "0.1011110101110011100E0");
+ mpz_set_str (mpq_numref (z), "187207494", 10);
+ mpz_set_str (mpq_denref (z), "5721", 10);
+ mpfr_set_prec (y, 29);
+ mpfr_add_q (y, x, z, GMP_RNDD);
+ mpfr_set_prec (x, 29);
+ mpfr_set_str_binary (x, "11111111101001110011010001001E-14");
+ MPFR_ASSERTN(mpfr_cmp (x, y) == 0);
+
+ mpfr_set_inf (x, 1);
+ mpz_set_str (mpq_numref (z), "395877315", 10);
+ mpz_set_str (mpq_denref (z), "3508975966", 10);
+ mpfr_set_prec (y, 118);
+ mpfr_add_q (y, x, z, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+
+
+ /* Exact value */
+ mpfr_set_prec (x, 60);
+ mpfr_set_prec (y, 60);
+ mpfr_set_str1 (x, "0.5");
+ mpz_set_str (mpq_numref (z), "3", 10);
+ mpz_set_str (mpq_denref (z), "2", 10);
+ res = mpfr_add_q (y, x, z, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_cmp_ui(y, 2)==0 && res==0);
+ res = mpfr_sub_q (y, x, z, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_cmp_si(y, -1)==0 && res==0);
+
+ mpq_clear (z);
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
+static void
+test_specialz (int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpz_srcptr, mp_rnd_t),
+ void (*mpz_func)(mpz_ptr, mpz_srcptr, mpz_srcptr),
+ const char *op)
+{
+ mpfr_t x1, x2;
+ mpz_t z1, z2;
+ int res;
+
+ mpfr_inits2 (128, x1, x2, NULL);
+ mpz_init (z1); mpz_init(z2);
+ mpz_fac_ui (z1, 19); /* 19!+1 fits perfectly in a 128 bits mantissa */
+ mpz_add_ui (z1, z1, 1);
+ mpz_fac_ui (z2, 20); /* 20!+1 fits perfectly in a 128 bits mantissa */
+ mpz_add_ui (z2, z2, 1);
+ res = mpfr_set_z(x1, z1, GMP_RNDN);
+ if (res)
+ {
+ printf("Specialz %s: set_z1 error\n", op);
+ abort();
+ }
+ /* (19!+1) * (20!+1) fits in a 128 bits number */
+ res = mpfr_func(x1, x1, z2, GMP_RNDN);
+ if (res)
+ {
+ printf("Specialz %s: wrong inexact flag.\n", op);
+ abort();
+ }
+ mpz_func(z1, z1, z2);
+ res = mpfr_set_z (x2, z1, GMP_RNDN);
+ if (res)
+ {
+ printf("Specialz %s: set_z2 error\n", op);
+ abort();
+ }
+ if (mpfr_cmp(x1, x2))
+ {
+ printf("Specialz %s: results differ.\nx1=", op);
+ mpfr_print_binary(x1);
+ printf("\nx2=");
+ mpfr_print_binary(x2);
+ putchar('\n');
+ abort();
+ }
+
+ mpz_clear (z1); mpz_clear(z2);
+ mpfr_clears(x1, x2, NULL);
+}
+
+static void
+test_genericz (mp_prec_t p0, mp_prec_t p1, unsigned int N,
+ int (*func)(mpfr_ptr, mpfr_srcptr, mpz_srcptr, mp_rnd_t),
+ const char *op)
+{
+ mp_prec_t prec;
+ mpfr_t arg1, dst_big, dst_small, tmp;
+ mpz_t arg2;
+ mp_rnd_t rnd;
+ int inexact, compare, compare2;
+ unsigned int n;
+
+ mpfr_inits (arg1, dst_big, dst_small, tmp, NULL);
+ mpz_init (arg2);
+
+ for (prec = p0; prec <= p1; prec++)
+ {
+ mpfr_set_prec (arg1, prec);
+ mpfr_set_prec (tmp, prec);
+ mpfr_set_prec (dst_small, prec);
+
+ for (n=0; n<N; n++)
+ {
+ mpfr_urandomb (arg1, RANDS);
+ mpz_urandomb (arg2, RANDS, 1024);
+ rnd = randlimb () % 4;
+ mpfr_set_prec (dst_big, 2*prec);
+ compare = func(dst_big, arg1, arg2, rnd);
+ if (mpfr_can_round (dst_big, 2*prec, rnd, rnd, prec))
+ {
+ mpfr_set (tmp, dst_big, rnd);
+ inexact = func(dst_small, arg1, arg2, rnd);
+ if (mpfr_cmp (tmp, dst_small))
+ {
+ printf ("Results differ for prec=%u rnd_mode=%s and %s \n"
+ "arg1=",
+ (unsigned) prec, mpfr_print_rnd_mode (rnd), op);
+ mpfr_print_binary (arg1);
+ printf("\narg2=");
+ mpz_out_str(stdout, 2, arg2);
+ printf ("\ngot ");
+ mpfr_print_binary (dst_small);
+ printf ("\nexpected ");
+ mpfr_print_binary (tmp);
+ printf ("\napprox ");
+ mpfr_print_binary (dst_big);
+ exit (1);
+ }
+ compare2 = mpfr_cmp (tmp, dst_big);
+ /* if rounding to nearest, cannot know the sign of t - f(x)
+ because of composed rounding: y = o(f(x)) and t = o(y) */
+ if (compare * compare2 >= 0)
+ compare = compare + compare2;
+ else
+ compare = inexact; /* cannot determine sign(t-f(x)) */
+ if (((inexact == 0) && (compare != 0)) ||
+ ((inexact > 0) && (compare <= 0)) ||
+ ((inexact < 0) && (compare >= 0)))
+ {
+ printf ("Wrong inexact flag for rnd=%s and %s:\n"
+ "expected %d, got %d\n",
+ mpfr_print_rnd_mode (rnd), op, compare, inexact);
+ printf ("\narg1="); mpfr_print_binary (arg1);
+ printf ("\narg2="); mpz_out_str(stdout, 2, arg2);
+ printf ("\ndstl="); mpfr_print_binary (dst_big);
+ printf ("\ndsts="); mpfr_print_binary (dst_small);
+ printf ("\ntmp ="); mpfr_print_binary (tmp);
+ exit (1);
+ }
+ }
+ }
+ }
+
+ mpz_clear (arg2);
+ mpfr_clears (arg1, dst_big, dst_small, tmp, NULL);
+}
+
+static void
+test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N,
+ int (*func)(mpfr_ptr, mpfr_srcptr, mpq_srcptr, mp_rnd_t),
+ const char *op)
+{
+ mp_prec_t prec;
+ mpfr_t arg1, dst_big, dst_small, tmp;
+ mpq_t arg2;
+ mp_rnd_t rnd;
+ int inexact, compare, compare2;
+ unsigned int n;
+
+ mpfr_inits (arg1, dst_big, dst_small, tmp, NULL);
+ mpq_init (arg2);
+
+ for (prec = p0; prec <= p1; prec++)
+ {
+ mpfr_set_prec (arg1, prec);
+ mpfr_set_prec (tmp, prec);
+ mpfr_set_prec (dst_small, prec);
+
+ for (n=0; n<N; n++)
+ {
+ mpfr_urandomb (arg1, RANDS);
+ mpq_set_ui (arg2, randlimb (), randlimb() );
+ rnd = randlimb () % 4;
+ mpfr_set_prec (dst_big, prec+10);
+ compare = func(dst_big, arg1, arg2, rnd);
+ if (mpfr_can_round (dst_big, prec+10, rnd, rnd, prec))
+ {
+ mpfr_set (tmp, dst_big, rnd);
+ inexact = func(dst_small, arg1, arg2, rnd);
+ if (mpfr_cmp (tmp, dst_small))
+ {
+ printf ("Results differ for prec=%u rnd_mode=%s and %s\n"
+ "arg1=",
+ (unsigned) prec, mpfr_print_rnd_mode (rnd), op);
+ mpfr_print_binary (arg1);
+ printf("\narg2=");
+ mpq_out_str(stdout, 2, arg2);
+ printf ("\ngot ");
+ mpfr_print_binary (dst_small);
+ printf ("\nexpected ");
+ mpfr_print_binary (tmp);
+ printf ("\napprox ");
+ mpfr_print_binary (dst_big);
+ putchar('\n');
+ exit (1);
+ }
+ compare2 = mpfr_cmp (tmp, dst_big);
+ /* if rounding to nearest, cannot know the sign of t - f(x)
+ because of composed rounding: y = o(f(x)) and t = o(y) */
+ if (compare * compare2 >= 0)
+ compare = compare + compare2;
+ else
+ compare = inexact; /* cannot determine sign(t-f(x)) */
+ if (((inexact == 0) && (compare != 0)) ||
+ ((inexact > 0) && (compare <= 0)) ||
+ ((inexact < 0) && (compare >= 0)))
+ {
+ printf ("Wrong inexact flag for rnd=%s and %s:\n"
+ "expected %d, got %d",
+ mpfr_print_rnd_mode (rnd), op, compare, inexact);
+ printf ("\narg1="); mpfr_print_binary (arg1);
+ printf ("\narg2="); mpq_out_str(stdout, 2, arg2);
+ printf ("\ndstl="); mpfr_print_binary (dst_big);
+ printf ("\ndsts="); mpfr_print_binary (dst_small);
+ printf ("\ntmp ="); mpfr_print_binary (tmp);
+ putchar('\n');
+ exit (1);
+ }
+ }
+ }
+ }
+
+ mpq_clear (arg2);
+ mpfr_clears (arg1, dst_big, dst_small, tmp, NULL);
+}
+
+static void
+test_specialq (mp_prec_t p0, mp_prec_t p1, unsigned int N,
+ int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpq_srcptr, mp_rnd_t),
+ void (*mpq_func)(mpq_ptr, mpq_srcptr, mpq_srcptr),
+ const char *op)
+{
+ mpfr_t fra, frb, frq;
+ mpq_t q1, q2, qr;
+ unsigned int n;
+ mp_prec_t prec;
+
+ for (prec = p0 ; prec < p1 ; prec++)
+ {
+ mpfr_inits2 (prec, fra, frb, frq, NULL);
+ mpq_init (q1); mpq_init(q2); mpq_init (qr);
+
+ for( n = 0 ; n < N ; n++)
+ {
+ mpq_set_ui(q1, randlimb(), randlimb() );
+ mpq_set_ui(q2, randlimb(), randlimb() );
+ mpq_func (qr, q1, q2);
+ mpfr_set_q (fra, q1, GMP_RNDD);
+ mpfr_func (fra, fra, q2, GMP_RNDD);
+ mpfr_set_q (frb, q1, GMP_RNDU);
+ mpfr_func (frb, frb, q2, GMP_RNDU);
+ mpfr_set_q (frq, qr, GMP_RNDN);
+ /* We should have fra <= qr <= frb */
+ if ( (mpfr_cmp(fra, frq) > 0) || (mpfr_cmp (frq, frb) > 0))
+ {
+ printf("Range error for prec=%lu and %s", prec, op);
+ printf ("\nq1="); mpq_out_str(stdout, 2, q1);
+ printf ("\nq2="); mpq_out_str(stdout, 2, q2);
+ printf ("\nfr_dn="); mpfr_print_binary (fra);
+ printf ("\nfr_q ="); mpfr_print_binary (frq);
+ printf ("\nfr_up="); mpfr_print_binary (frb);
+ putchar('\n');
+ exit (1);
+ }
+ }
+
+ mpq_clear (q1); mpq_clear (q2); mpq_clear (qr);
+ mpfr_clears (fra, frb, frq, NULL);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ tests_start_mpfr ();
+
+ special ();
+
+ test_genericz (2, 150, 100, mpfr_add_z, "add");
+ test_genericz (2, 150, 100, mpfr_sub_z, "sub");
+ test_genericz (2, 150, 100, mpfr_mul_z, "mul");
+ test_genericz (2, 150, 100, mpfr_div_z, "div");
+ test_specialz (mpfr_add_z, mpz_add, "add");
+ test_specialz (mpfr_sub_z, mpz_sub, "sub");
+ test_specialz (mpfr_mul_z, mpz_mul, "mul");
+
+ test_genericq (2, 150, 100, mpfr_add_q, "add");
+ test_genericq (2, 150, 100, mpfr_sub_q, "sub");
+ test_genericq (2, 150, 100, mpfr_mul_q, "mul");
+ test_genericq (2, 150, 100, mpfr_div_q, "div");
+ test_specialq (2, 150, 100, mpfr_mul_q, mpq_mul, "mul");
+ test_specialq (2, 150, 100, mpfr_div_q, mpq_div, "div");
+ test_specialq (2, 150, 100, mpfr_add_q, mpq_add, "add");
+ test_specialq (2, 150, 100, mpfr_sub_q, mpq_sub, "sub");
+
+ tests_end_mpfr ();
+ return 0;
+}
+
diff --git a/tests/thyperbolic.c b/tests/thyperbolic.c
index 6c1923f99..29ea98d28 100644
--- a/tests/thyperbolic.c
+++ b/tests/thyperbolic.c
@@ -1,23 +1,23 @@
/* Test file for hyperbolic function : mpfr_cosh, mpfr_sinh, mpfr_tanh, mpfr_acosh, mpfr_asinh, mpfr_atanh.
-
+
Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
-
+
This file is part of the MPFR Library.
-
+
The 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 2.1 of the License, or (at youroption) any later version.
-
+
The MPFR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITYor 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 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 <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
@@ -30,6 +30,7 @@ check_NAN (void)
{
mpfr_t t, ch,sh,th,ach,ash,ath;
int tester;
+ int fail = 0;
mpfr_init2(t,200);
mpfr_init2(ch,200);
@@ -47,14 +48,8 @@ check_NAN (void)
if (!MPFR_IS_NAN(ch) || tester!=0)
{
printf("cosh NAN \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******sinh********/
@@ -63,14 +58,8 @@ check_NAN (void)
if (!MPFR_IS_NAN(sh) || tester!=0)
{
printf("sinh NAN \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******tanh********/
@@ -79,14 +68,8 @@ check_NAN (void)
if (!MPFR_IS_NAN(th) || tester!=0)
{
printf("tanh NAN \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******acosh********/
@@ -95,7 +78,8 @@ check_NAN (void)
if (!MPFR_IS_NAN(ach) || tester!=0)
{
printf("acosh NAN \n");
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******asinh********/
@@ -104,14 +88,8 @@ check_NAN (void)
if (!MPFR_IS_NAN(ash) || tester!=0)
{
printf("asinh NAN \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******atanh********/
@@ -120,16 +98,11 @@ check_NAN (void)
if (!MPFR_IS_NAN(ath) || tester!=0)
{
printf("atanh NAN \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
+ clean_up:
mpfr_clear(t);
mpfr_clear(ch);
mpfr_clear(sh);
@@ -138,7 +111,7 @@ check_NAN (void)
mpfr_clear(ash);
mpfr_clear(ath);
- return(0);
+ return fail;
}
static int
@@ -146,6 +119,7 @@ check_zero (void)
{
mpfr_t t, ch,sh,th,ach,ash,ath;
int tester;
+ int fail = 0;
mpfr_init2(t,200);
mpfr_init2(ch,200);
@@ -163,14 +137,8 @@ check_zero (void)
if (mpfr_cmp_ui(ch, 1) || tester)
{
printf("cosh(0) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******sinh********/
@@ -179,14 +147,8 @@ check_zero (void)
if (!MPFR_IS_ZERO(sh) || tester)
{
printf("sinh(0) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******tanh********/
@@ -195,14 +157,8 @@ check_zero (void)
if (!MPFR_IS_ZERO(th) || tester)
{
printf("tanh(0) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******acosh********/
@@ -211,14 +167,8 @@ check_zero (void)
if (!MPFR_IS_NAN(ach) || tester)
{
printf("acosh(0) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******asinh********/
@@ -227,14 +177,8 @@ check_zero (void)
if (!MPFR_IS_ZERO(ash) || tester)
{
printf("asinh(0) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******atanh********/
@@ -243,16 +187,11 @@ check_zero (void)
if (!MPFR_IS_ZERO(ath) || tester)
{
printf("atanh(0) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
+ clean_up:
mpfr_clear(t);
mpfr_clear(ch);
mpfr_clear(sh);
@@ -261,7 +200,7 @@ check_zero (void)
mpfr_clear(ash);
mpfr_clear(ath);
- return(0);
+ return fail;
}
static int
@@ -269,6 +208,7 @@ check_INF (void)
{
mpfr_t t, ch,sh,th,ach,ash,ath;
int tester;
+ int fail = 0;
mpfr_init2(t,200);
mpfr_init2(ch,200);
@@ -290,14 +230,8 @@ check_INF (void)
if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0)
{
printf("cosh(INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******sinh********/
@@ -306,14 +240,8 @@ check_INF (void)
if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) < 0 || tester!=0)
{
printf("sinh(INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******tanh********/
@@ -322,14 +250,8 @@ check_INF (void)
if (mpfr_cmp_ui(th,1) != 0 || tester!=0)
{
printf("tanh(INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******acosh********/
@@ -338,14 +260,8 @@ check_INF (void)
if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0)
{
printf("acosh(INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******asinh********/
@@ -354,30 +270,18 @@ check_INF (void)
if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) < 0 || tester!=0)
{
printf("asinh(INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******atanh********/
- tester=mpfr_atanh(ath,t,GMP_RNDD);
+ tester=mpfr_atanh(ath,t,GMP_RNDD);
if (!MPFR_IS_INF(ath) || tester != 0)
{
printf("atanh(INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
MPFR_CHANGE_SIGN(t);
@@ -388,14 +292,8 @@ check_INF (void)
if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0)
{
printf("cosh(-INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******sinh********/
@@ -404,14 +302,8 @@ check_INF (void)
if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) > 0 || tester!=0)
{
printf("sinh(-INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******tanh********/
@@ -420,30 +312,18 @@ check_INF (void)
if (!mpfr_cmp_ui(th,-1) || tester!=0)
{
printf("tanh(-INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******acosh********/
tester=mpfr_acosh(ach,t,GMP_RNDD);
- if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0)
+ if (!MPFR_IS_NAN(ach) || tester!=0)
{
printf("acosh(-INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******asinh********/
@@ -452,14 +332,8 @@ check_INF (void)
if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) > 0 || tester!=0)
{
printf("asinh(-INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
/******atanh********/
@@ -468,16 +342,11 @@ check_INF (void)
if (!MPFR_IS_INF(ath) || MPFR_SIGN(ath) > 0 || tester != 0)
{
printf("atanh(-INF) \n");
- mpfr_clear(t);
- mpfr_clear(ch);
- mpfr_clear(sh);
- mpfr_clear(th);
- mpfr_clear(ach);
- mpfr_clear(ash);
- mpfr_clear(ath);
- return(1);
+ fail = 1;
+ goto clean_up;
}
+ clean_up:
mpfr_clear(t);
mpfr_clear(ch);
mpfr_clear(sh);
@@ -486,7 +355,7 @@ check_INF (void)
mpfr_clear(ash);
mpfr_clear(ath);
- return(0);
+ return fail;
}
int
@@ -494,15 +363,24 @@ main(void)
{
tests_start_mpfr ();
- if (check_zero())
- printf("Error in evaluation at 0\n");
+ if (check_zero ())
+ {
+ printf ("Error in evaluation at 0\n");
+ exit (1);
+ }
- if (check_INF())
- printf("Error in evaluation of INF\n");
+ if (check_INF ())
+ {
+ printf ("Error in evaluation of INF\n");
+ exit (1);
+ }
- if (check_NAN())
- printf("Error in evaluation of NAN\n");
+ if (check_NAN ())
+ {
+ printf ("Error in evaluation of NAN\n");
+ exit (1);
+ }
tests_end_mpfr ();
- return(0);
+ return 0;
}
diff --git a/tests/thypot.c b/tests/thypot.c
index 15abd95e0..6ccaffbce 100644
--- a/tests/thypot.c
+++ b/tests/thypot.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_hypot.
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
Adapted from tarctan.c.
This file is part of the MPFR Library.
@@ -67,6 +67,19 @@ test_large (void)
mpfr_set_str_binary (t, "0.11111001010011000001110110001101011100001000010010100E-1021");
mpfr_hypot (y, x, t, GMP_RNDN);
+ mpfr_set_prec (x, 240);
+ mpfr_set_prec (y, 22);
+ mpfr_set_prec (t, 2);
+ mpfr_set_str_binary (x, "0.100111011010010010110100000100000001100010011100110101101111111101011110111011011101010110100101111000111100010100110000100101011110111011100110100110100101110101101100011000001100000001111101110100100100011011011010110111100110010101000111e-7");
+ mpfr_set_str_binary (y, "0.1111000010000011000111e-10");
+ mpfr_hypot (t, x, y, GMP_RNDN);
+ mpfr_set_str_binary (y, "0.11E-7");
+ if (mpfr_cmp (t, y))
+ {
+ printf ("Error in mpfr_hypot (1)\n");
+ exit (1);
+ }
+
mpfr_clear (x);
mpfr_clear (y);
mpfr_clear (z);
diff --git a/tests/tpow.c b/tests/tpow.c
index fa183e77e..c21e4376c 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -142,6 +142,22 @@ special ()
mpfr_init2 (z, 53);
mpfr_init2 (t, 2);
+ mpfr_set_ui (x, 2, GMP_RNDN);
+ mpfr_pow_si (x, x, -2, GMP_RNDN);
+ if (mpfr_cmp_ui_2exp (x, 1, -2))
+ {
+ printf ("Error in pow_si(x,x,-2) for x=2\n");
+ exit (1);
+ }
+ mpfr_set_ui (x, 2, GMP_RNDN);
+ mpfr_set_si (y, -2, GMP_RNDN);
+ mpfr_pow (x, x, y, GMP_RNDN);
+ if (mpfr_cmp_ui_2exp (x, 1, -2))
+ {
+ printf ("Error in pow(x,x,y) for x=2, y=-2\n");
+ exit (1);
+ }
+
mpfr_set_prec (x, 64);
mpfr_set_prec (y, 64);
mpfr_set_prec (z, 64);
diff --git a/tests/trint.c b/tests/trint.c
index e8a47cefa..b02b42221 100644
--- a/tests/trint.c
+++ b/tests/trint.c
@@ -1,4 +1,4 @@
-/* Test file for mpfr_trunc, mpfr_floor, mpfr_ceil, mpfr_round.
+/* Test file for mpfr_rint, mpfr_trunc, mpfr_floor, mpfr_ceil, mpfr_round.
Copyright 2002, 2003 Free Software Foundation.
@@ -21,17 +21,84 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "gmp.h"
+#include "gmp-impl.h"
#include "mpfr.h"
+#include "mpfr-impl.h"
#include "mpfr-test.h"
+#if __STDC_VERSION__ >= 199901L
+
+static void
+test_fct (double (*f)(double), int (*g)(), char *s, mp_rnd_t r)
+{
+ double d, y;
+ mpfr_t dd, yy;
+
+ mpfr_init2 (dd, 53);
+ mpfr_init2 (yy, 53);
+ for (d = -5.0; d <= 5.0; d += 0.25)
+ {
+ mpfr_set_d (dd, d, r);
+ y = (*f)(d);
+ if (g == &mpfr_rint)
+ mpfr_rint (yy, dd, r);
+ else
+ (*g)(yy, dd);
+ mpfr_set_d (dd, y, r);
+ if (mpfr_cmp (yy, dd))
+ {
+ printf ("test_against_libc: incorrect result for %s, rnd = %s,"
+ " d = %g\ngot ", s, mpfr_print_rnd_mode (r), d);
+ mpfr_out_str (stdout, 10, 0, yy, GMP_RNDN);
+ printf (" instead of %g\n", y);
+ exit (1);
+ }
+ }
+ mpfr_clear (dd);
+ mpfr_clear (yy);
+}
+
+#define TEST_FCT(F) test_fct (&F, &mpfr_##F, #F, r)
+
+static void
+test_against_libc (void)
+{
+ int r = 0;
+
+ TEST_FCT (round);
+ TEST_FCT (trunc);
+ TEST_FCT (floor);
+ TEST_FCT (ceil);
+ for (r = 0; r < 4; r++)
+ if (mpfr_set_machine_rnd_mode (r) == 0)
+ test_fct (&nearbyint, &mpfr_rint, "rint", r);
+}
+
+#endif
+
+static void
+err (char *str, mp_size_t s, mpfr_t x, mpfr_t y, mp_prec_t p, mp_rnd_t r,
+ int trint, int inexact)
+{
+ printf ("Error: %s\ns = %u, p = %u, r = %s, trint = %d, inexact = %d\nx = ",
+ str, (unsigned int) s, (unsigned int) p, mpfr_print_rnd_mode (r),
+ trint, inexact);
+ mpfr_print_binary (x);
+ printf ("\ny = ");
+ mpfr_print_binary (y);
+ printf ("\n");
+ exit (1);
+}
+
int
-main (void)
+main (int argc, char *argv[])
{
mp_size_t s;
mpz_t z;
mp_prec_t p;
- mpfr_t x, y, t;
+ mpfr_t x, y, t, u, v;
mp_rnd_t r;
int inexact, sign_t;
@@ -41,6 +108,8 @@ main (void)
mpfr_init (y);
mpz_init (z);
mpfr_init (t);
+ mpfr_init (u);
+ mpfr_init (v);
mpz_set_ui (z, 1);
for (s = 2; s < 100; s++)
{
@@ -51,45 +120,125 @@ main (void)
mpz_add_ui (z, z, 1);
mpfr_set_prec (x, s);
mpfr_set_prec (t, s);
+ mpfr_set_prec (u, s);
if (mpfr_set_z (x, z, GMP_RNDN))
{
printf ("Error: mpfr_set_z should be exact (s = %u)\n",
(unsigned int) s);
exit (1);
}
- for (p=2; p<100; p++)
+ if (randlimb () % 2)
+ mpfr_neg (x, x, GMP_RNDN);
+ if (randlimb () % 2)
+ mpfr_div_2ui (x, x, randlimb () % s, GMP_RNDN);
+ for (p = 2; p < 100; p++)
{
+ int trint;
mpfr_set_prec (y, p);
- for (r=0; r<4; r++)
- {
- if (r == GMP_RNDN)
- inexact = mpfr_round (y, x);
- else if (r == GMP_RNDZ)
- inexact = mpfr_trunc (y, x);
- else if (r == GMP_RNDU)
- inexact = mpfr_ceil (y, x);
- else /* r = GMP_RNDD */
- inexact = mpfr_floor (y, x);
- if (mpfr_sub (t, y, x, GMP_RNDN))
- {
- printf ("Error: subtraction should be exact\n");
- exit (1);
- }
- sign_t = mpfr_cmp_ui (t, 0);
- if (((inexact == 0) && (sign_t != 0)) ||
- ((inexact < 0) && (sign_t >= 0)) ||
- ((inexact > 0) && (sign_t <= 0)))
- {
- printf ("Wrong inexact flag\n");
- exit (1);
- }
- }
+ mpfr_set_prec (v, p);
+ for (r = 0; r < 4; r++)
+ for (trint = 0; trint < 2; trint++)
+ {
+ if (trint)
+ inexact = mpfr_rint (y, x, r);
+ else if (r == GMP_RNDN)
+ inexact = mpfr_round (y, x);
+ else if (r == GMP_RNDZ)
+ inexact = mpfr_trunc (y, x);
+ else if (r == GMP_RNDU)
+ inexact = mpfr_ceil (y, x);
+ else /* r = GMP_RNDD */
+ inexact = mpfr_floor (y, x);
+ if (mpfr_sub (t, y, x, GMP_RNDN))
+ err ("subtraction 1 should be exact",
+ s, x, y, p, r, trint, inexact);
+ sign_t = mpfr_cmp_ui (t, 0);
+ if (((inexact == 0) && (sign_t != 0)) ||
+ ((inexact < 0) && (sign_t >= 0)) ||
+ ((inexact > 0) && (sign_t <= 0)))
+ err ("wrong inexact flag", s, x, y, p, r, trint, inexact);
+ if (inexact == 0)
+ continue; /* end of the test for exact results */
+
+ if (((r == GMP_RNDD || (r == GMP_RNDZ && MPFR_SIGN (x) > 0))
+ && inexact > 0) ||
+ ((r == GMP_RNDU || (r == GMP_RNDZ && MPFR_SIGN (x) < 0))
+ && inexact < 0))
+ err ("wrong rounding direction",
+ s, x, y, p, r, trint, inexact);
+ if (inexact < 0)
+ {
+ mpfr_add_ui (v, y, 1, GMP_RNDU);
+ if (mpfr_cmp (v, x) <= 0)
+ err ("representable integer between x and its "
+ "rounded value", s, x, y, p, r, trint, inexact);
+ }
+ else
+ {
+ mpfr_sub_ui (v, y, 1, GMP_RNDD);
+ if (mpfr_cmp (v, x) >= 0)
+ err ("representable integer between x and its "
+ "rounded value", s, x, y, p, r, trint, inexact);
+ }
+ if (r == GMP_RNDN)
+ {
+ int cmp;
+ if (mpfr_sub (u, v, x, GMP_RNDN))
+ err ("subtraction 2 should be exact",
+ s, x, y, p, r, trint, inexact);
+ cmp = mpfr_cmp_abs (t, u);
+ if (cmp > 0)
+ err ("faithful rounding, but not the nearest integer",
+ s, x, y, p, r, trint, inexact);
+ if (cmp < 0)
+ continue;
+ /* |t| = |u|: x is the middle of two consecutive
+ representable integers. */
+ if (trint)
+ {
+ /* halfway case for mpfr_rint in GMP_RNDN rounding
+ mode: round to an even integer or mantissa. */
+ mpfr_div_2ui (y, y, 1, GMP_RNDZ);
+ if (!mpfr_integer_p (y))
+ err ("halfway case for mpfr_rint, result isn't an"
+ " even integer", s, x, y, p, r, trint, inexact);
+ /* If floor(x) and ceil(x) aren't both representable
+ integers, the mantissa must be even. */
+ mpfr_sub (v, v, y, GMP_RNDN);
+ mpfr_abs (v, v, GMP_RNDN);
+ if (mpfr_cmp_ui (v, 1) != 0)
+ {
+ mpfr_div_2si (y, y, MPFR_EXP (y) - MPFR_PREC (y)
+ + 1, GMP_RNDN);
+ if (!mpfr_integer_p (y))
+ err ("halfway case for mpfr_rint, mantissa isn't"
+ " even", s, x, y, p, r, trint, inexact);
+ }
+ }
+ else
+ { /* halfway case for mpfr_round: x must have been
+ rounded away from zero. */
+ if ((MPFR_SIGN (x) > 0 && inexact < 0) ||
+ (MPFR_SIGN (x) < 0 && inexact > 0))
+ err ("halfway case for mpfr_round, bad rounding"
+ " direction", s, x, y, p, r, trint, inexact);
+ }
+ }
+ }
}
}
mpfr_clear (x);
mpfr_clear (y);
mpz_clear (z);
mpfr_clear (t);
+ mpfr_clear (u);
+ mpfr_clear (v);
+
+ /* TODO: add hardcoded tests */
+#if __STDC_VERSION__ >= 199901L
+ if (argc > 1 && strcmp (argv[1], "-s") == 0)
+ test_against_libc ();
+#endif
tests_end_mpfr ();
return 0;
diff --git a/tests/tset.c b/tests/tset.c
index 379c1c623..cd37c3544 100644
--- a/tests/tset.c
+++ b/tests/tset.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_set.
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -27,6 +27,23 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
#include "mpfr-test.h"
+/* Maybe better create its own test file ? */
+static void
+check_neg_special ()
+{
+ mpfr_t x;
+ mpfr_init (x);
+ MPFR_SET_NAN (x);
+ mpfr_clear_nanflag ();
+ mpfr_neg (x, x, GMP_RNDN);
+ if (!mpfr_nanflag_p () )
+ {
+ printf("ERROR: neg (NaN) doesn't set Nan flag.\n");
+ exit (1);
+ }
+ mpfr_clear (x);
+}
+
int
main (void)
{
@@ -84,6 +101,8 @@ main (void)
mpfr_clear (z);
mpfr_clear (u);
+ check_neg_special ();
+
tests_end_mpfr ();
return 0;
}
diff --git a/tests/tset_f.c b/tests/tset_f.c
index e3fa5f05c..42bff6309 100644
--- a/tests/tset_f.c
+++ b/tests/tset_f.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_set_f.
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -23,7 +23,9 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include <time.h>
#include "gmp.h"
+#include "gmp-impl.h"
#include "mpfr.h"
+#include "mpfr-impl.h"
#include "mpfr-test.h"
int
@@ -32,11 +34,12 @@ main (void)
mpfr_t x, u;
mpf_t y, z;
unsigned long k, pr;
+ int r, inexact;
tests_start_mpfr ();
- mpf_init(y);
- mpf_init(z);
+ mpf_init (y);
+ mpf_init (z);
mpf_set_d (y, 0.0);
@@ -45,44 +48,84 @@ main (void)
mpfr_set_prec (x, 100);
mpfr_set_f (x, y, GMP_RNDN);
- mpf_random2(y, 10, 0);
- mpfr_set_f(x, y, randlimb () & 3);
+ mpf_random2 (y, 10, 0);
+ mpfr_set_f (x, y, randlimb () & 3);
/* bug found by Jean-Pierre Merlet */
- mpfr_set_prec(x, 256);
- mpf_set_prec(y, 256);
- mpfr_init2(u, 256);
- mpfr_set_str(u,
+ mpfr_set_prec (x, 256);
+ mpf_set_prec (y, 256);
+ mpfr_init2 (u, 256);
+ mpfr_set_str (u,
"7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2",
16, GMP_RNDN);
- mpf_set_str(y, "2033.033", 10);
- mpfr_set_f(x, y, GMP_RNDN);
- if (mpfr_cmp(x, u))
+ mpf_set_str (y, "2033.033", 10);
+ mpfr_set_f (x, y, GMP_RNDN);
+ if (mpfr_cmp (x, u))
{
printf ("mpfr_set_f failed for y=2033.033\n");
exit (1);
}
- mpf_set_str(y, "-2033.033", 10);
- mpfr_set_f(x, y, GMP_RNDN);
- mpfr_neg(u, u, GMP_RNDN);
- if (mpfr_cmp(x, u))
+ mpf_set_str (y, "-2033.033", 10);
+ mpfr_set_f (x, y, GMP_RNDN);
+ mpfr_neg (u, u, GMP_RNDN);
+ if (mpfr_cmp (x, u))
{
printf ("mpfr_set_f failed for y=-2033.033\n");
exit (1);
}
- mpfr_clear(u);
- mpfr_clear(x);
+ mpf_set_prec (y, 300);
+ mpf_set_str (y, "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", -2);
+ mpf_mul_2exp (y, y, 600);
+ mpfr_set_prec (x, 300);
+ mpfr_set_f (x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, 1, 901) == 0);
+
+ mpfr_clear (u);
for (k = 1; k <= 100000; k++)
{
pr = 2 + (randlimb () & 255);
mpf_set_prec (z, pr);
mpf_random2 (z, z->_mp_prec, 0);
- mpfr_init2 (x, pr);
+ mpfr_set_prec (x, pr);
mpfr_set_f (x, z, 0);
- mpfr_clear (x);
}
+
+ /* Check for +0 */
+ mpfr_set_prec (x, 53);
+ mpf_set_prec (y, 53);
+ mpf_set_ui (y, 0);
+ for(r = 0 ; r < 4 ; r++)
+ {
+ int i;
+ for (i = -1; i <= 1; i++)
+ {
+ if (i)
+ mpfr_set_si (x, i, GMP_RNDN);
+ inexact = mpfr_set_f (x, y, r);
+ if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x) <= 0 || inexact)
+ {
+ printf ("mpfr_set_f(x,0) failed for %s, i = %d\n",
+ mpfr_print_rnd_mode (r), i);
+ exit (1);
+ }
+ }
+ }
+
+ /* coverage test */
+ mpf_set_prec (y, 2);
+ mpfr_set_prec (x, 3 * mp_bits_per_limb);
+ mpf_set_ui (y, 1);
+ for (r = 0; r < mp_bits_per_limb; r++)
+ {
+ mpfr_random (x); /* to fill low limbs with random data */
+ inexact = mpfr_set_f (x, y, GMP_RNDN);
+ MPFR_ASSERTN(inexact == 0 && mpfr_cmp_ui_2exp (x, 1, r) == 0);
+ mpf_mul_2exp (y, y, 1);
+ }
+
+ mpfr_clear (x);
mpf_clear (y);
mpf_clear (z);
diff --git a/tests/tset_ld.c b/tests/tset_ld.c
index 0aed61892..7cb6a461e 100644
--- a/tests/tset_ld.c
+++ b/tests/tset_ld.c
@@ -29,6 +29,20 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
#include "mpfr-test.h"
+static void
+check_gcc33_bug (void)
+{
+ volatile long double x;
+ x = (long double) 9007199254740992.0 + 1.0;
+ if (x != 0.0)
+ return; /* OK */
+ printf
+ ("Detected optimization bug of gcc 3.3 on Alpha concerning long double\n"
+ "comparisons; set_ld tests are disabled (set_ld won't work correctly).\n"
+ "See http://gcc.gnu.org/ml/gcc-bugs/2003-10/msg00853.html for more\n"
+ "information on this bug.\n");
+ exit (0); /* This is not a bug in MPFR, so don't fail. */
+}
static int
Isnan_ld (long double d)
@@ -78,6 +92,8 @@ main (int argc, char *argv[])
mpfr_t x;
int i;
+ check_gcc33_bug ();
+
tests_start_mpfr ();
mpfr_test_init ();
tests_machine_prec_long_double ();
diff --git a/tests/tsub.c b/tests/tsub.c
index dc63be229..0cdca5ad6 100644
--- a/tests/tsub.c
+++ b/tests/tsub.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_sub.
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -37,6 +37,18 @@ check_diverse (void)
mpfr_init (y);
mpfr_init (z);
+ mpfr_set_prec (x, 288);
+ mpfr_set_prec (y, 288);
+ mpfr_set_prec (z, 288);
+ mpfr_set_str_binary (y, "0.111000110011000001000111101010111011110011101001101111111110000011100101000001001010110010101010011001010100000001110011110001010101101010001011101110100100001011110100110000101101100011010001001011011010101010000010001101001000110010010111111011110001111101001000101101001100101100101000E80");
+ mpfr_set_str_binary (z, "0.100001111111101001011010001100110010100111001110000110011101001011010100001000000100111011010110110010000000000010101101011000010000110001110010100001100101011100100100001011000100011110000001010101000100011101001000010111100000111000111011001000100100011000100000010010111000000100100111E-258");
+ inexact = mpfr_sub (x, y, z, GMP_RNDN);
+ if (inexact <= 0)
+ {
+ printf ("Wrong inexact flag for prec=288\n");
+ exit (1);
+ }
+
mpfr_set_prec (x, 32);
mpfr_set_prec (y, 63);
mpfr_set_prec (z, 63);
diff --git a/tests/tui_pow.c b/tests/tui_pow.c
index caac437fd..29171527d 100644
--- a/tests/tui_pow.c
+++ b/tests/tui_pow.c
@@ -36,8 +36,22 @@ test1 (void)
mpfr_init2 (x, 32);
mpfr_init2 (y, 65);
+
mpfr_set_str_binary (x, "-0.101110001001011011011e-9");
mpfr_ui_pow (y, 7, x, GMP_RNDN);
+
+ mpfr_set_prec (x, 40);
+ mpfr_set_str_binary (x, "-0.1100101100101111011001010010110011110110E-1");
+ mpfr_set_prec (y, 74);
+ mpfr_ui_pow (y, 8, x, GMP_RNDN);
+ mpfr_set_prec (x, 74);
+ mpfr_set_str_binary (x, "0.11100000010100111101000011111011011010011000011000101011010011010101000011E-1");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error for input of 40 bits, output of 74 bits\n");
+ exit (1);
+ }
+
mpfr_clear (x);
mpfr_clear (y);
}
@@ -131,7 +145,7 @@ main (int argc, char *argv[])
}
MPFR_CHANGE_SIGN(x);
- mpfr_ui_pow (y, n,x, GMP_RNDN);
+ mpfr_ui_pow (y, n, x, GMP_RNDN);
if(!MPFR_IS_ZERO(y))
{
printf ("evaluation of function in -INF does not return 0");
@@ -139,7 +153,7 @@ main (int argc, char *argv[])
}
MPFR_SET_NAN(x);
- mpfr_ui_pow (y, n,x, GMP_RNDN);
+ mpfr_ui_pow (y, n, x, GMP_RNDN);
if(!MPFR_IS_NAN(y))
{
printf ("evaluation of function in NAN does not return NAN");
@@ -165,6 +179,34 @@ main (int argc, char *argv[])
mpfr_set_str_binary (t, "0.110000E5");
mpfr_ui_pow (z, 3, t, GMP_RNDN);
+ mpfr_set_prec (x, 2);
+ mpfr_set_prec (y, 2);
+ mpfr_set_d (x, -0.5, GMP_RNDZ);
+ mpfr_ui_pow (y, 4, x, GMP_RNDD);
+ if (mpfr_get_d1 (y) != 0.5)
+ {
+ fprintf (stderr, "Error for 4^(-0.5), prec=2, GMP_RNDD\n");
+ fprintf (stderr, "expected 0.5, got ");
+ mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
+ fprintf (stderr, "\n");
+ exit (1);
+ }
+
+ /* problem found by Kevin on spe175.testdrive.compaq.com
+ (03 Sep 2003) */
+ mpfr_set_prec (x, 2);
+ mpfr_set_prec (y, 2);
+ mpfr_set_d (x, 0.5, GMP_RNDN);
+ mpfr_ui_pow (y, 398441521, x, GMP_RNDN);
+ if (mpfr_get_d1 (y) != 16384.0)
+ {
+ fprintf (stderr, "Error for 398441521^(0.5), prec=2, GMP_RNDN\n");
+ fprintf (stderr, "expected 1.0e14, got ");
+ mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
+ fprintf (stderr, "\n");
+ exit (1);
+ }
+
mpfr_clear (z);
mpfr_clear (t);
diff --git a/tests/tzeta.c b/tests/tzeta.c
index 95b6dd38e..92b8ee6a2 100644
--- a/tests/tzeta.c
+++ b/tests/tzeta.c
@@ -1,6 +1,6 @@
/* tzeta -- test file for the Riemann Zeta function
-Copyright 2003 Free Software Foundation.
+Copyright 2003, 2004 Free Software Foundation.
Contributed by Jean-Luc Re'my and the Spaces project, INRIA Lorraine.
This file is part of the MPFR Library.
@@ -35,8 +35,54 @@ test1 (void)
mpfr_init2 (x, 32);
mpfr_init2 (y, 42);
+
mpfr_set_str_binary (x, "1.1111111101000111011010010010100e-1");
mpfr_zeta (y, x, GMP_RNDN); /* shouldn't crash */
+
+ mpfr_set_prec (x, 40);
+ mpfr_set_prec (y, 50);
+ mpfr_set_str_binary (x, "1.001101001101000010011010110100110000101e-1");
+ mpfr_zeta (y, x, GMP_RNDU);
+ mpfr_set_prec (x, 50);
+ mpfr_set_str_binary (x, "-0.11111100011100111111101111100011110111001111111111E1");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error for input on 40 bits, output on 50 bits\n");
+ printf ("Expected "); mpfr_print_binary (x); puts ("");
+ printf ("Got "); mpfr_print_binary (y); puts ("");
+ mpfr_set_str_binary (x, "1.001101001101000010011010110100110000101e-1");
+ mpfr_zeta (y, x, GMP_RNDU);
+ mpfr_print_binary (x); puts ("");
+ mpfr_print_binary (y); puts ("");
+ exit (1);
+ }
+
+ mpfr_set_prec (x, 2);
+ mpfr_set_prec (y, 55);
+ mpfr_set_str_binary (x, "0.11e3");
+ mpfr_zeta (y, x, GMP_RNDN);
+ mpfr_set_prec (x, 55);
+ mpfr_set_str_binary (x, "0.1000001000111000010011000010011000000100100100100010010E1");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_zeta (1)\n");
+ printf ("Expected "); mpfr_print_binary (x); puts ("");
+ printf ("Got "); mpfr_print_binary (y); puts ("");
+ exit (1);
+ }
+
+ mpfr_set_prec (x, 3);
+ mpfr_set_prec (y, 47);
+ mpfr_set_str_binary (x, "0.111e4");
+ mpfr_zeta (y, x, GMP_RNDN);
+ mpfr_set_prec (x, 47);
+ mpfr_set_str_binary (x, "1.0000000000000100000000111001001010111100101011");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_zeta (2)\n");
+ exit (1);
+ }
+
mpfr_clear (x);
mpfr_clear (y);
}
diff --git a/zeta.c b/zeta.c
index f35268a25..b75f987e9 100644
--- a/zeta.c
+++ b/zeta.c
@@ -1,6 +1,6 @@
/* mpfr_zeta -- compute the Riemann Zeta function
-Copyright 2003 Free Software Foundation.
+Copyright 2003, 2004 Free Software Foundation.
Contributed by Jean-Luc Re'my and the Spaces project, INRIA Lorraine.
This file is part of the MPFR Library.
@@ -29,10 +29,6 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
-void mpfr_zeta_part_b _PROTO ((mpfr_t, mpfr_srcptr, int, int, mpfr_t *));
-void mpfr_zeta_c _PROTO ((int, mpfr_t *));
-void mpfr_zeta_part_a _PROTO ((mpfr_t, mpfr_srcptr, int));
-
/*
Parameters:
s - the input floating-point number
@@ -41,7 +37,7 @@ void mpfr_zeta_part_a _PROTO ((mpfr_t, mpfr_srcptr, int));
Output:
b is the result
*/
-void
+static void
mpfr_zeta_part_b (mpfr_t b, mpfr_srcptr s, int n, int p, mpfr_t *tc)
{
int n2, l, t, precb;
@@ -93,7 +89,7 @@ mpfr_zeta_part_b (mpfr_t b, mpfr_srcptr s, int n, int p, mpfr_t *tc)
/* Input: p - an integer
Output: fills tc[1..p]
*/
-void
+static void
mpfr_zeta_c (int p, mpfr_t *tc)
{
mpfr_t d;
@@ -122,8 +118,8 @@ mpfr_zeta_c (int p, mpfr_t *tc)
/* Input: s - a floating-point number
n - an integer
- Output: sum - a floating-point number */
-void
+ Output: sum - a floating-point number approximating sum(1/i^s, i=1..n-1) */
+static void
mpfr_zeta_part_a (mpfr_t sum, mpfr_srcptr s, int n)
{
int i, preca;
@@ -159,11 +155,11 @@ mpfr_zeta_part_a (mpfr_t sum, mpfr_srcptr s, int n)
static int
mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
{
- int p, n, l, dint, add, d, can_round;
+ int p, n, l, add, can_round;
double beta, sd, dnep;
- mpfr_t a,b,c,z_pre,f,g,s1;
+ mpfr_t a, b, c, z_pre, f, g, s1;
mpfr_t *tc1;
- mp_prec_t precz, precs;
+ mp_prec_t precz, precs, d, dint;
int inex;
precz = mpfr_get_prec (z);
@@ -182,7 +178,8 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
printf ("\n");
#endif
d = precz + 11;
- mpfr_init2 (s1, precs);
+ /* we want that s1 = s-1 is exact, i.e. we should have PREC(s1) >= EXP(s) */
+ mpfr_init2 (s1, (precs > MPFR_EXP(s)) ? precs : MPFR_EXP(s));
do
{
/* Principal loop: we compute, in z_pre,
@@ -195,7 +192,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
inex = 0;
goto clear_and_return;
}
- else if (MPFR_GET_EXP (s1) <= -(d-3)/2)
+ else if (MPFR_GET_EXP (s1) <= -(mp_exp_t) ((mp_prec_t) (d-3)/2))
/* Branch 1: when s-1 is very small, one
uses the approximation Zeta(s)=1/(s-1)+gamma,
where gamma is Euler's constant */
@@ -266,7 +263,8 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
/* Computation of the 3 parts of the fonction Zeta. */
mpfr_zeta_part_a (a, s, n);
mpfr_zeta_part_b (b, s, n, p, tc1);
- mpfr_sub_ui (s1, s, 1, GMP_RNDN);
+ /* s1 = s-1 is already computed above */
+ /* mpfr_sub_ui (s1, s, 1, GMP_RNDN); */
mpfr_ui_div (c, 1, s1, GMP_RNDN);
mpfr_ui_pow (f, n, s1, GMP_RNDN);
mpfr_div (c, c, f, GMP_RNDN);
@@ -328,7 +326,7 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
double sd, eps, m1, c;
int can_round;
long add;
- mpfr_t z_pre, s1, s2, y, sfrac, sint, p;
+ mpfr_t z_pre, s1, s2, y, p;
mp_prec_t precz, prec1, precs, precs1;
int inex;
@@ -367,7 +365,7 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
precs = mpfr_get_prec (s);
/* Precision precs1 needed to represent 1 - s, and s + 2,
without any truncation */
- precs1 = precs + 2 + MAX (0, - abs (MPFR_GET_EXP (s)));
+ precs1 = precs + 2 + MAX (0, - MPFR_GET_EXP (s));
sd = mpfr_get_d (s, GMP_RNDN) - 1.0;
if (sd < 0.0)
sd = -sd; /* now sd = abs(s-1.0) */
@@ -383,14 +381,13 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
prec1 = MAX(prec1, precs1);
if (MPFR_SIGN (s) != -1 && MPFR_GET_EXP (s) >= 0) /* Case s >= 1/2 */
inex = mpfr_zeta_pos (z, s, rnd_mode);
- else
+ else /* use reflection formula
+ zeta(s) = 2^s*Pi^(s-1)*sin(Pi*s/2)*gamma(1-s)*zeta(1-s) */
{
- mpfr_init2(z_pre, MPFR_PREC_MIN);
- mpfr_init2(s1, MPFR_PREC_MIN);
- mpfr_init2(y, MPFR_PREC_MIN);
- mpfr_init2(p, MPFR_PREC_MIN);
- mpfr_init2(sint, MPFR_PREC_MIN);
- mpfr_init2(sfrac, MPFR_PREC_MIN);
+ mpfr_init2 (z_pre, MPFR_PREC_MIN);
+ mpfr_init2 (s1, MPFR_PREC_MIN);
+ mpfr_init2 (y, MPFR_PREC_MIN);
+ mpfr_init2 (p, MPFR_PREC_MIN);
do
{
prec1 = prec1 + 10;
@@ -398,33 +395,18 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
mpfr_set_prec (s1, prec1);
mpfr_set_prec (y, prec1);
mpfr_set_prec (p, prec1);
- mpfr_set_prec (sint, prec1);
- mpfr_set_prec (sfrac, prec1);
- mpfr_ui_sub (s1, 1, s, GMP_RNDN);
- mpfr_add_ui (sfrac, s, 2, GMP_RNDN);
- mpfr_div_2ui (sfrac, sfrac, 2, GMP_RNDN);
- mpfr_floor (sint, sfrac);
- mpfr_sub (sfrac, sfrac, sint, GMP_RNDN);
- mpfr_mul_2ui (sfrac, sfrac, 2, GMP_RNDN);
- mpfr_sub_ui (sfrac, sfrac, 2, GMP_RNDN);
- if (mpfr_cmp_ui (sfrac, 1) > 0)
- mpfr_ui_sub (sfrac, 2, sfrac, GMP_RNDN);
- else if (mpfr_cmp_si (sfrac, -1) < 0)
- {
- mpfr_neg (sfrac, sfrac, GMP_RNDN);
- mpfr_sub_ui (sfrac, sfrac, 2, GMP_RNDN);
- }
- mpfr_div_2ui (sfrac, sfrac, 1, GMP_RNDN);
- mpfr_zeta_pos (z_pre, s1, GMP_RNDN);
- mpfr_gamma (y, s1, GMP_RNDN);
- mpfr_mul (z_pre, z_pre, y, GMP_RNDN);
+ mpfr_ui_sub (s1, 1, s, GMP_RNDN); /* s1 = 1-s */
+ mpfr_zeta_pos (z_pre, s1, GMP_RNDN); /* zeta(1-s) */
+ mpfr_gamma (y, s1, GMP_RNDN); /* gamma(1-s) */
+ mpfr_mul (z_pre, z_pre, y, GMP_RNDN); /* gamma(1-s)*zeta(1-s) */
mpfr_const_pi (p, GMP_RNDD);
- mpfr_mul (y, sfrac, p, GMP_RNDN);
- mpfr_sin (y, y, GMP_RNDN);
+ mpfr_mul (y, s, p, GMP_RNDN);
+ mpfr_div_2ui (y, y, 1, GMP_RNDN); /* s*Pi/2 */
+ mpfr_sin (y, y, GMP_RNDN); /* sin(Pi*s/2) */
mpfr_mul (z_pre, z_pre, y, GMP_RNDN);
- mpfr_mul_2ui (y, p, 1, GMP_RNDN);
- mpfr_neg (s1, s1, GMP_RNDN);
- mpfr_pow (y, y, s1, GMP_RNDN);
+ mpfr_mul_2ui (y, p, 1, GMP_RNDN); /* 2*Pi */
+ mpfr_neg (s1, s1, GMP_RNDN); /* s-1 */
+ mpfr_pow (y, y, s1, GMP_RNDN); /* (2*Pi)^(s-1) */
mpfr_mul (z_pre, z_pre, y, GMP_RNDN);
mpfr_mul_2ui (z_pre, z_pre, 1, GMP_RNDN);
can_round = mpfr_can_round (z_pre, prec1 - add, GMP_RNDN, GMP_RNDZ,
@@ -436,8 +418,6 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode)
mpfr_clear(s1);
mpfr_clear(y);
mpfr_clear(p);
- mpfr_clear(sint);
- mpfr_clear(sfrac);
}
return inex;
}