diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-12-17 23:59:32 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-12-17 23:59:32 +0000 |
commit | 7107797d0000ad2aed72de3b993582de079a492e (patch) | |
tree | 2130b92c5903502ae3c3a26d6c53a5199cffd899 | |
parent | d84fd7e461e1dc4be6be4a22fcafe2ef77d03db3 (diff) | |
parent | 0a21c66e52c42e13472c2a33e0a101d8b0b43839 (diff) | |
download | mpfr-7107797d0000ad2aed72de3b993582de079a492e.tar.gz |
Replaced the 4.0 branch by a copy of the trunk (in order to keep the
history of the latest changes of the trunk); this replacement is due
to a limitation of Subversion where a merge is regarded as a single
commit, and is OK here since the 4.0 branch is new.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@11990 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | ChangeLog | 309 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | doc/FAQ.html | 2 | ||||
-rw-r--r-- | doc/README.dev | 53 | ||||
-rw-r--r-- | doc/mpfr.texi | 2 | ||||
-rw-r--r-- | src/add1sp.c | 51 | ||||
-rw-r--r-- | src/div.c | 40 | ||||
-rw-r--r-- | src/exp.c | 2 | ||||
-rw-r--r-- | src/exp_2.c | 1 | ||||
-rw-r--r-- | src/get_q.c | 4 | ||||
-rw-r--r-- | src/lngamma.c | 10 | ||||
-rw-r--r-- | src/mpf2mpfr.h | 6 | ||||
-rw-r--r-- | src/mpfr-cvers.h | 4 | ||||
-rw-r--r-- | src/mpfr-gmp.h | 9 | ||||
-rw-r--r-- | src/mpfr-impl.h | 14 | ||||
-rw-r--r-- | src/mpfr.h | 2 | ||||
-rw-r--r-- | src/mul.c | 8 | ||||
-rw-r--r-- | src/root.c | 16 | ||||
-rw-r--r-- | src/sqr.c | 8 | ||||
-rw-r--r-- | src/sub1.c | 8 | ||||
-rw-r--r-- | src/sub1sp.c | 55 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/zeta.c | 14 | ||||
-rw-r--r-- | tests/reuse.c | 28 | ||||
-rw-r--r-- | tests/tadd1sp.c | 19 | ||||
-rw-r--r-- | tests/talloc.c | 1 | ||||
-rw-r--r-- | tests/tgeneric.c | 14 | ||||
-rw-r--r-- | tests/tget_q.c | 34 | ||||
-rw-r--r-- | tests/tget_set_d64.c | 4 | ||||
-rw-r--r-- | tests/troot.c | 21 | ||||
-rw-r--r-- | tests/tsub1sp.c | 68 | ||||
-rw-r--r-- | tests/tsum.c | 2 | ||||
-rw-r--r-- | tools/timings-mpfr.c | 21 |
35 files changed, 579 insertions, 260 deletions
@@ -1,67 +1,306 @@ ------------------------------------------------------------------------ -r11946 | vlefevre | 2017-12-08 16:17:03 +0000 (Fri, 08 Dec 2017) | 2 lines +r11987 | zimmerma | 2017-12-17 16:23:21 +0000 (Sun, 17 Dec 2017) | 2 lines Changed paths: - M /branches/4.0 - M /branches/4.0/src/Makefile.am + M /trunk/src/add1sp.c + +[src/add1sp.c] fix bug in mpfr_add1sp3() in case d=GMP_NUMB_BITS -[src/Makefile.am] Also distribute generic/coverage/mparam.h -(merged changeset r11945 from the trunk) ------------------------------------------------------------------------ -r11944 | vlefevre | 2017-12-08 15:01:52 +0000 (Fri, 08 Dec 2017) | 1 line +r11986 | zimmerma | 2017-12-17 15:16:48 +0000 (Sun, 17 Dec 2017) | 14 lines Changed paths: - M /branches/4.0/ChangeLog + M /trunk/tests/tadd1sp.c -ChangeLog update with "LC_ALL=en_US.UTF8 TZ=UTC svn log -rHEAD:0 -v". +[tests/tadd1sp.c] added test for new bug (still to be fixed): + +Seed GMP_CHECK_RANDOMIZE=1514385177 (include this in bug reports) +add1 & add1sp return different values for MPFR_RNDN +Prec_a = 137, Prec_b = 137, Prec_c = 137 +B = 0.11111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000E-66 +C = 0.11111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000110000E-2 + +add1 : 0.10000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001000E-1 +add1sp: 0.11111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000010000E-2 +Inexact sp = 0 | Inexact = 0 +Flags sp = 8 | Flags = 8 +add1sp.c:89: MPFR assertion failed: 0 + +------------------------------------------------------------------------ +r11981 | vlefevre | 2017-12-15 02:44:49 +0000 (Fri, 15 Dec 2017) | 1 line +Changed paths: + M /trunk/src/root.c + +[src/root.c] Minor comment correction. +------------------------------------------------------------------------ +r11980 | vlefevre | 2017-12-15 02:36:50 +0000 (Fri, 15 Dec 2017) | 4 lines +Changed paths: + M /trunk/src/root.c + M /trunk/tests/troot.c + +[src/root.c] Completed fix from r11978, as x=-1 was affected too. Also + added comments explaining that mpfr_root_aux assumes |x| ≠1 and why. + Hence the need of a filter on |x| = 1. +[tests/troot.c] Added test for x = -1. +------------------------------------------------------------------------ +r11979 | vlefevre | 2017-12-15 01:44:11 +0000 (Fri, 15 Dec 2017) | 1 line +Changed paths: + M /trunk/tests/troot.c + +[tests/troot.c] Replaced mpfr_root by TF (like in the other tests). +------------------------------------------------------------------------ +r11978 | zimmerma | 2017-12-14 10:22:32 +0000 (Thu, 14 Dec 2017) | 3 lines +Changed paths: + M /trunk/src/root.c + M /trunk/tests/troot.c + +[src/root.c] fixed bug when x=1 +[tests/troot.c] added non-regression test + +------------------------------------------------------------------------ +r11977 | vlefevre | 2017-12-14 07:57:05 +0000 (Thu, 14 Dec 2017) | 2 lines +Changed paths: + M /trunk/tests/tsub1sp.c + +[tests/tsub1sp.c] Corrected a type. And mpfr_equal_p being a predicate +function, it's better to use Boolean operators on it. +------------------------------------------------------------------------ +r11976 | zimmerma | 2017-12-14 07:35:35 +0000 (Thu, 14 Dec 2017) | 2 lines +Changed paths: + M /trunk/tests/tsub1sp.c + +[tests/tsub1sp.c] added a generic test for bug20171213() + +------------------------------------------------------------------------ +r11975 | vlefevre | 2017-12-14 02:17:05 +0000 (Thu, 14 Dec 2017) | 7 lines +Changed paths: + M /trunk/src/mul.c + M /trunk/src/sqr.c + +[src/{mul.c,sqr.c}] Minor changes, making code similar to sub1sp.c. +Checked with + grep -A 1 'sb *>>' src/*.c +that the bug fixed in r11974 does not occur in other parts of the code. +BTW, there is much duplicate code, as shown by the grep output, and +using macros could have avoided that, making bugs easier to reproduce +(since a same bug would be duplicate several times). +------------------------------------------------------------------------ +r11974 | zimmerma | 2017-12-13 21:18:23 +0000 (Wed, 13 Dec 2017) | 3 lines +Changed paths: + M /trunk/src/sub1sp.c + M /trunk/tests/tsub1sp.c + +[src/sub1sp.c] fixed bug in mpfr_sub1sp2() +[tests/tsub1sp.c] added non-regression test + +------------------------------------------------------------------------ +r11973 | vlefevre | 2017-12-13 18:00:00 +0000 (Wed, 13 Dec 2017) | 1 line +Changed paths: + M /trunk/src/mpf2mpfr.h + +[src/mpf2mpfr.h] Added a comment. +------------------------------------------------------------------------ +r11972 | zimmerma | 2017-12-13 17:25:07 +0000 (Wed, 13 Dec 2017) | 2 lines +Changed paths: + M /trunk/src/mpf2mpfr.h + +[src/mpf2mpfr.h] missing mpf_inits/mpf_clears + +------------------------------------------------------------------------ +r11969 | zimmerma | 2017-12-13 07:05:01 +0000 (Wed, 13 Dec 2017) | 2 lines +Changed paths: + M /trunk/src/mpfr-gmp.h + +[src/mpfr-gmp.h] redefine __clz_tab also with gmp-build + +------------------------------------------------------------------------ +r11968 | vlefevre | 2017-12-12 22:20:41 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/configure.ac + +[configure.ac] Improved error message. +------------------------------------------------------------------------ +r11967 | vlefevre | 2017-12-12 15:38:37 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/tests/talloc.c + +[tests/talloc.c] Added a comment about why talloc requires ISO C99. +------------------------------------------------------------------------ +r11966 | vlefevre | 2017-12-12 15:35:34 +0000 (Tue, 12 Dec 2017) | 4 lines +Changed paths: + M /trunk/src/mpfr-cvers.h + +[src/mpfr-cvers.h] Removed a useless test for __MPFR_STDC, as one just +needs to check whether we have a C99, C11, etc. implementation (if not +done via a configure test). Particular incompatibilities with the C90 +standard should always be checked via a configure test. +------------------------------------------------------------------------ +r11965 | vlefevre | 2017-12-12 12:04:01 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/tests + +[tests] Added *.exe to svn:ignore property (files from MinGW builds). +------------------------------------------------------------------------ +r11964 | zimmerma | 2017-12-12 11:07:36 +0000 (Tue, 12 Dec 2017) | 2 lines +Changed paths: + M /trunk/tools/timings-mpfr.c + +[tools/timings-mpfr.c] always use clock() [now very accurate under Linux] + +------------------------------------------------------------------------ +r11963 | vlefevre | 2017-12-12 10:15:50 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/tools/timings-mpfr.c + +[tools/timings-mpfr.c] Updated years in copyright notice. +------------------------------------------------------------------------ +r11962 | vlefevre | 2017-12-12 10:14:08 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/tools/timings-mpfr.c + +[tools/timings-mpfr.c] Fixed prototypes. +------------------------------------------------------------------------ +r11961 | vlefevre | 2017-12-12 10:12:48 +0000 (Tue, 12 Dec 2017) | 2 lines +Changed paths: + M /trunk/tools/timings-mpfr.c + +[tools/timings-mpfr.c] Added a defined(_MSC_VER). But clock() is +standard, so why not always using it? +------------------------------------------------------------------------ +r11960 | vlefevre | 2017-12-12 01:17:00 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/doc/README.dev + +[doc/README.dev] Correction. +------------------------------------------------------------------------ +r11959 | vlefevre | 2017-12-12 01:11:31 +0000 (Tue, 12 Dec 2017) | 1 line +Changed paths: + M /trunk/doc/README.dev + +[doc/README.dev] Made formatting consistent (same as configure --help). +------------------------------------------------------------------------ +r11958 | vlefevre | 2017-12-12 00:58:43 +0000 (Tue, 12 Dec 2017) | 5 lines +Changed paths: + M /trunk/tests/reuse.c + M /trunk/tests/tget_set_d64.c + M /trunk/tests/tsum.c + +Completed r11955: There were also DEBUG macros under the "tests" +directory. Since such macros can still be useful in case a test failure, +replaced them by MPFR_DEBUG to avoid issues with CI builds that define +the DEBUG macro. But an environment variable would be a better solution +(see MPFR_DEBUG_BADCASES as an example). ------------------------------------------------------------------------ -r11943 | vlefevre | 2017-12-08 14:55:53 +0000 (Fri, 08 Dec 2017) | 1 line +r11957 | vlefevre | 2017-12-12 00:44:45 +0000 (Tue, 12 Dec 2017) | 1 line Changed paths: - M /branches/4.0 - M /branches/4.0/doc/FAQ.html + M /trunk/TODO -[doc] Updated FAQ.html with a merge of changeset r11942 from the trunk. +[TODO] Removed item on the DEBUG macro (done in r11955). ------------------------------------------------------------------------ -r11940 | vlefevre | 2017-12-08 14:33:54 +0000 (Fri, 08 Dec 2017) | 3 lines +r11956 | zimmerma | 2017-12-11 17:36:36 +0000 (Mon, 11 Dec 2017) | 3 lines Changed paths: - M /branches/4.0 - M /branches/4.0/doc/FAQ.html + M /trunk/doc/README.dev + M /trunk/src/mpfr-impl.h + M /trunk/tests/tgeneric.c + +DEBUG_TGENERIC -> MPFR_DEBUG_TGENERIC +XDEBUG -> MPFR_DISABLE_IEEE_FLOATS -[doc] Updated FAQ.html with a merge of changeset r11939 from the trunk -and a replacement assuming MPFR 4.0.0 has been released (since this is -a file for the MPFR 4.0.0 release). ------------------------------------------------------------------------ -r11937 | vlefevre | 2017-12-08 14:15:30 +0000 (Fri, 08 Dec 2017) | 1 line +r11955 | zimmerma | 2017-12-11 17:02:05 +0000 (Mon, 11 Dec 2017) | 3 lines Changed paths: - M /branches/4.0/NEWS + M /trunk/src/add1sp.c + M /trunk/src/div.c + M /trunk/src/exp.c + M /trunk/src/exp_2.c + M /trunk/src/mpfr-impl.h + M /trunk/src/sub1.c + M /trunk/src/sub1sp.c + M /trunk/src/zeta.c + +get rid of DEBUG macro (but keep corresponding commands in comment to help +understanding of the code and debugging) -[NEWS] Added test coverage for MPFR 4.0.0. ------------------------------------------------------------------------ -r11936 | vlefevre | 2017-12-08 14:05:15 +0000 (Fri, 08 Dec 2017) | 1 line +r11954 | vlefevre | 2017-12-11 15:33:31 +0000 (Mon, 11 Dec 2017) | 1 line Changed paths: - M /branches/4.0/VERSION - M /branches/4.0/configure.ac - M /branches/4.0/doc/mpfr.texi - M /branches/4.0/src/mpfr.h - M /branches/4.0/src/version.c + M /trunk/tests/tget_q.c -Updated version to 4.0.0-rc1. +[tests/tget_q.c] Removed trailing whitespace. ------------------------------------------------------------------------ -r11935 | vlefevre | 2017-12-08 14:00:43 +0000 (Fri, 08 Dec 2017) | 6 lines +r11953 | zimmerma | 2017-12-10 07:42:03 +0000 (Sun, 10 Dec 2017) | 2 lines Changed paths: - M /branches/4.0 - M /branches/4.0/doc/README.dev + M /trunk/tests/tget_q.c + +[tests/tget_q.c] replaced MPFR_ASSERTN(0) by exit(1) + +------------------------------------------------------------------------ +r11952 | vlefevre | 2017-12-10 02:02:43 +0000 (Sun, 10 Dec 2017) | 2 lines +Changed paths: + M /trunk/src/get_q.c + +[src/get_q.c] Optimization of r11951 suggested by Trevor Spiteri: +https://sympa.inria.fr/sympa/arc/mpfr/2017-12/msg00040.html +------------------------------------------------------------------------ +r11951 | zimmerma | 2017-12-09 21:59:21 +0000 (Sat, 09 Dec 2017) | 3 lines +Changed paths: + M /trunk/src/get_q.c + M /trunk/tests/tget_q.c + +[src/get_q.c] make result of mpfr_get_q in canonical form +[tests/tget_q.c] added non-regression test + +------------------------------------------------------------------------ +r11950 | zimmerma | 2017-12-09 21:46:01 +0000 (Sat, 09 Dec 2017) | 2 lines +Changed paths: + M /trunk/src/lngamma.c + +[src/lngamma.c] replace call to __gmpfr_ceil_log2 by __gmpfr_int_ceil_log2 + +------------------------------------------------------------------------ +r11949 | vlefevre | 2017-12-09 11:18:20 +0000 (Sat, 09 Dec 2017) | 1 line +Changed paths: + M /trunk/TODO + +[TODO] Rename the DEBUG macro to MPFR_DEBUG? +------------------------------------------------------------------------ +r11945 | vlefevre | 2017-12-08 16:15:36 +0000 (Fri, 08 Dec 2017) | 2 lines +Changed paths: + M /trunk/src/Makefile.am + +[src/Makefile.am] Also distribute generic/coverage/mparam.h +(at least useful for testing the distributed tarballs). +------------------------------------------------------------------------ +r11942 | vlefevre | 2017-12-08 14:53:52 +0000 (Fri, 08 Dec 2017) | 1 line +Changed paths: + M /trunk/doc/FAQ.html + +[doc] Updated FAQ.html with update-faq. +------------------------------------------------------------------------ +r11939 | vlefevre | 2017-12-08 14:30:37 +0000 (Fri, 08 Dec 2017) | 1 line +Changed paths: + M /trunk/doc/FAQ.html + +[doc] Updated FAQ.html with update-faq. +------------------------------------------------------------------------ +r11934 | vlefevre | 2017-12-08 13:56:42 +0000 (Fri, 08 Dec 2017) | 5 lines +Changed paths: + M /trunk/doc/README.dev [doc/README.dev] "To make a release": * Note that this needs to be done in a branch. * Swapped (1) and (2), in particular because the coverage might be different in -dev versions and it is better to give results closer to the release. -(merged changeset r11934 from the trunk) ------------------------------------------------------------------------ -r11932 | vlefevre | 2017-12-08 13:38:16 +0000 (Fri, 08 Dec 2017) | 1 line +r11933 | vlefevre | 2017-12-08 13:40:19 +0000 (Fri, 08 Dec 2017) | 1 line Changed paths: - A /branches/4.0 (from /trunk:11931) + M /trunk/INSTALL + M /trunk/VERSION + M /trunk/configure.ac + M /trunk/doc/mpfr.texi + M /trunk/src/mpfr.h + M /trunk/src/version.c -Created branch 4.0. +Updated version to 4.1.0-dev. ------------------------------------------------------------------------ r11931 | vlefevre | 2017-12-08 13:17:51 +0000 (Fri, 08 Dec 2017) | 1 line Changed paths: @@ -110,7 +110,6 @@ Changes from versions 3.1.* to version 4.0.0: in the computation of Bernoulli numbers (used in mpfr_gamma, mpfr_li2, mpfr_digamma, mpfr_lngamma and mpfr_lgamma), in mpfr_div, in mpfr_fma and mpfr_fms. -- Test coverage: 96.3% lines of code. - Bug fixes. In particular: a speed improvement when the --enable-assert or --enable-assert=full configure option is used with GCC; mpfr_get_str now sets the NaN flag on NaN input and the inexact flag when the conversion @@ -1 +1 @@ -4.0.0-rc1 +4.0.0-rc2 diff --git a/configure.ac b/configure.ac index 064b5d635..06bab3db9 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., ]) dnl Add check-news when it checks for more than 15 lines -AC_INIT([MPFR],[4.0.0-rc1]) +AC_INIT([MPFR],[4.0.0-rc2]) dnl Older Automake versions than 1.13 may still be supported, but no longer dnl tested, and many things have changed in 1.13. Moreover the INSTALL file @@ -427,7 +427,7 @@ dnl http://www.ncsa.illinois.edu/UserInfo/Resources/Software/Intel/Compilers AC_MSG_CHECKING(for ICC) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #if !defined(__ICC) -# error "ICC Not Found" +# error "Not ICC" error #endif ]], [[]])],[ diff --git a/doc/FAQ.html b/doc/FAQ.html index ae9f29fae..92530c190 100644 --- a/doc/FAQ.html +++ b/doc/FAQ.html @@ -338,7 +338,7 @@ installation using <cite>autoconf</cite> or <cite>pkg-config</cite>?</dt> <dd><p>The <cite><acronym>MPFR</acronym></cite> team does not currently recommend any <cite>autoconf</cite> code, but a section will later be added to the <cite><acronym>MPFR</acronym></cite> manual. -Limited <cite>pkg-config</cite> support has been added for +Limited <cite>pkg-config</cite> support will be added for <cite><acronym>MPFR</acronym></cite> 4.0.0; example:</p> <pre style="margin-left: 2em">cc myprogram.c $(pkg-config --cflags --libs mpfr)</pre></dd> diff --git a/doc/README.dev b/doc/README.dev index e1900cca3..f74ca080a 100644 --- a/doc/README.dev +++ b/doc/README.dev @@ -210,9 +210,9 @@ To make a release (for the MPFR team): 6) Test the release version on different machines, with --enable-assert set to "yes", "no" (default), "none" and "full" respectively, with - and without -DXDEBUG in $CFLAGS, with and without gmp internal files - (--enable-gmp-internals), with and without GMP built as a shared - library, with objdir equal to and different from srcdir (e.g. + and without -DMPFR_DISABLE_IEEE_FLOATS in $CFLAGS, with and without gmp + internal files (--enable-gmp-internals), with and without GMP built as + a shared library, with objdir equal to and different from srcdir (e.g. ../mpfr-source/configure after making mpfr-source read-only), with and without --enable-logging. @@ -255,16 +255,17 @@ To make a release (for the MPFR team): 32, mode32 and mode64 (in particular mode32, where long's have 32 bits and limbs have 64 bits [long long]). - Test with -DMPFR_TESTS_FPE_DIV -DMPFR_ERRDIVZERO -DXDEBUG in order + Test with -DMPFR_TESTS_FPE_DIV -DMPFR_ERRDIVZERO + -DMPFR_DISABLE_IEEE_FLOATS in order to detect whether tests can fail due to a FP division by 0 (yielding either FE_DIVBYZERO, e.g. from 1.0 / 0.0 to generate an infinity, or FE_INVALID, e.g. from 0.0 / 0.0 to generate a NaN) on platforms where such an operation fails (e.g. trap). On platforms that do not support IEEE 754, such an operation yields an undefined behavior. If _MPFR_IEEE_FLOATS is defined to 1 (by the configure script), some - divisions by 0 are avoided in the MPFR library. The -DXDEBUG option - sets _MPFR_IEEE_FLOATS to 0, allowing one to detect more issues, for - platforms without IEEE floats. + divisions by 0 are avoided in the MPFR library. + The -DMPFR_DISABLE_IEEE_FLOATS option sets _MPFR_IEEE_FLOATS to 0, + allowing one to detect more issues, for platforms without IEEE floats. Test with -D_MPFR_PREC_FORMAT=2 when the "int" type is smaller than the "long" type. @@ -425,11 +426,8 @@ Format of long double. + HAVE_LDOUBLE_IEEE_QUAD_LITTLE: IEEE quad, little endian. + HAVE_LDOUBLE_MAYBE_DOUBLE_DOUBLE: Double-double (a.k.a. IBM). -+ DEBUG: For debugging messages in some functions (currently - not suitable for "make check" because many messages - would be output and it is not possible to disable - these messages once this macro has been defined). -+ XDEBUG: Use generic 'double' code instead of IEEE specific one. ++ MPFR_DISABLE_IEEE_FLOATS: + Use generic 'double' code instead of IEEE specific one. + MPFR_WANT_ASSERT: Assertion level. See src/mpfr-impl.h for details. + MPFR_EXP_CHECK: Define if we want to check the exp field. @@ -448,7 +446,8 @@ Format of long double. as double-double (a.k.a. IBM long double). + MPFR_USE_LOGGING: Define to enable logging. -+ MPFR_WANT_DECIMAL_FLOATS: Define to build conversion functions from/to ++ MPFR_WANT_DECIMAL_FLOATS: + Define to build conversion functions from/to decimal floats. + MPFR_WANT_FLOAT128: Define to build conversion functions from/to __float128. @@ -459,12 +458,14 @@ Format of long double. the GMP build directory (--with-gmp-build). + MPFR_USE_THREAD_SAFE: Define to build MPFR as thread safe (TLS). -+ MPFR_USE_C11_THREAD_SAFE: Define to implement TLS in the C11 way. ++ MPFR_USE_C11_THREAD_SAFE: + Define to implement TLS in the C11 way. + MPFR_HAVE_NORETURN: Define if the _Noreturn function specifier is supported. -+ MPFR_HAVE_BUILTIN_UNREACHABLE: Define if the __builtin_unreachable - GCC built-in is supported. ++ MPFR_HAVE_BUILTIN_UNREACHABLE: + Define if the __builtin_unreachable GCC built-in is + supported. + MPFR_GENERIC_ABI: Define to disable code that is tied to a specific ABI (e.g. GMP_NUMB_BITS value). @@ -523,7 +524,8 @@ Environment variables that affect the tests: + MPFR_CHECK_LARGEMEM: Define to enable expensive tests. -+ MPFR_CHECK_LIBC_PRINTF: Define to enable comparisons with the printf ++ MPFR_CHECK_LIBC_PRINTF: + Define to enable comparisons with the printf function of the C library. These comparisons are disabled by default as failures could be due to the C library itself on some machines, and they @@ -531,11 +533,12 @@ Environment variables that affect the tests: + MPFR_DEBUG_BADCASES: For debugging (see tests.c, function bad_cases). -+ MPFR_SUSPICIOUS_OVERFLOW: Define to check suspicious overflow in the - generic tests (tgeneric.c). For developers and - testers. ++ MPFR_SUSPICIOUS_OVERFLOW: + Define to check suspicious overflow in the generic + tests (tgeneric.c). For developers and testers. -+ MPFR_TESTS_MEMORY_LIMIT: The memory limit for the tests (default is ++ MPFR_TESTS_MEMORY_LIMIT: + The memory limit for the tests (default is 2^22 = 4 MB). Set to 0 for unlimited. + MPFR_TESTS_TIMEOUT: When timeout in the tests is enabled, this @@ -575,7 +578,7 @@ But: [...] if (l != 0) do_action (); - since mp_limb_t may be "unsigned long long", and some buggy compiler +since mp_limb_t may be "unsigned long long", and some buggy compiler produce illegal codes with the first form. ===================================================================== @@ -748,9 +751,9 @@ for undefined preprocessing identifier"). =========================================================================== If you want to use the logging of MPFR, you need to enable it: - ./configure --enable-logging - make clean - make + make distclean + ./configure --enable-logging + make Then link your program with this new build of MPFR. Warning! The logging code for functions sometimes output an "inexact" diff --git a/doc/mpfr.texi b/doc/mpfr.texi index e5a6f63ff..3dccf760b 100644 --- a/doc/mpfr.texi +++ b/doc/mpfr.texi @@ -2,7 +2,7 @@ @c %**start of header @setfilename mpfr.info @documentencoding UTF-8 -@set VERSION 4.0.0-rc1 +@set VERSION 4.0.0-rc2 @set UPDATED-MONTH December 2017 @settitle GNU MPFR @value{VERSION} @synindex tp fn diff --git a/src/add1sp.c b/src/add1sp.c index 004ffb7a7..3dee9df79 100644 --- a/src/add1sp.c +++ b/src/add1sp.c @@ -94,14 +94,6 @@ int mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) # define mpfr_add1sp mpfr_add1sp_ref #endif /* MPFR_WANT_ASSERT >= 2 */ -/* Debugging support */ -#ifdef DEBUG -# undef DEBUG -# define DEBUG(x) (x) -#else -# define DEBUG(x) /**/ -#endif - #if !defined(MPFR_GENERIC_ABI) /* same as mpfr_add1sp, but for p < GMP_NUMB_BITS */ @@ -535,7 +527,11 @@ mpfr_add1sp3 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, : (cp[2] << (2*GMP_NUMB_BITS-d)) | (cp[1] >> (d - GMP_NUMB_BITS)); a0 = bp[0] + c0shifted; a1 = bp[1] + (cp[2] >> (d - GMP_NUMB_BITS)) + (a0 < bp[0]); - a2 = bp[2] + (a1 < bp[1]); + /* if a1 < bp[1], there was a carry in the above addition, + or when a1 = bp[1] and one of the added terms is nonzero + (the sum of cp[2] >> (d - GMP_NUMB_BITS) and a0 < bp[0] + is at most 2^GMP_NUMB_BITS-d) */ + a2 = bp[2] + ((a1 < bp[1]) || (a1 == bp[1] && a0 < bp[0])); if (a2 == 0) goto exponent_shift; rb = a0 & (MPFR_LIMB_ONE << (sh - 1)); @@ -680,17 +676,17 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) MPFR_UNSIGNED_MINUS_MODULO(sh, p); d = (mpfr_uexp_t) (bx - MPFR_GET_EXP(c)); - DEBUG (printf ("New add1sp with diff=%lu\n", (unsigned long) d)); + /* printf ("New add1sp with diff=%lu\n", (unsigned long) d); */ if (d == 0) { /* d==0 */ - DEBUG( mpfr_print_mant_binary("C= ", MPFR_MANT(c), p) ); - DEBUG( mpfr_print_mant_binary("B= ", MPFR_MANT(b), p) ); + /* mpfr_print_mant_binary("C= ", MPFR_MANT(c), p); */ + /* mpfr_print_mant_binary("B= ", MPFR_MANT(b), p); */ bx++; /* exp + 1 */ ap = MPFR_MANT(a); limb = mpn_add_n (ap, MPFR_MANT(b), MPFR_MANT(c), n); - DEBUG( mpfr_print_mant_binary("A= ", ap, p) ); + /* mpfr_print_mant_binary("A= ", ap, p); */ MPFR_ASSERTD(limb != 0); /* There must be a carry */ limb = ap[0]; /* Get LSB (In fact, LSW) */ mpn_rshift (ap, ap, n, 1); /* Shift mantissa A */ @@ -817,9 +813,9 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) } } - DEBUG( mpfr_print_mant_binary("Before", MPFR_MANT(c), p) ); - DEBUG( mpfr_print_mant_binary("B= ", MPFR_MANT(b), p) ); - DEBUG( mpfr_print_mant_binary("After ", cp, p) ); + /* mpfr_print_mant_binary("Before", MPFR_MANT(c), p); + mpfr_print_mant_binary("B= ", MPFR_MANT(b), p); + mpfr_print_mant_binary("After ", cp, p); */ /* fast track for RNDF */ if (rnd_mode == MPFR_RNDF) @@ -853,9 +849,8 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) mp_limb_t *tp = MPFR_MANT(c); mp_size_t kx = n - 1 - (x / GMP_NUMB_BITS); mpfr_prec_t sx = GMP_NUMB_BITS - 1 - (x % GMP_NUMB_BITS); - DEBUG (printf ("(First) x=%lu Kx=%ld Sx=%lu\n", - (unsigned long) x, (long) kx, - (unsigned long) sx)); + /* printf ("(First) x=%lu Kx=%ld Sx=%lu\n", + (unsigned long) x, (long) kx, (unsigned long) sx); */ /* Looks at the last bits of limb kx (if sx=0 does nothing)*/ if (tp[kx] & MPFR_LIMB_MASK(sx)) bcp1 = 1; @@ -892,8 +887,8 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) bcp1 = (kx >= 0); } } - DEBUG (printf("sh=%u Cp=%lu C'p+1=%lu\n", sh, - (unsigned long) bcp, (unsigned long) bcp1)); + /* printf("sh=%u Cp=%lu C'p+1=%lu\n", sh, + (unsigned long) bcp, (unsigned long) bcp1); */ clean: /* Clean shifted C' */ @@ -903,7 +898,7 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) /* Add the mantissa c from b in a */ ap = MPFR_MANT(a); limb = mpn_add_n (ap, MPFR_MANT(b), cp, n); - DEBUG( mpfr_print_mant_binary("Add= ", ap, p) ); + /* mpfr_print_mant_binary("Add= ", ap, p); */ /* Check for overflow */ if (MPFR_UNLIKELY (limb)) @@ -915,9 +910,9 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) ap[0] &= mask; /* Clear LSB bit */ bcp1 |= bcp; /* Recompute C'p+1 */ bcp = limb; /* Recompute Cp */ - DEBUG (printf ("(Overflow) Cp=%lu C'p+1=%lu\n", - (unsigned long) bcp, (unsigned long) bcp1)); - DEBUG (mpfr_print_mant_binary ("Add= ", ap, p)); + /* printf ("(Overflow) Cp=%lu C'p+1=%lu\n", + (unsigned long) bcp, (unsigned long) bcp1); + mpfr_print_mant_binary ("Add= ", ap, p); */ } /* Round: @@ -949,11 +944,11 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) add_one_ulp: /* add one unit in last place to a */ - DEBUG( printf("AddOneUlp\n") ); + /* printf("AddOneUlp\n"); */ if (MPFR_UNLIKELY( mpn_add_1(ap, ap, n, MPFR_LIMB_ONE<<sh) )) { /* Case 100000x0 = 0x1111x1 + 1*/ - DEBUG( printf("Pow of 2\n") ); + /* printf("Pow of 2\n"); */ bx++; ap[n-1] = MPFR_LIMB_HIGHBIT; } @@ -962,7 +957,7 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) set_exponent: if (MPFR_UNLIKELY(bx > __gmpfr_emax)) /* Check for overflow */ { - DEBUG( printf("Overflow\n") ); + /* printf("Overflow\n"); */ MPFR_TMP_FREE(marker); return mpfr_overflow (a, rnd_mode, MPFR_SIGN(a)); } @@ -651,21 +651,6 @@ mpfr_div_2 (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) #endif /* !defined(MPFR_GENERIC_ABI) */ -#ifdef DEBUG2 -#define mpfr_mpn_print(ap,n) mpfr_mpn_print3 (ap,n,MPFR_LIMB_ZERO) -static void -mpfr_mpn_print3 (mpfr_limb_ptr ap, mp_size_t n, mp_limb_t cy) -{ - mp_size_t i; - for (i = 0; i < n; i++) - printf ("+%lu*2^%lu", (unsigned long) ap[i], (unsigned long) - (GMP_NUMB_BITS * i)); - if (cy) - printf ("+2^%lu", (unsigned long) (GMP_NUMB_BITS * n)); - printf ("\n"); -} -#endif - /* check if {ap, an} is zero */ static int mpfr_mpn_cmpzero (mpfr_limb_ptr ap, mp_size_t an) @@ -1052,9 +1037,6 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) else /* k=0: no more dividend limb */ extra_bit = mpfr_mpn_cmpzero (vp, l) == 0; } -#ifdef DEBUG - printf ("extra_bit=%d\n", extra_bit); -#endif /* set exponent */ qexp = MPFR_GET_EXP (u) - MPFR_GET_EXP (v) + extra_bit; @@ -1225,10 +1207,6 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) /* if Mulders' short division failed, we revert to division with remainder */ qh = mpn_divrem (qp, 0, ap + k, qqsize - k, bp, qsize - k); /* warning: qh may be 1 if u1 == v1, but u < v */ -#ifdef DEBUG2 - printf ("q="); mpfr_mpn_print (qp, qsize); - printf ("r="); mpfr_mpn_print (ap, qsize); -#endif k = qsize; sticky_u = sticky_u || mpfr_mpn_cmpzero (ap, k); @@ -1256,20 +1234,12 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) including the round bit, and 1 <= sh2 <= GMP_NUMB_BITS is the number of bits in sticky3 */ inex = (sticky != MPFR_LIMB_ZERO) || (sticky3 != MPFR_LIMB_ZERO); -#ifdef DEBUG - printf ("sticky=%lu sticky3=%lu inex=%d\n", - (unsigned long) sticky, (unsigned long) sticky3, inex); -#endif /* to round, we distinguish two cases: (a) vsize <= qsize: we used the full divisor (b) vsize > qsize: the divisor was truncated */ -#ifdef DEBUG - printf ("vsize=%lu qsize=%lu\n", - (unsigned long) vsize, (unsigned long) qsize); -#endif if (MPFR_LIKELY(vsize <= qsize)) /* use the full divisor */ { if (MPFR_LIKELY(rnd_mode == MPFR_RNDN)) @@ -1302,10 +1272,6 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) { round_bit = sticky3 & (MPFR_LIMB_ONE << (sh2 - 1)); sticky3 = sticky3 ^ round_bit; -#ifdef DEBUG - printf ("rb=%lu sb=%lu\n", - (unsigned long) round_bit, (unsigned long) sticky3); -#endif } if (sticky3 != MPFR_LIMB_ZERO && sticky3 != MPFR_LIMB_ONE) { @@ -1343,9 +1309,6 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) mpfr_mpn_cmp_aux (sp, k, up, usize - qqsize, extra_bit) : mpfr_mpn_cmpzero (sp, k); } -#ifdef DEBUG - printf ("cmp(q*v0,r+u0)=%d\n", cmp_s_r); -#endif /* now cmp_s_r > 0 if {sp, vsize} > {ap, qsize} + low(u) cmp_s_r = 0 if {sp, vsize} = {ap, qsize} + low(u) cmp_s_r < 0 if {sp, vsize} < {ap, qsize} + low(u) */ @@ -1403,9 +1366,6 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) cmp_s_r = 1; /* since in fact we subtracted less than 1 */ } -#ifdef DEBUG - printf ("cmp(q*v0-(r+u0),v)=%d\n", cmp_s_r); -#endif if (cmp_s_r <= 0) /* q1-1 <= u/v < q1 */ { if (sticky3 == MPFR_LIMB_ONE) @@ -22,8 +22,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-impl.h" -/* #define DEBUG */ - /* Cache for emin and emax bounds. Contrary to other caches, it uses a fixed size for the mantissa, so there is no dynamic allocation, and no need to free them. */ diff --git a/src/exp_2.c b/src/exp_2.c index ea6350be9..a9439b8b0 100644 --- a/src/exp_2.c +++ b/src/exp_2.c @@ -21,7 +21,6 @@ along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* #define DEBUG */ #define MPFR_NEED_LONGLONG_H /* for count_leading_zeros */ #include "mpfr-impl.h" diff --git a/src/get_q.c b/src/get_q.c index bdd274c39..8cc2bc02b 100644 --- a/src/get_q.c +++ b/src/get_q.c @@ -32,6 +32,8 @@ mpfr_get_q (mpq_ptr q, mpfr_srcptr f) mpz_ptr u = mpq_numref (q); mpz_ptr v = mpq_denref (q); + /* v is set to 1 and will not be changed directly. + This ensures that q will be canonical. */ mpz_set_ui (v, 1); if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) @@ -54,7 +56,7 @@ mpfr_get_q (mpq_ptr q, mpfr_srcptr f) else /* exp < 0 */ { MPFR_ASSERTN (-exp <= (mp_bitcnt_t) -1); - mpz_mul_2exp (v, v, -exp); + mpq_div_2exp (q, q, -exp); } } } diff --git a/src/lngamma.c b/src/lngamma.c index 8eaff8dd9..147ef6bfc 100644 --- a/src/lngamma.c +++ b/src/lngamma.c @@ -640,7 +640,7 @@ GAMMA_FUNC (mpfr_ptr y, mpfr_srcptr z0, mpfr_rnd_t rnd) |h| <= (2m+48)*ulp(s), thus exp(s0) = exp(s) * exp(-h). For |h| <= 1/4, we have |exp(h)-1| <= 1.2*|h| thus |exp(s) - exp(s0)| <= 1.2 * exp(s) * (2m+48)* 2^(EXP(s)-w). */ - d = 1.2 * (2.0 * (double) m + 48.0); + /* d = 1.2 * (2.0 * (double) m + 48.0); */ /* the error on s is bounded by d*2^err_s * 2^(-w) */ mpfr_sqrt (t, v, MPFR_RNDN); /* let v0 be the exact value of v. We have v = v0*(1+u)^(4k+1), @@ -649,7 +649,13 @@ GAMMA_FUNC (mpfr_ptr y, mpfr_srcptr z0, mpfr_rnd_t rnd) /* the error on input s is bounded by (1+u)^(d*2^err_s), and that on t is (1+u)^(2k+3/2), thus the total error is (1+u)^(d*2^err_s+2k+5/2) */ - err_s += __gmpfr_ceil_log2 (d); + /* err_s += __gmpfr_ceil_log2 (d); */ + /* since d = 1.2 * (2m+48), ceil(log2(d)) = 2 + ceil(log2(0.6*m+14.4)) + <= 2 + ceil(log2(0.6*m+15)) */ + { + unsigned long mm = (1 + m / 5) * 3; /* 0.6*m <= mm */ + err_s += 2 + __gmpfr_int_ceil_log2 (mm + 15); + } err_t = __gmpfr_ceil_log2 (2.0 * (double) k + 2.5); err_s = (err_s >= err_t) ? err_s + 1 : err_t + 1; #else diff --git a/src/mpf2mpfr.h b/src/mpf2mpfr.h index a6231cff8..2c2c881c8 100644 --- a/src/mpf2mpfr.h +++ b/src/mpf2mpfr.h @@ -39,6 +39,12 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #undef mpf_init2 #define mpf_init2(x,p) (mpfr_init2((x),(p)), mpfr_set_ui ((x), 0, MPFR_DEFAULT_RND)) +/* Warning! This assumes that all pointer types have the same representation. */ +#undef mpf_inits +#define mpf_inits mpfr_inits +#undef mpf_clears +#define mpf_clears mpfr_clears + /* functions which don't take as argument the rounding mode */ #undef mpf_ceil #define mpf_ceil mpfr_ceil diff --git a/src/mpfr-cvers.h b/src/mpfr-cvers.h index 67d651efd..177bac31b 100644 --- a/src/mpfr-cvers.h +++ b/src/mpfr-cvers.h @@ -25,9 +25,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., /* Macros to detect STDC, ICC, GCC, and GLIBC versions */ #if defined(__STDC_VERSION__) -# define __MPFR_STDC(version) (__STDC_VERSION__>=(version)) -#elif defined(__STDC__) -# define __MPFR_STDC(version) (0 == (version)) +# define __MPFR_STDC(version) (__STDC_VERSION__ >= (version)) #else # define __MPFR_STDC(version) 0 #endif diff --git a/src/mpfr-gmp.h b/src/mpfr-gmp.h index 4eb103a41..a4c13aa41 100644 --- a/src/mpfr-gmp.h +++ b/src/mpfr-gmp.h @@ -80,7 +80,10 @@ extern "C" { # error "Can't compute log2(GMP_NUMB_BITS)" #endif - +/* Remap names of internal mpn functions (for longlong.h). + Note: this should be made both with and without gmp build. */ +#undef __clz_tab +#define __clz_tab mpfr_clz_tab /****************************************************** ************* Define GMP Internal Interface ********* @@ -231,10 +234,6 @@ typedef mp_limb_t UWtype; typedef unsigned int UHWtype; #define W_TYPE_SIZE GMP_NUMB_BITS -/* Remap names of internal mpn functions (for longlong.h). */ -#undef __clz_tab -#define __clz_tab mpfr_clz_tab - /* Use (4.0 * ...) instead of (2.0 * ...) to work around buggy compilers that don't convert ulong->double correctly (eg. SunOS 4 native cc). */ #undef MP_BASE_AS_DOUBLE diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index d035c349c..95c44ebfd 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -581,8 +581,8 @@ __MPFR_DECLSPEC extern const mpfr_t __gmpfr_const_log2_RNDU; # endif #endif -/* With -DXDEBUG, exercise non IEEE floats */ -#ifdef XDEBUG +/* With -DMPFR_DISABLE_IEEE_FLOATS, exercise non IEEE floats */ +#ifdef MPFR_DISABLE_IEEE_FLOATS # ifdef _MPFR_IEEE_FLOATS # undef _MPFR_IEEE_FLOATS # endif @@ -1397,16 +1397,6 @@ do { \ } \ while (0) -/* Use it only for debug reasons */ -/* MPFR_TRACE (operation) : execute operation iff DEBUG flag is set */ -/* MPFR_DUMP (x) : print x (a mpfr_t) on stdout */ -#ifdef DEBUG -# define MPFR_TRACE(x) x -#else -# define MPFR_TRACE(x) (void) 0 -#endif -#define MPFR_DUMP(x) ( printf(#x"="), mpfr_dump(x) ) - /* Test if X (positive) is a power of 2 */ #define IS_POW2(X) (((X) & ((X) - 1)) == 0) #define NOT_POW2(X) (((X) & ((X) - 1)) != 0) diff --git a/src/mpfr.h b/src/mpfr.h index b4682ec95..b0171a6e2 100644 --- a/src/mpfr.h +++ b/src/mpfr.h @@ -27,7 +27,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define MPFR_VERSION_MAJOR 4 #define MPFR_VERSION_MINOR 0 #define MPFR_VERSION_PATCHLEVEL 0 -#define MPFR_VERSION_STRING "4.0.0-rc1" +#define MPFR_VERSION_STRING "4.0.0-rc2" /* User macros: MPFR_USE_FILE: Define it to make MPFR define functions dealing @@ -242,7 +242,7 @@ mpfr_mul_1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, needed in asm). Make sure that GCC generates optimized code once it supports carry-in. */ a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; } rb = a0 & (MPFR_LIMB_ONE << (sh - 1)); sb |= (a0 & mask) ^ rb; @@ -333,7 +333,7 @@ mpfr_mul_1n (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) needed in asm). Make sure that GCC generates optimized code once it supports carry-in. */ a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; } rb = sb & MPFR_LIMB_HIGHBIT; sb = sb & ~MPFR_LIMB_HIGHBIT; @@ -461,7 +461,7 @@ mpfr_mul_2 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, ax --; h = (h << 1) | (l >> (GMP_NUMB_BITS - 1)); l = (l << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; /* no need to shift sb2 since we only want to know if it is zero or not */ } ap[1] = h; @@ -595,7 +595,7 @@ mpfr_mul_3 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, a2 = (a2 << 1) | (a1 >> (GMP_NUMB_BITS - 1)); a1 = (a1 << 1) | (a0 >> (GMP_NUMB_BITS - 1)); a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; /* no need to shift sb2: we only need to know if it is zero or not */ } ap[2] = a2; diff --git a/src/root.c b/src/root.c index 0d619a3d7..6bf9d578d 100644 --- a/src/root.c +++ b/src/root.c @@ -112,6 +112,11 @@ mpfr_rootn_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long k, mpfr_rnd_t rnd_mode) MPFR_RET_NAN; } + /* Special case |x| = 1. Note that if x = -1, then k is odd + (NaN results have already been filtered), so that y = -1. */ + if (mpfr_cmpabs (x, __gmpfr_one) == 0) + return mpfr_set (y, x, rnd_mode); + /* General case */ /* For large k, use exp(log(x)/k). The threshold of 100 seems to be quite @@ -193,6 +198,14 @@ mpfr_rootn_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long k, mpfr_rnd_t rnd_mode) Assume all special cases have been eliminated before. In the extended exponent range, overflows/underflows are not possible. Assume x > 0, or x < 0 and k odd. + Also assume |x| <> 1 because log(1) = 0, which does not have an exponent + and would yield a failure in the error bound computation. A priori, this + constraint is quite artificial because if |x| is close enough to 1, then + the exponent of log|x| does not need to be used (in the code, err would + be 1 in such a domain). So this constraint |x| <> 1 could be avoided in + the code. However, this is an exact case easy to detect, so that such a + change would be useless. Values very close to 1 are not an issue, since + an underflow is not possible before the MPFR_GET_EXP. */ static int mpfr_root_aux (mpfr_ptr y, mpfr_srcptr x, unsigned long k, mpfr_rnd_t rnd_mode) @@ -224,7 +237,8 @@ mpfr_root_aux (mpfr_ptr y, mpfr_srcptr x, unsigned long k, mpfr_rnd_t rnd_mode) mpfr_log (t, absx, MPFR_RNDN); /* t = log|x| * (1 + theta) with |theta| <= 2^(-w) */ mpfr_div_ui (t, t, k, MPFR_RNDN); - expt = MPFR_GET_EXP (t); + /* No possible underflow in mpfr_log and mpfr_div_ui. */ + expt = MPFR_GET_EXP (t); /* assumes t <> 0 */ /* t = log|x|/k * (1 + theta) + eps with |theta| <= 2^(-w) and |eps| <= 1/2 ulp(t), thus the total error is bounded by 1.5 * 2^(expt - w) */ @@ -50,7 +50,7 @@ mpfr_sqr_1 (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode, mpfr_prec_t p) { ax --; a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; } rb = a0 & (MPFR_LIMB_ONE << (sh - 1)); sb |= (a0 & mask) ^ rb; @@ -143,7 +143,7 @@ mpfr_sqr_1n (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode) { ax --; a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; } rb = sb & MPFR_LIMB_HIGHBIT; sb = sb & ~MPFR_LIMB_HIGHBIT; @@ -270,7 +270,7 @@ mpfr_sqr_2 (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode, mpfr_prec_t p) ax --; h = (h << 1) | (l >> (GMP_NUMB_BITS - 1)); l = (l << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; /* no need to shift sb2 since we only want to know if it is zero or not */ } ap[1] = h; @@ -412,7 +412,7 @@ mpfr_sqr_3 (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode, mpfr_prec_t p) a2 = (a2 << 1) | (a1 >> (GMP_NUMB_BITS - 1)); a1 = (a1 << 1) | (a0 >> (GMP_NUMB_BITS - 1)); a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); - sb = sb << 1; + sb <<= 1; /* no need to shift sb2: we only need to know if it is zero or not */ } ap[2] = a2; diff --git a/src/sub1.c b/src/sub1.c index f67fcd9f0..258e3bec6 100644 --- a/src/sub1.c +++ b/src/sub1.c @@ -238,7 +238,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) cp[0] = mpn_rshift (cp + 1, MPFR_MANT(c), cn++, shift_c); } -#ifdef DEBUG +#if 0 MPFR_LOG_MSG (("rnd=%s shift_b=%d shift_c=%d diffexp=%" MPFR_EXP_FSPEC "d\n", mpfr_print_rnd_mode (rnd_mode), shift_b, shift_c, (mpfr_eexp_t) diff_exp)); @@ -271,7 +271,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) else cancel2 = - (mp_size_t) ((diff_exp - cancel) / GMP_NUMB_BITS); /* the high cancel2 limbs from b should not be taken into account */ -#ifdef DEBUG +#if 0 MPFR_LOG_MSG (("cancel=%Pd cancel1=%Pd cancel2=%Pd\n", cancel, cancel1, cancel2)); #endif @@ -404,7 +404,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) cn0 = cn; cn -= an + cancel2; -#ifdef DEBUG +#if 0 MPFR_LOG_MSG (("last sh=%d bits from a are %Mu, bn=%Pd, cn=%Pd\n", sh, carry, (mpfr_prec_t) bn, (mpfr_prec_t) cn)); #endif @@ -497,7 +497,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) } } -#ifdef DEBUG +#if 0 MPFR_LOG_MSG (("k=%d bb=%Mu cc=%Mu cmp_low=%d\n", k, bb, cc, cmp_low)); #endif diff --git a/src/sub1sp.c b/src/sub1sp.c index decb12244..bc776ee1b 100644 --- a/src/sub1sp.c +++ b/src/sub1sp.c @@ -84,14 +84,6 @@ int mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) # define mpfr_sub1sp mpfr_sub1sp_ref #endif /* MPFR_WANT_ASSERT >= 2 */ -/* Debugging support */ -#ifdef DEBUG -# undef DEBUG -# define DEBUG(x) (x) -#else -# define DEBUG(x) /**/ -#endif - #if !defined(MPFR_GENERIC_ABI) /* special code for p < GMP_NUMB_BITS */ @@ -616,6 +608,7 @@ mpfr_sub1sp2 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, { ap[1] = (a1 << 1) | (a0 >> (GMP_NUMB_BITS - 1)); a0 = (a0 << 1) | (sb >> (GMP_NUMB_BITS - 1)); + sb <<= 1; bx --; } else @@ -1193,7 +1186,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) /* Now |b| > |c| */ MPFR_ASSERTD(bx >= cx); d = (mpfr_uexp_t) bx - cx; - DEBUG (printf ("New with diff=%lu\n", (unsigned long) d)); + /* printf ("New with diff=%lu\n", (unsigned long) d); */ if (d <= 1) { @@ -1256,7 +1249,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) MPFR_TMP_FREE(marker); /* since b and c have same sign, exponent and precision, the subtraction is exact */ - DEBUG( printf("(D==0 Underflow)\n") ); + /* printf("(D==0 Underflow)\n"); */ /* for MPFR_RNDN, mpfr_underflow always rounds away from zero, thus for |a| <= 2^(emin-2) we change to RNDZ. */ if (rnd_mode == MPFR_RNDN && @@ -1443,7 +1436,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) else bcp1 = 1; } - DEBUG( printf("(D=P) Cp=-1 Cp+1=%d C'p+1=%d \n", bbcp!=0, bcp1!=0) ); + /* printf("(D=P) Cp=-1 Cp+1=%d C'p+1=%d \n", bbcp!=0, bcp1!=0); */ bp = MPFR_MANT (b); /* Even if src and dest overlap, it is OK using MPN_COPY */ @@ -1483,7 +1476,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) { /* Cp=0, Cp+1=-1 if d==p+1, C'p+1=-1 */ bcp = 0; bbcp = (d==p+1); bcp1 = 1; - DEBUG( printf("(D>P) Cp=%d Cp+1=%d C'p+1=%d\n", bcp!=0,bbcp!=0,bcp1!=0) ); + /* printf("(D>P) Cp=%d Cp+1=%d C'p+1=%d\n", bcp!=0,bbcp!=0,bcp1!=0); */ /* Need to compute C'p+2 if d==p+1 and if rnd_mode=NEAREST (Because of a very improbable case) */ if (MPFR_UNLIKELY(d==p+1 && rnd_mode==MPFR_RNDN)) @@ -1499,7 +1492,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) } else bbcp1 = 1; - DEBUG( printf("(D>P) C'p+2=%d\n", bbcp1!=0) ); + /* printf("(D>P) C'p+2=%d\n", bbcp1!=0); */ } /* Copy mantissa B in A */ MPN_COPY(ap, MPFR_MANT(b), n); @@ -1545,9 +1538,9 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) MPN_ZERO(cp+n-m, m); } - DEBUG( mpfr_print_mant_binary("Before", MPFR_MANT(c), p) ); - DEBUG( mpfr_print_mant_binary("B= ", MPFR_MANT(b), p) ); - DEBUG( mpfr_print_mant_binary("After ", cp, p) ); + /* mpfr_print_mant_binary("Before", MPFR_MANT(c), p); */ + /* mpfr_print_mant_binary("B= ", MPFR_MANT(b), p); */ + /* mpfr_print_mant_binary("After ", cp, p); */ /* Compute bcp=Cp and bcp1=C'p+1 */ if (MPFR_LIKELY(sh)) @@ -1570,9 +1563,8 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) mp_limb_t *tp = MPFR_MANT(c); mp_size_t kx = n-1 - (x / GMP_NUMB_BITS); mpfr_prec_t sx = GMP_NUMB_BITS-1-(x%GMP_NUMB_BITS); - DEBUG (printf ("(First) x=%lu Kx=%ld Sx=%lu\n", - (unsigned long) x, (long) kx, - (unsigned long) sx)); + /* printf ("(First) x=%lu Kx=%ld Sx=%lu\n", + (unsigned long) x, (long) kx, (unsigned long) sx); */ /* Looks at the last bits of limb kx (if sx=0 does nothing)*/ if (tp[kx] & MPFR_LIMB_MASK(sx)) bcp1 = 1; @@ -1610,7 +1602,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) bcp1 = (kx >= 0); } } - DEBUG( printf("sh=%lu Cp=%d C'p+1=%d\n", sh, bcp!=0, bcp1!=0) ); + /* printf("sh=%lu Cp=%d C'p+1=%d\n", sh, bcp!=0, bcp1!=0); */ /* Check if we can lose a bit, and if so compute Cp+1 and C'p+2 */ bp = MPFR_MANT(b); @@ -1634,9 +1626,8 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) mpfr_prec_t sx = GMP_NUMB_BITS-1 - (x % GMP_NUMB_BITS); MPFR_ASSERTD(p > d); - DEBUG (printf ("(pre) x=%lu Kx=%ld Sx=%lu\n", - (unsigned long) x, (long) kx, - (unsigned long) sx)); + /* printf ("(pre) x=%lu Kx=%ld Sx=%lu\n", + (unsigned long) x, (long) kx, (unsigned long) sx); */ bbcp = (tp[kx] & (MPFR_LIMB_ONE<<sx)) ; /* Looks at the last bits of limb kx (If sx=0, does nothing)*/ /* If Cp+1=0, since C'p+1!=0, C'p+2=1 ! */ @@ -1649,10 +1640,10 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) kx--; while (kx >= 0 && tp[kx] == 0); bbcp1 = (kx >= 0); - DEBUG (printf ("(Pre) Scan done for %ld\n", (long) kx)); + /* printf ("(Pre) Scan done for %ld\n", (long) kx); */ } } /*End of Bcp1 != 0*/ - DEBUG( printf("(Pre) Cp+1=%d C'p+2=%d\n", bbcp!=0, bbcp1!=0) ); + /* printf("(Pre) Cp+1=%d C'p+2=%d\n", bbcp!=0, bbcp1!=0); */ } /* End of "can lose a bit" */ /* Clean shifted C' */ @@ -1662,7 +1653,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) /* Subtract the mantissa c from b in a */ ap = MPFR_MANT(a); mpn_sub_n (ap, bp, cp, n); - DEBUG( mpfr_print_mant_binary("Sub= ", ap, p) ); + /* mpfr_print_mant_binary("Sub= ", ap, p); */ /* Normalize: we lose at max one bit*/ if (MPFR_UNLIKELY(MPFR_LIMB_MSB(ap[n-1]) == 0)) @@ -1731,7 +1722,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) for d = 1 are in the "SubD1NoLose" case, and in that case |b|-|c| >= 1/2*W^n, thus round(|b|-|c|) >= 1/2*W^n, and ap[n-1] cannot go below MPFR_LIMB_HIGHBIT. */ - DEBUG( printf("(SubOneUlp)Cp=%d, Cp+1=%d C'p+1=%d\n", bcp!=0,bbcp!=0,bcp1!=0)); + /* printf("(SubOneUlp)Cp=%d, Cp+1=%d C'p+1=%d\n", bcp!=0,bbcp!=0,bcp1!=0); */ /* Compute the last bit (Since we have shifted the mantissa) we need one more bit! */ MPFR_ASSERTD(bbcp != MPFR_LIMB_MAX); @@ -1742,14 +1733,14 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) ap[0] |= MPFR_LIMB_ONE << sh; if (rnd_mode == MPFR_RNDN) inexact = 1; - DEBUG( printf("(SubOneUlp) Last bit set\n") ); + /* printf("(SubOneUlp) Last bit set\n"); */ } /* Result could be exact if C'p+1 = 0 and rnd == Zero since we have had one more bit to the result */ /* Fixme: rnd_mode == MPFR_RNDZ needed ? */ if (rnd_mode == MPFR_RNDZ && bcp1 == 0) { - DEBUG( printf("(SubOneUlp) Exact result\n") ); + /* printf("(SubOneUlp) Exact result\n"); */ inexact = 0; } } @@ -1780,15 +1771,15 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) /* It is a power of 2! */ /* Compute Cp+1 if it isn't already compute (ie d==1) */ /* Note: if d=1, we have {a, n} > 1/2*W^n, thus we cannot have k < 0. */ - DEBUG( printf("(Truncate) Cp=%d, Cp+1=%d C'p+1=%d C'p+2=%d\n", \ - bcp!=0, bbcp!=0, bcp1!=0, bbcp1!=0) ); + /* printf("(Truncate) Cp=%d, Cp+1=%d C'p+1=%d C'p+2=%d\n", + bcp!=0, bbcp!=0, bcp1!=0, bbcp1!=0); */ MPFR_ASSERTD(bbcp != MPFR_LIMB_MAX); MPFR_ASSERTD(rnd_mode != MPFR_RNDN || bcp != 0 || bbcp == 0 || bbcp1 != MPFR_LIMB_MAX); if ((rnd_mode != MPFR_RNDZ && bcp != 0) || (rnd_mode == MPFR_RNDN && bcp == 0 && bbcp != 0 && bbcp1 != 0)) { - DEBUG( printf("(Truncate) Do sub\n") ); + /* printf("(Truncate) Do sub\n"); */ mpn_sub_1 (ap, ap, n, MPFR_LIMB_ONE << sh); ap[n-1] |= MPFR_LIMB_HIGHBIT; bx--; diff --git a/src/version.c b/src/version.c index 684ce0b1f..94679c01e 100644 --- a/src/version.c +++ b/src/version.c @@ -25,5 +25,5 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., const char * mpfr_get_version (void) { - return "4.0.0-rc1"; + return "4.0.0-rc2"; } diff --git a/src/zeta.c b/src/zeta.c index caebc36b3..7931ce258 100644 --- a/src/zeta.c +++ b/src/zeta.c @@ -203,8 +203,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) where gamma is Euler's constant */ { dint = MAX (d + 3, precs); - MPFR_TRACE (printf ("branch 1\ninternal precision=%lu\n", - (unsigned long) dint)); + /* branch 1, with internal precision dint */ MPFR_GROUP_REPREC_4 (group, dint, b, c, z_pre, f); mpfr_div (z_pre, __gmpfr_one, s1, MPFR_RNDN); mpfr_const_euler (f, MPFR_RNDN); @@ -214,7 +213,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) { size_t size; - MPFR_TRACE (printf ("branch 2\n")); + /* branch 2 */ /* Computation of parameters n, p and working precision */ dnep = (double) d * LOG2; sd = mpfr_get_d (s, MPFR_RNDN); @@ -234,7 +233,6 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) p = 1 + (int) beta / 2; n = 1 + (int) ((sd + 2.0 * (double) p - 1.0) / 6.2832); } - MPFR_TRACE (printf ("\nn=%d\np=%d\n",n,p)); /* add = 4 + floor(1.5 * log(d) / log (2)). We should have add >= 10, which is always fulfilled since d = precz + 11 >= 12, thus ceil(log2(d)) >= 4 */ @@ -244,8 +242,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) if (dint < precs) dint = precs; - MPFR_TRACE (printf ("internal precision=%lu\n", - (unsigned long) dint)); + /* internal precision is dint */ size = (p + 1) * sizeof(mpfr_t); tc1 = (mpfr_t*) mpfr_allocate_func (size); @@ -253,8 +250,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) mpfr_init2 (tc1[l], dint); MPFR_GROUP_REPREC_4 (group, dint, b, c, z_pre, f); - MPFR_TRACE (printf ("precision of z = %lu\n", - (unsigned long) precz)); + /* precision of z is precz */ /* Computation of the coefficients c_k */ mpfr_zeta_c (p, tc1); @@ -265,7 +261,6 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) mpfr_div (c, __gmpfr_one, s1, MPFR_RNDN); mpfr_ui_pow (f, n, s1, MPFR_RNDN); mpfr_div (c, c, f, MPFR_RNDN); - MPFR_TRACE (MPFR_DUMP (c)); mpfr_add (z_pre, z_pre, c, MPFR_RNDN); mpfr_add (z_pre, z_pre, b, MPFR_RNDN); for (l=1; l<=p; l++) @@ -274,7 +269,6 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode) /* End branch 2 */ } - MPFR_TRACE (MPFR_DUMP (z_pre)); if (MPFR_LIKELY (MPFR_CAN_ROUND (z_pre, d-3, precz, rnd_mode))) break; MPFR_ZIV_NEXT (loop, d); diff --git a/tests/reuse.c b/tests/reuse.c index 96163a0f8..2705d7c47 100644 --- a/tests/reuse.c +++ b/tests/reuse.c @@ -101,8 +101,8 @@ test3 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t), mpfr_t res1; int i; -#ifdef DEBUG - printf("checking %s\n", foo); +#ifdef MPFR_DEBUG + printf ("checking %s\n", foo); #endif mpfr_init2 (ref1, prec); mpfr_init2 (ref2, prec); @@ -174,8 +174,8 @@ test4 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr, mpfr_t res; int i, j, k; -#ifdef DEBUG - printf("checking %s\n", foo); +#ifdef MPFR_DEBUG + printf ("checking %s\n", foo); #endif mpfr_init2 (ref, prec); mpfr_init2 (op1, prec); @@ -303,8 +303,8 @@ test2ui (int (*testfunc)(mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t), mpfr_t res1; int i; -#ifdef DEBUG - printf("checking %s\n", foo); +#ifdef MPFR_DEBUG + printf ("checking %s\n", foo); #endif mpfr_init2 (ref1, prec); mpfr_init2 (ref2, prec); @@ -348,8 +348,8 @@ testui2 (int (*testfunc)(mpfr_ptr, unsigned long int, mpfr_srcptr, mpfr_rnd_t), mpfr_t res1; int i; -#ifdef DEBUG - printf("checking %s\n", foo); +#ifdef MPFR_DEBUG + printf ("checking %s\n", foo); #endif mpfr_init2 (ref1, prec); mpfr_init2 (ref3, prec); @@ -389,8 +389,8 @@ test2 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_rnd_t), mpfr_t res1; int i; -#ifdef DEBUG - printf("checking %s\n", foo); +#ifdef MPFR_DEBUG + printf ("checking %s\n", foo); #endif mpfr_init2 (ref1, prec); mpfr_init2 (ref2, prec); @@ -429,7 +429,7 @@ test2a (int (*testfunc)(mpfr_ptr, mpfr_srcptr), mpfr_t res1; int i; -#ifdef DEBUG +#ifdef MPFR_DEBUG printf ("checking %s\n", foo); #endif mpfr_init2 (ref1, prec); @@ -469,7 +469,7 @@ test3a (int (*testfunc)(mpfr_ptr, mpfr_ptr, mpfr_srcptr, mpfr_rnd_t), mpfr_t res1, res2; int i; -#ifdef DEBUG +#ifdef MPFR_DEBUG printf ("checking %s\n", foo); #endif mpfr_init2 (ref1, prec); @@ -532,8 +532,8 @@ pow_int (mpfr_rnd_t rnd) mpfr_t res1; int i; -#ifdef DEBUG - printf("pow_int\n"); +#ifdef MPFR_DEBUG + printf ("pow_int\n"); #endif mpfr_inits2 ((randlimb () % 200) + MPFR_PREC_MIN, ref1, ref2, res1, (mpfr_ptr) 0); diff --git a/tests/tadd1sp.c b/tests/tadd1sp.c index eda82bb41..62aa42a34 100644 --- a/tests/tadd1sp.c +++ b/tests/tadd1sp.c @@ -54,6 +54,24 @@ check_overflow (void) set_emax (emax); } +static void +bug20171217 (void) +{ + mpfr_t a, b, c; + + mpfr_init2 (a, 137); + mpfr_init2 (b, 137); + mpfr_init2 (c, 137); + mpfr_set_str_binary (b, "0.11111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000E-66"); + mpfr_set_str_binary (c, "0.11111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000110000E-2"); + mpfr_add (a, b, c, MPFR_RNDN); + mpfr_set_str_binary (b, "0.10000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001000E-1"); + MPFR_ASSERTN(mpfr_equal_p (a, b)); + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); +} + int main (void) { @@ -61,6 +79,7 @@ main (void) tests_start_mpfr (); + bug20171217 (); check_special (); for(p = MPFR_PREC_MIN; p < 200 ; p++) check_random (p); diff --git a/tests/talloc.c b/tests/talloc.c index 5597d35d4..70cfe11eb 100644 --- a/tests/talloc.c +++ b/tests/talloc.c @@ -31,6 +31,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., # define MPFR_ALLOCA_MAX 16384 #endif +/* ISO C99 is needed by MPFR_DECL_INIT. */ #if __MPFR_STDC (199901L) && MPFR_ALLOCA_MAX <= 16384 int diff --git a/tests/tgeneric.c b/tests/tgeneric.c index b2851e72d..62f9ec619 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -104,7 +104,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define TGENERIC_CHECK(S, EXPR) TGENERIC_CHECK_AUX(S, EXPR, 0) #endif -#ifdef DEBUG_TGENERIC +#ifdef MPFR_DEBUG_TGENERIC #define TGENERIC_IAUX(F,P,X,U) \ do \ { \ @@ -125,7 +125,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #else #define TGENERIC_INFO(F,P) TGENERIC_IAUX(F,P,x,0) #endif -#endif /* DEBUG_TGENERIC */ +#endif /* MPFR_DEBUG_TGENERIC */ /* For some functions (for example cos), the argument reduction is too expensive when using mpfr_get_emax(). Then simply define REDUCE_EMAX @@ -309,7 +309,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) rnd = RND_RAND (); mpfr_clear_flags (); -#ifdef DEBUG_TGENERIC +#ifdef MPFR_DEBUG_TGENERIC TGENERIC_INFO (TEST_FUNCTION, MPFR_PREC (y)); #endif #if defined(TWO_ARGS) @@ -429,7 +429,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) mpfr_flags_t ex_flags; mpfr_set_emax (e - 1); -#ifdef DEBUG_TGENERIC +#ifdef MPFR_DEBUG_TGENERIC printf ("tgeneric: overflow test (emax = %" MPFR_EXP_FSPEC "d)\n", (mpfr_eexp_t) __gmpfr_emax); @@ -488,7 +488,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) mpfr_flags_t ex_flags; mpfr_set_emin (e + 1); -#ifdef DEBUG_TGENERIC +#ifdef MPFR_DEBUG_TGENERIC printf ("tgeneric: underflow test (emin = %" MPFR_EXP_FSPEC "d)\n", (mpfr_eexp_t) __gmpfr_emin); @@ -556,7 +556,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) { mpfr_set_emin (emin); mpfr_set_emax (emax); -#ifdef DEBUG_TGENERIC +#ifdef MPFR_DEBUG_TGENERIC /* Useful information in case of assertion failure. */ printf ("tgeneric: reduced exponent range [%" MPFR_EXP_FSPEC "d,%" MPFR_EXP_FSPEC "d]\n", @@ -666,7 +666,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) test below). */ if (randlimb () & 1) __gmpfr_flags = MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE; -#ifdef DEBUG_TGENERIC +#ifdef MPFR_DEBUG_TGENERIC TGENERIC_INFO (TEST_FUNCTION, MPFR_PREC (z)); #endif /* Let's increase the precision of the inputs in a random way. diff --git a/tests/tget_q.c b/tests/tget_q.c index fa2d5bb8b..cb8b2b4db 100644 --- a/tests/tget_q.c +++ b/tests/tget_q.c @@ -100,6 +100,38 @@ random_tests (void) mpfr_clear (g); } +/* Check results are in canonical form. + See https://sympa.inria.fr/sympa/arc/mpfr/2017-12/msg00029.html */ +static void +check_canonical (void) +{ + mpfr_t x; + mpq_t q; + mpz_t z; + + mpfr_init2 (x, 53); + mpfr_set_ui (x, 3, MPFR_RNDN); + mpq_init (q); + mpfr_get_q (q, x); + /* check the denominator is positive */ + if (mpz_sgn (mpq_denref (q)) <= 0) + { + printf ("Error, the denominator of mpfr_get_q should be positive\n"); + exit (1); + } + mpz_init (z); + mpz_gcd (z, mpq_numref (q), mpq_denref (q)); + /* check the numerator and denominator are coprime */ + if (mpz_cmp_ui (z, 1) != 0) + { + printf ("Error, numerator and denominator of mpfr_get_q should be coprime\n"); + exit (1); + } + mpfr_clear (x); + mpq_clear (q); + mpz_clear (z); +} + int main (void) { @@ -108,6 +140,8 @@ main (void) special (); random_tests (); + check_canonical (); + tests_end_mpfr (); return 0; } diff --git a/tests/tget_set_d64.c b/tests/tget_set_d64.c index 6f1203dc8..68d0bd1d8 100644 --- a/tests/tget_set_d64.c +++ b/tests/tget_set_d64.c @@ -32,8 +32,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., # define DEC64_MAX 9.999999999999999E384dd #endif -/* #define DEBUG */ - #if _MPFR_IEEE_FLOATS static void print_decimal64 (_Decimal64 d) @@ -389,7 +387,7 @@ main (void) tests_start_mpfr (); mpfr_test_init (); -#ifdef DEBUG +#ifdef MPFR_DEBUG #ifdef DPD_FORMAT printf ("Using DPD format\n"); #else diff --git a/tests/troot.c b/tests/troot.c index 1cc1927bf..947d3267c 100644 --- a/tests/troot.c +++ b/tests/troot.c @@ -457,6 +457,26 @@ cmp_pow (void) mpfr_clears (x, y1, y2, (mpfr_ptr) 0); } +static void +bug20171214 (void) +{ + mpfr_t x, y; + int inex; + + mpfr_init2 (x, 805); + mpfr_init2 (y, 837); + mpfr_set_ui (x, 1, MPFR_RNDN); + inex = TF (y, x, 120, MPFR_RNDN); + MPFR_ASSERTN (inex == 0); + MPFR_ASSERTN (mpfr_cmp_ui (y, 1) == 0); + mpfr_set_si (x, -1, MPFR_RNDN); + inex = TF (y, x, 121, MPFR_RNDN); + MPFR_ASSERTN (inex == 0); + MPFR_ASSERTN (mpfr_cmp_si (y, -1) == 0); + mpfr_clear (x); + mpfr_clear (y); +} + int main (int argc, char *argv[]) { @@ -507,6 +527,7 @@ main (int argc, char *argv[]) tests_start_mpfr (); + bug20171214 (); exact_powers (3, 1000); special (); bigint (); diff --git a/tests/tsub1sp.c b/tests/tsub1sp.c index bda7efe24..7dd2b2239 100644 --- a/tests/tsub1sp.c +++ b/tests/tsub1sp.c @@ -218,6 +218,72 @@ compare_sub_sub1sp (void) } } +static void +bug20171213 (void) +{ + mpfr_t a, b, c; + + mpfr_init2 (a, 127); + mpfr_init2 (b, 127); + mpfr_init2 (c, 127); + mpfr_set_str_binary (b, "0.1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E1"); + mpfr_set_str_binary (c, "0.1000011010111101100101100110101111111001011001010000110000000000000000000000000000000000000000000000000000000000000000000000000E-74"); + mpfr_sub (a, b, c, MPFR_RNDN); + mpfr_set_str_binary (b, "0.1111111111111111111111111111111111111111111111111111111111111111111111111101111001010000100110100110010100000001101001101011110E0"); + MPFR_ASSERTN(mpfr_equal_p (a, b)); + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); +} + +/* generic test for bug20171213: + b = 1.0 with precision p + c = 0.1xxx110...0E-e with precision p, with e >= 1, such that the part 1xxx1 has + exactly p+1-e bits, thus b-c = 0.111..01... is exact on p+1 bits. + Due to the round-to-even rule, b-c should be rounded to 0.111..0. +*/ +static void +bug20171213_gen (mpfr_prec_t pmax) +{ + mpfr_prec_t p; + mpfr_exp_t e; + mpfr_t a, b, c, d; + + for (p = MPFR_PREC_MIN; p <= pmax; p++) + { + for (e = 1; e < p; e++) + { + mpfr_init2 (a, p); + mpfr_init2 (b, p); + mpfr_init2 (c, p); + mpfr_init2 (d, p); + mpfr_set_ui (b, 1, MPFR_RNDN); + mpfr_set_ui_2exp (c, 1, p + 1 - e, MPFR_RNDN); /* c = 2^(p + 1 - e) */ + mpfr_sub_ui (c, c, 1, MPFR_RNDN); /* c = 2^(p + 1 - e) - 1 */ + mpfr_div_2exp (c, c, p + 1, MPFR_RNDN); /* c = 2^(-e) - 2^(-p-1) */ + /* the exact difference is 1 - 2^(-e) + 2^(-p-1) */ + mpfr_sub (a, b, c, MPFR_RNDN); + /* check that a = 1 - 2^(-e) */ + mpfr_set_ui_2exp (d, 1, e, MPFR_RNDN); /* b = 2^e */ + mpfr_sub_ui (d, d, 1, MPFR_RNDN); /* b = 2^e - 1 */ + mpfr_div_2exp (d, d, e, MPFR_RNDN); /* b = 1 - 2^(-e) */ + if (! mpfr_equal_p (a, d)) + { + printf ("bug20171213_gen failed for p=%lu, e=%lu\n", p, e); + printf ("b="); mpfr_dump (b); + printf ("c="); mpfr_dump (c); + printf ("got a="); mpfr_dump (a); + printf ("expected d="); mpfr_dump (d); + exit (1); + } + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); + mpfr_clear (d); + } + } +} + int main (void) { @@ -228,6 +294,8 @@ main (void) compare_sub_sub1sp (); test20170208 (); bug20170109 (); + bug20171213 (); + bug20171213_gen (256); check_special (); for (p = MPFR_PREC_MIN ; p < 200 ; p++) { diff --git a/tests/tsum.c b/tests/tsum.c index f1c814731..9a23849c5 100644 --- a/tests/tsum.c +++ b/tests/tsum.c @@ -937,7 +937,7 @@ cancel (void) rnd = RND_RAND (); -#if DEBUG +#if MPFR_DEBUG printf ("mpfr_sum cancellation test\n"); for (j = 0; j < n; j++) { diff --git a/tools/timings-mpfr.c b/tools/timings-mpfr.c index 02aa89d9a..18eb961ca 100644 --- a/tools/timings-mpfr.c +++ b/tools/timings-mpfr.c @@ -1,6 +1,6 @@ /* timings-mpfr - program to measure the efficiency of GNU MPFR -Copyright 2001, 2010, 2011 Free Software Foundation, Inc. +Copyright 2001-2017 Free Software Foundation, Inc. Copyright 2001 Norbert Mueller (Univ. Trier, Germany). Contributed by the Arenaire and Caramel projects, INRIA. @@ -25,30 +25,15 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include <string.h> #include "gmp.h" #include "mpfr.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined(HPUX) #include <time.h> -int -cputime () +static int +cputime (void) { if (CLOCKS_PER_SEC < 100000) return clock () * 1000 / CLOCKS_PER_SEC; return clock () / (CLOCKS_PER_SEC / 1000); } -#else -#include <sys/types.h> -#include <sys/resource.h> - -static int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#endif int main (int argc, char *argv[]) |