1Copyright 2002-2020 Free Software Foundation, Inc. 2Contributed by the AriC and Caramba projects, INRIA. 3 4This file is part of the GNU MPFR Library. 5 6The GNU MPFR Library is free software; you can redistribute it and/or modify 7it under the terms of the GNU Lesser General Public License as published by 8the Free Software Foundation; either version 3 of the License, or (at your 9option) any later version. 10 11The GNU MPFR Library is distributed in the hope that it will be useful, but 12WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14License for more details. 15 16You should have received a copy of the GNU Lesser General Public License 17along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 18https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 1951 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 20 21 22Notes for the MPFR developers and Subversion users 23================================================== 24 25To compile source code obtained from the Subversion repository, you 26need some GNU development utilities: aclocal, autoheader, automake, 27autoconf 2.60 (at least), libtoolize, and the AX_PTHREAD macro from 28<https://www.gnu.org/software/autoconf-archive/ax_pthread.html> 29(for the latter, under Debian/Ubuntu it suffices to install the 30autoconf-archive package). 31As some files like "configure" are not part of the Subversion 32repository, you first need to run "autoreconf -i" (or ./autogen.sh, 33which could be used later to update the config files). Then you can 34run ./configure in the usual way (see the INSTALL file, but note that 35there are no patches to apply, and the URLs are not valid since the 36corresponding version has not been released yet). 37 38To generate mpfr.info, you need texinfo version 4.2 (or higher). 39 40=========================================================================== 41 42The VERSION file contains the number of the next release version, i.e. 43the version currently being developed. A suffix can be attached for the 44development versions (in general, "-dev") or pre-release versions (e.g. 45"-rc1"). It must be updated with the update-version script. Examples: 46 47 tools/update-version 3 1 0 dev 48 tools/update-version 3 1 0 rc1 49 tools/update-version 3 1 0 50 51The "-dev" suffix means that additional tests may be done or required 52for development. For instance, the data files from the tests/data 53directory are required; such files are not included in tarballs as 54they can be large. 55 56If nightly snapshots are built, the date in the yyyymmdd format and/or 57the Subversion revision number (giving more accurate information) must 58be added to the version as a suffix, for instance: "2.3.0-20070621" or 59"2.3.0-r4553". 60 61Patches can be tracked by adding a chunk of the form 62 63--- PATCHES~ Tue Nov 6 19:59:33 2001 64+++ PATCHES Tue Nov 6 19:59:42 2001 65@@ -1,0 +1 @@ 66+<your-id-here> 67 68to the patch file[*]. After such patches have been applied, the file 69src/get_patches.c providing the mpfr_get_patches() function will be 70rebuilt by "make". MPFR distributors can still modify the version 71suffix from the applied patches according to their version naming 72scheme; for instance, for their own patches, MPFR developers do: 73 74 tools/update-version 3 1 0 p1 - 75 76[*] This idea comes from Thomas Roessler, who implemented it in Mutt. 77 78For patches from MPFR developers, e.g. for MPFR 3.1.0: 791. Unarchive the tarball: a directory mpfr-3.1.0 is created. 802. Go into this directory (cd mpfr-3.1.0). 813. Apply the current patches with "patch -N -Z -p1 < /path/to/allpatches". 824. Reset the PATCHES file with "true >| PATCHES". 835. Rename mpfr-3.1.0 as mpfr-3.1.0-a and duplicate it as mpfr-3.1.0-b 84 without changing the timestamps (e.g. with cp -a). 856. In mpfr-3.1.0-b, apply the patch obtained with "svn diff", e.g. 86 patch --no-backup-if-mismatch -p0 < /path/to/new_patch 87 If an autotools file has been modified, run "autoreconf" and remove 88 the autom4te.cache directory. 897. In mpfr-3.1.0-b, update the version information: 90 tools/update-version 3 1 0 p<n> - 91 where <n> is the patch number. 928. In mpfr-3.1.0-b, update PATCHES file: echo >> PATCHES <patch_name> 939. Make the patch: TZ=UTC0 diff -Naurd mpfr-3.1.0-a mpfr-3.1.0-b 94 95The tools/build-patch script can be used to ease the process. 96 97Note: if autotools files are modified, the corresponding changes in the 98distributed files depending on them must be included in the patch, and 99the timestamps of such autotools files should be reset so that they do 100not change when the patch is applied with the -Z option. Otherwise the 101autotools would be needed to build MPFR (unless maintainer mode is 102disabled). 103 104Patches are put under the misc/www directory of the Subversion repository. 105The web server is updated and patches are also copied as InriaForge files. 106 107=========================================================================== 108 109When submitting patches, unified diffs (option -u) are recommended, 110as they are more readable. You can also use the option -d to generate 111a smaller set of changes. See diff(1) for more information. 112 113=========================================================================== 114 115Copyright Notices: For easier maintainability, make sure that the 116copyright notices match the regexp "Copyright.* yyyy Free Software" 117where yyyy is the year of the latest modification in the branch 118(and nothing else should match it). 119 120The latest rules for GNU software can be found here: 121 122 https://www.gnu.org/prep/maintain/maintain.html#Copyright-Notices 123 124=========================================================================== 125 126To make a release (for the MPFR team): 127 128 *** Please read this section entirely before making any release. *** 129 130 0) For a non-patchlevel release, before creating a branch from the trunk 131 (or more often), some operations should be done: 132 * make sure that the src/mpfr-longlong.h file (from GMP's longlong.h) 133 is up-to-date (updates could also be done in patchlevel releases, 134 but with care); 135 * among the checks below, those that are most likely to notice issues, 136 as it is easy to forget something; 137 * in particular, check that the abi-compliance-checker output, 138 the "API Compatibility" section of the manual (mpfr.texi), and 139 the NEWS file are consistent; 140 * update the libtool version (see src/Makefile.am) and the DLL version 141 (see configure.ac) if need be, though this should have been done as 142 soon as the ABI changed in the trunk; 143 * update the ChangeLog (see below) in the trunk, in order to minimize 144 the future diffs. 145 If everything is OK, create the branch. Then: 146 147 1) Check the version and change the suffix to "rc1", "rc2", etc. with 148 tools/update-version for the release candidates; remove the suffix 149 for the final release. 150 Update the libtool version (see src/Makefile.am), needed at least for 151 patchlevel releases. 152 Update the DLL version (see configure.ac) if not done yet. 153 Check these versions with tools/ck-version-info (this check will also 154 be done automatically by "make dist" / "make distcheck"). 155 Update the date in doc/mpfr.texi. 156 157 2) Generate the tuning parameters on different architectures and 158 put them in src/mparam_h.in. For each architecture: 159 160 a) download the latest release of GMP on gmplib.org 161 b) build GMP with --disable-shared in say /tmp/gmp-x.y.z 162 There is no need in tuning GMP, since most users will build MPFR 163 with a vanilla GMP installation, i.e., with the default GMP tuning; 164 however you need to go into /tmp/gmp-x.y.z/tune and type "make speed" 165 (the MPFR tuning is using the resulting speed library) 166 c) configure MPFR with --disable-shared --with-gmp-build=/tmp/gmp-x.y.z 167 d) go into the "tune" directory and run "make tune" 168 e) put the resulting mparam.h file into mparam_h.in (please include 169 the version of GMP and the compiler used) 170 171 You can produce time graphs to check the thresholds are correct (and 172 compare to the corresponding mpf functions) with mbench. For example 173 (-x1 corresponds to add, -x2 to sub, -x3 to mul, ...): 174 175 $ cd mpfr/tools/mbench 176 $ make mpfr-gfx GMP=... MPFR=... 177 $ ./mpfr-gfx -b16 -e320 -s16 -f2 -x3 # compares mpfr_mul and mpf_mul 178 # from 16 to 320 bits with increment 179 # of 16 bits 180 $ gnuplot -persist plot.gnuplot 181 182 Another example, comparing mpfr_mul and mpf_mul from 2 to 1000000 bits, 183 with ratio 1.1 between two sizes, 10 random values, and 10 smoothness 184 checks: 185 186 $ ./mpfr-gfx -b2 -e1000000 -r1.1 -f10 -x3 -m10 187 $ gnuplot -persist plot.gnuplot 188 189 Check the coverage of each source file by the test suite is at least 90% 190 (or clearly justify any value under this threshold), and publish (for 191 example in NEWS) the global coverage of this release. The individual 192 coverage of each source file might also be published on the release web 193 page. There is a specific mparam.h file to improve coverage; it should 194 be tested by configuring MPFR with -DMPFR_TUNE_COVERAGE. 195 196 Also test with -DMPFR_COV_CHECK, which allows one to check the coverage 197 of some combinations of variable values (as defined in the MPFR source 198 and test suite). 199 200 3) Update the NEWS file, in particular say if the release is binary 201 and/or API compatible (or not) with previous releases. 202 Also update the "API Compatibility" section in the manual (mpfr.texi). 203 Check with abi-compliance-checker (ABI Compliance Checker)[*], on the 204 latest MPFR releases built with no configure options (except --prefix), 205 that no changes have been missed. The ^/misc/build-multi script in the 206 repository may be useful to prepare data for abi-compliance-checker. 207 Note that abi-compliance-checker can only check the symbols, types 208 and constants; it cannot detect just a change in the behavior, thus 209 may miss some incompatibilities. 210 Update the FAQ.html file with update-faq (and check it) in the doc 211 directory. 212 [*] https://lvc.github.io/abi-compliance-checker/ 213 214 4) Update the ChangeLog file with "TZ=UTC0 svn log -rHEAD:0 -v" in 215 UTF-8 locales, e.g. "LC_ALL=en_US.UTF8 TZ=UTC0 svn log -rHEAD:0 -v". 216 This should at least be done last, in order to be complete before the 217 generation of the tarball. 218 Note: First, make sure that all the pending commits have been done. 219 220 5) Do a "svn export" of the branch to make sure to start from a clean 221 source tree; this also has the advantage (over a checkout) to set 222 the timestamps to the commit time, ensuring the right ordering of 223 the files by date. 224 Generate the tarballs with: 225 $ ./autogen.sh 226 $ ./configure 227 $ make distcheck 228 229 6) Test the release version on different machines, with --enable-assert 230 set to "yes", "no" (default), "none" and "full" respectively, with 231 and without -DMPFR_DISABLE_IEEE_FLOATS in $CFLAGS, with and without gmp 232 internal files (--enable-gmp-internals), with and without GMP built as 233 a shared library, with objdir equal to and different from srcdir (e.g. 234 ../mpfr-source/configure after making mpfr-source read-only), with 235 and without --enable-logging. 236 237 Try different temporary allocation methods: GMP's --disable-alloca 238 configure option (or compile GMP with --enable-alloca=debug and MPFR 239 with --with-gmp-build to be able to get the memory leak errors); and 240 -DMPFR_ALLOCA_MAX=0. 241 242 Try different gcc versions with different options: with and without 243 "-std=c99 -O3 -D_XOPEN_SOURCE=500", with and without "-ansi" (which 244 allows to turn off features that are incompatible with ISO C90), 245 with and without [-ansi] -pedantic-errors (which has the effect to 246 disable extensions, such as long long when used together with -ansi), 247 with and without -std=c11, with and without --enable-thread-safe, in 248 various FPU precisions (double, double extended and single) if the 249 platform supports that (e.g. under Linux/x86, with GCC and its -mpc64 250 option to simulate the FreeBSD / NetBSD 6- behavior, where by default, 251 the x87 FPU is configured to round on 53 bits), and in various locales 252 (LC_ALL=tr_TR in particular, if installed). 253 On x86, test with -m96bit-long-double and -m128bit-long-double. 254 Try also with gcc's -fno-common option. 255 Check also with "-Wformat=2", but without logging support (in order 256 to avoid too many spurious warnings). 257 Check with "-UHAVE_BIG_ENDIAN -UHAVE_LITTLE_ENDIAN" to simulate 258 platforms where the endianness is unknown (or can't be specified 259 without AC_CONFIG_HEADERS). 260 Check also without the mpz_t pool (-DMPFR_POOL_NENTRIES=0). 261 Check the generic code, e.g. with -DMPFR_GENERIC_ABI in $CFLAGS 262 (useful because most tests are written for low precision) and with 263 mpfr_cv_c_long_double_format=unknown (as a variable assignment). 264 Check with -DMPFR_GROUP_STATIC_SIZE=0 to detect memory leaks that would 265 occur in medium precision or more if a MPFR_GROUP_CLEAR were forgotten. 266 267 Check that make and make check pass with a C++ compiler, for example: 268 ./configure CC=g++ (MPFR 2.3.2 did not). 269 Also test --enable-gmp-internals with it. 270 271 Try different compilers, e.g., icc, opencc (x86_64 machines), 272 tcc <https://bellard.org/tcc/>, llvm-gcc, clang. 273 274 On 64-bit PowerPC, test against GMP built with the different ABI's: 275 32, mode32 and mode64 (in particular mode32, where long's have 276 32 bits and limbs have 64 bits [long long]). 277 278 Test with -DMPFR_TESTS_FPE_DIV -DMPFR_ERRDIVZERO 279 -DMPFR_DISABLE_IEEE_FLOATS in order 280 to detect whether tests can fail due to a FP division by 0 (yielding 281 either FE_DIVBYZERO, e.g. from 1.0 / 0.0 to generate an infinity, or 282 FE_INVALID, e.g. from 0.0 / 0.0 to generate a NaN) on platforms where 283 such an operation fails (e.g. trap). On platforms that do not support 284 IEEE 754, such an operation yields an undefined behavior. 285 If _MPFR_IEEE_FLOATS is defined to 1 (by the configure script), some 286 divisions by 0 are avoided in the MPFR library. 287 The -DMPFR_DISABLE_IEEE_FLOATS option sets _MPFR_IEEE_FLOATS to 0, 288 allowing one to detect more issues, for platforms without IEEE floats. 289 290 Test with -D_MPFR_PREC_FORMAT=2 when the "int" type is smaller 291 than the "long" type. 292 293 Test with mini-gmp. 294 295 Test with valgrind by setting the environment variable: 296 LOG_COMPILER="valgrind -q --error-exitcode=1 --leak-check=full" 297 See below for more information about valgrind. 298 299 Test with "clang -fsanitize=undefined" (available as of Clang 3.3), 300 e.g.: ./configure CC=clang CFLAGS='-fsanitize=undefined' 301 The -fno-sanitize-recover option can give more visibility by making 302 the corresponding tests fail (useful for automated tests). However 303 clang unconditionally regards the floating-point division by zero 304 as an error with "-fsanitize=undefined"; this is detected by a 305 configure test, which sets MPFR_ERRDIVZERO to disable the tests 306 involving a floating-point division by zero. Alternatively, on systems 307 supporting IEC 60559 / IEEE 754 division by zero, one can also provide 308 the -fno-sanitize=float-cast-overflow,float-divide-by-zero option 309 *after* the -fsanitize=undefined one. 310 311 GCC 4.9 also supports "-fsanitize=undefined", but it just gives 312 diagnostic messages at run time, not a failure; GCC 5 supports 313 -fno-sanitize-recover like clang. 314 315 Test with GCC's AddressSanitizer (-fsanitize=address). Optimizations 316 should not be enabled, otherwise they can make some errors disappear. 317 One also needs to unset LD_PRELOAD or use -static-libasan to avoid 318 failures. But the -static-libasan solution does not work with MPFR, 319 as it yields the following error: 320 Your application is linked against incompatible ASan runtimes. 321 322 Test with i686-w64-mingw32 under Wine (see below). 323 324 Test with both "make check" and the worst cases. 325 326 Check various warnings, in particular for obsolescent features. 327 With GCC: "-Wall -Wold-style-declaration -Wold-style-definition 328 -Wmissing-parameter-type -Wmissing-prototypes -Wmissing-declarations 329 -Wmissing-field-initializers". The -Wint-in-bool-context option 330 could be added once available. These warnings can easily be checked 331 in automatic tests by adding "-Werror -Wno-error=unused-function", 332 but this needs: 333 * GCC 4.9+ 334 * a patched autoconf: 335 https://lists.gnu.org/archive/html/autoconf-patches/2014-01/msg00003.html 336 337 Check whether some functions could be declared as pure, const, etc. 338 with GCC, using -Wsuggest-attribute=... options. 339 340 Check that there are no abnormal regressions in the timings (both for 341 100, 1000, 10000 digits, https://www.mpfr.org/mpfr-current/timings.html, 342 and for small precision, using the mbench program, see mpfr/mbench). 343 344 Test the library interface compatibility by running the test suite 345 compiled against an old library version and dynamically linked with 346 the new library version: for instance, build the shared library of 347 old and new MPFR versions with the same configure options, and from 348 the build directory of the old version, do something like: 349 (cd src/.libs && \ 350 ln -nsf ../../../mpfr-new/src/.libs/libmpfr.so.1.* libmpfr.so.1) 351 then "make check". 352 353 Also test with different environment variables set 354 (GMP_CHECK_RANDOMIZE, MPFR_CHECK_LIBC_PRINTF, MPFR_CHECK_LARGEMEM, 355 MPFR_CHECK_EXPENSIVE, MPFR_SUSPICIOUS_OVERFLOW, MPFR_CHECK_LOCALES, 356 MPFR_CHECK_BADCASES). 357 358 Check there is no branch misprediction due to wrong MPFR_LIKELY or 359 MPFR_UNLIKELY statements. For that test, configure with 360 --enable-debug-prediction, run "timings-mpfr 100", and check that 361 the output contains no WARNING. 362 363 For various platforms and compilers, check that: 364 * [make check-gmp-symbols] 365 MPFR does not use GMP internal symbols (unless --with-gmp-build 366 or --enable-gmp-internals has been used); 367 * [make check-exported-symbols] 368 MPFR does not define symbols with a GMP reserved prefix. 369 But note that these rules are not really portable: they may do 370 nothing or might even incorrectly fail on some platforms. 371 372 7) For the release itself (not the release candidates), if no problems 373 have been found, create a tag with: 374 svn cp .../mpfr/branches/x.y .../mpfr/tags/x.y.z 375 376 8) For the release itself (not the release candidates), update 377 the version with the update-version script to indicate the 378 next version (use the "dev" suffix). 379 380 9) * For the release itself (not the release candidates): 381 Create a web page for the MPFR release and add the documentation 382 (for mpfr.html, use "makeinfo --html --no-split mpfr.texi" from 383 the doc directory). Make sure that both the .dvi and .ps files 384 have an a4 papersize (see technical information later about the 385 MPFR manual). 386 Upload the tarballs and the signatures to the MPFR web server 387 (via a svn working copy) and to InriaForge. 388 Prepare the files for the GNU FTP site with the gnu-sigdir script 389 in the /misc directory and upload them. 390 Update the mpfr-current symbolic link and the history page. 391 Update the old current page to point to the new release; see 392 examples for 3.0.1 (latest version of the branch) and 3.1.0 393 (which is not the latest version of the branch). 394 Run the tools/announce-text script to do some checking and get 395 the announce text. Edit this text if need be. 396 Announce the release in the mpfr-announce, mpfr, gmp-discuss, gcc 397 and info-gnu[1] mailing-lists, and on InriaForge (MPFR News, and 398 contact the InriaForge administrators[2] to have the announce 399 published on the main page). 400 In case of a new patchlevel release, add a link from the web page 401 of the previous release. 402 403 * For the release candidates: Announce the RC in the mpfr-announce, 404 mpfr, gmp-discuss, gcc and platform-testers[3] mailing-lists. 405 A minimal web page for the MPFR release can be created right now 406 (see svn history such as [4] for examples), as the manual already 407 contains the new URL's. 408 409 [1] https://www.gnu.org/prep/maintain/html_node/Announcements.html 410 [2] http://siteadmin.gforge.inria.fr/FAQ.html 411 [3] See https://lists.gnu.org/mailman/listinfo/platform-testers and 412 https://lists.gnu.org/archive/html/platform-testers/2011-09/msg00000.html 413 [4] https://gforge.inria.fr/scm/viewvc.php/misc/www/mpfr-3.1.2/index.html?view=markup&revision=8472&root=mpfr 414 415Note: Mail sent to the mpfr-announce list should also be sent to 416the mpfr list, and the Reply-To should be set to the mpfr list. 417 418For major or minor releases (but not patchlevels), a branch may be 419created first to allow new features to be committed to the trunk. 420 421To add tcc support with libtool 2.4.2 or below, do the following before 422running "make distcheck": 423$ patch m4/libtool.m4 libtool-tcc-wl.patch 424$ autoreconf 425 426And for libtool 2.4.3 to 2.4.6, the following is needed: 427$ patch m4/libtool.m4 libtool-tcc-rpath.patch 428$ autoreconf 429 430=========================================================================== 431 432Here is a non-exhaustive list of macros used for building and checking MPFR. 433Most of them are automatically set up by the configure script and its options. 434 435List of macros used for building MPFR (also used for checking): 436 437+ HAVE_CONFIG_H: Define if we have to include 'config.h' first. 438+ MPFR_HAVE_GMP_IMPL: Define if we have the gmp internal files. 439 ('gmp-impl.h', 'gmp-maparam.h', ...). 440+ MPFR_USE_MINI_GMP: Define to use mini-gmp. 441 442+ HAVE_ALLOCA: Define if alloca() works. 443+ HAVE_ALLOCA_H: Define if the function alloca() is in alloca.h. 444+ HAVE_LOCALE_H: Define if <locale.h> is available. 445+ HAVE_LONG_LONG: Define if the system supports 'long long'. 446 447+ HAVE_STDARG: Define if the system supports 'stdarg.h'. 448 Otherwise it is assumed it is 'vararg.h'. 449 450+ HAVE_INTTYPES_H: Define if <inttypes.h> is available (ISO C99). 451+ HAVE_STDINT_H: Define if <stdint.h> is available (ISO C99). 452+ MPFR_HAVE_INTMAX_MAX: Define if the INTMAX_MAX macro works correctly 453 (if 'intmax_t' is supported). 454 455+ MPFR_HAVE_C11_LOCK: Define if C11 threads are supported. 456+ HAVE_PTHREAD: Define if pthread is available. 457 458Format of long double. 459+ HAVE_LDOUBLE_IS_DOUBLE: IEEE double. 460+ HAVE_LDOUBLE_IEEE_EXT_BIG: IEEE extended, big endian. 461+ HAVE_LDOUBLE_IEEE_EXT_LITTLE: IEEE extended, little endian. 462+ HAVE_LDOUBLE_IEEE_QUAD_BIG: IEEE quad, big endian. 463+ HAVE_LDOUBLE_IEEE_QUAD_LITTLE: IEEE quad, little endian. 464+ HAVE_LDOUBLE_MAYBE_DOUBLE_DOUBLE: Double-double (a.k.a. IBM). 465 466+ MPFR_DISABLE_IEEE_FLOATS: 467 Related to the native floating-point types (e.g. 468 for conversion functions), use the generic code 469 instead of IEEE 754 specific one. 470 Note: This is mainly for developers in order to 471 check the generic code, as machines without IEEE 472 floating-point types are very uncommon nowadays. 473+ MPFR_WANT_ASSERT: Assertion level. See src/mpfr-impl.h for details. 474+ MPFR_EXP_CHECK: Define if we want to check the exp field. 475 476+ _MPFR_PREC_FORMAT: Used to define the mpfr_prec_t type. 477+ _MPFR_EXP_FORMAT: Used to define the mpfr_exp_t type. 478 Note: these two macros are for internal use, 479 testing and experimented users only; they must 480 not be changed when the MPFR library is to be 481 installed in a system directory. 482 483+ IEEE_DBL_MANT_DIG: Number of bits in the significand (mantissa) of a 484 double (default: 53). 485+ MPFR_LDBL_MANT_DIG: Number of bits in the significand (mantissa) of a 486 long double (generally based on the standard macro 487 LDBL_MANT_DIG). Note: be careful with formats such 488 as double-double (a.k.a. IBM long double). 489 490+ MPFR_USE_LOGGING: Define to enable logging. 491 492+ MPFR_WANT_DECIMAL_FLOATS: 493 Define to build conversion functions from/to 494 decimal floats. At most one of the following 495 three macros can be defined. 496+ DECIMAL_BID_FORMAT: BID encoding detected or assumed. 497+ DECIMAL_DPD_FORMAT: DPD encoding detected or assumed. 498+ DECIMAL_GENERIC_CODE: Use generic code for decimal floats. 499 500+ MPFR_WANT_FLOAT128: Define to build conversion functions from/to 501 binary128 floats (_Float128 or __float128). 502 503+ MPFR_ALLOCA_MAX: Maximum size for the use of alloca() by temporary 504 allocations (default: 16384); if set to 0, alloca() 505 will not be used, and not even referenced. 506 This macro is not used when MPFR is built with 507 the GMP build directory (--with-gmp-build). 508 509+ MPFR_USE_THREAD_SAFE: Define to build MPFR as thread safe (TLS). 510+ MPFR_USE_C11_THREAD_SAFE: 511 Define to implement TLS in the C11 way. 512 513+ MPFR_WANT_SHARED_CACHE: 514 Define to have caches shared by all threads. 515+ MPFR_THREAD_LOCK_METHOD: 516 When MPFR_WANT_SHARED_CACHE is defined, this macro 517 gives the thread locking method (string). 518 519+ MPFR_HAVE_NORETURN: Define if the _Noreturn function specifier is 520 supported. 521+ MPFR_HAVE_BUILTIN_UNREACHABLE: 522 Define if the __builtin_unreachable GCC built-in is 523 supported. 524 525+ MPFR_GENERIC_ABI: Define to disable code that is tied to a specific 526 ABI (e.g. GMP_NUMB_BITS value). 527 Note: Currently it is also used to disable code 528 specific to low precision, i.e. to use only generic 529 code. This is useful because most tests are written 530 for low precision, meaning that without this macro, 531 the generic code would not sufficiently be tested. 532 533+ MPFR_WANT_PROVEN_CODE: 534 Define to enable formally proven code. 535 536List of macros used for checking MPFR: 537 538+ MPFR_HAVE_FESETROUND: Define if the function fesetround() is available 539 (and in header <fenv.h>). 540+ MPFR_FPU_PREC: Allows to test MPFR on x86 processors when the 541 x87 FPU rounding precision has been changed (see 542 tests/tests.c for its usage). 543+ HAVE_SUBNORM_DBL: Define if the double type fully supports subnormals. 544+ HAVE_SUBNORM_FLT: Define if the float type fully supports subnormals. 545+ HAVE_SIGNEDZ: Define if signed zeros are supported. 546+ HAVE_SYS_TIME_H: Define if the header sys/time.h is usable. 547+ HAVE_GETTIMEOFDAY: Define if the function gettimeofday() is available. 548+ HAVE_SETLOCALE: Define if the function setlocale() is available. 549+ MPFR_ERRDIVZERO: Define if the floating-point division by 0 fails 550 in the MPFR library (e.g., because a SIGFPE signal 551 is generated, or because it is regarded as undefined 552 behavior by a sanitizer). This disables the tests 553 involving such operations. 554 Note: Tests related to NaN and infinities must not 555 rely on native FP division by 0, whether this macro 556 is defined or not. 557+ MPFR_TESTS_FPE_DIV: Define to check whether there has been a FP 558 exception FE_DIVBYZERO or FE_INVALID, which 559 probably comes from 1.0 / 0.0 or 0.0 / 0.0 to 560 generate an infinity or a NaN. This is normally 561 used together with MPFR_ERRDIVZERO, in order to 562 check that all divisions by 0 have been protected 563 in the tests (so that tests can pass on platforms 564 where the floating-point division by 0 fails). 565+ MPFR_TESTS_FPE_TRAP: Define to trap the FE_DIVBYZERO and FE_INVALID 566 exceptions; MPFR_TESTS_FPE_DIV needs to be defined 567 too, and MPFR_ERRDIVZERO should be defined as well 568 to avoid spurious traps (see above). 569+ MPFR_TESTS_TIMEOUT: Define to enable timeout in the tests. Its value 570 specifies the default timeout (in seconds), or 0 571 for no timeout by default. When defined, this 572 value can be overridden at run time (e.g., with 573 "make check" or when executing an individual test) 574 with the MPFR_TESTS_TIMEOUT environment variable. 575+ MPFR_TESTS_ABORT: Define to replace exit(1) by abort(), thus with a 576 core dump. 577+ MPFR_COV_CHECK: Define to enable value coverage checking (must not 578 be used in production). This macro is for the MPFR 579 developers, in order to improve the test suite. 580 581=========================================================================== 582 583Environment variables that affect the tests: 584 585+ GMP_CHECK_RANDOMIZE: Seed for the random functions, except for 0 or 1, 586 in which case a random (time based) seed is used. 587 By default, a fixed seed is used. Only developers 588 and testers should change the seed. 589 590+ MPFR_CHECK_LARGEMEM: Define to enable tests that take a lot of memory. 591 592+ MPFR_CHECK_EXPENSIVE: Define to enable tests that take a lot of time. 593 Warning! The --enable-assert=full option should 594 not be used, otherwise this can take much too 595 long. While checking assertions (--enable-assert) 596 may be useful with MPFR_CHECK_EXPENSIVE, the 597 --enable-assert=full is not necessary with it. 598 599+ MPFR_CHECK_LIBC_PRINTF: 600 Define to enable comparisons with the printf 601 function of the C library. These comparisons are 602 disabled by default as failures could be due to 603 the C library itself on some machines, and they 604 do not affect MPFR. 605 606+ MPFR_CHECK_LOCALES: Fail in case a locale cannot be set. Developers 607 can set this variable on their machines to make 608 sure that needed locales are properly installed 609 and tested. 610 611+ MPFR_CHECK_BADCASES: Fail if function bad_cases generates too many 612 cases for which f(f^{-1}(x)) ≠ x, due to a poor 613 choice of the parameters. 614 615+ MPFR_DEBUG_BADCASES: For debugging (see tests.c, function bad_cases). 616 617+ MPFR_SUSPICIOUS_OVERFLOW: 618 Define to check suspicious overflow in the generic 619 tests (tgeneric.c). For developers and testers. 620 621+ MPFR_TESTS_MEMORY_LIMIT: 622 The memory limit for the tests (default is 623 2^22 = 4 MB). Set to 0 for unlimited. 624 625+ MPFR_TESTS_TIMEOUT: When timeout in the tests is enabled, this 626 overrides the value of the macro. 627 628=========================================================================== 629 630Before testing any macro in a .c file, one needs: 631 632#ifdef HAVE_CONFIG_H 633# include "config.h" 634#endif 635 636except if mpfr-impl.h (for the library) or mpfr-test.h (for the tests) is 637included first, because these header files already have the above code. 638 639=========================================================================== 640 641The GNU Coding standards can be read at: 642 https://www.gnu.org/prep/standards/ 643 644ISO C Names and corresponding headers: 645 http://www.schweikhardt.net/identifiers.html 646 647The C language: 648 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf (C99) 649 http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf 650 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf (C11 draft) 651 http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html 652 653About undefined behavior: 654 https://blog.regehr.org/archives/213 655 https://blog.regehr.org/archives/226 656 https://blog.regehr.org/archives/232 657 https://blog.regehr.org/archives/1520 658 http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html 659 660Type punning, strict aliasing, and optimization: 661 https://blog.regehr.org/archives/959 662 663To allow MPFR to be built on some buggy compiler, try to follow 664these rules: 665 666 ===================================================================== 667 668Don't write: 669 mp_limb_t l; 670 [...] 671 if (l) do_action (); 672But: 673 mp_limb_t l; 674 [...] 675 if (l != 0) do_action (); 676 677since mp_limb_t may be "unsigned long long", and some buggy compiler 678produce illegal codes with the first form. 679 680 ===================================================================== 681 682Try to avoid "LONG_MIN/1" since it produces a SIGNAL on (old) FreeBsd. 683Don't forget that LONG_MIN/-1 is not representable (specially 684with code like MPFR_EXP_MIN/n). 685 686 ===================================================================== 687 688Don't use "near" and "far" as variable names since they are "Keywords" 689for some C compiler (Old DOS compiler). Also don't use "pm", which is used 690by the C compiler 'sharp' to design variables that should be stored in the 691flash memory. Don't use "new", which is reserved in C++. 692 693Check C++ reserved keywords, e.g. from 694 695 https://en.cppreference.com/w/cpp/keyword 696 697or more generally: 698 699 https://www.google.com/search?q=%22C%2B%2B%22+reserved+keywords 700 701Quoted from <https://www.gnu.org/software/gcc/codingconventions.html>: 702 703 Avoid the use of identifiers or idioms that would prevent code 704 compiling with a C++ compiler. Identifiers such as new or class, 705 that are reserved words in C++, should not be used as variables 706 or field names. Explicit casts should be used to convert between 707 void* and other pointer types. 708 709When a string literal ("...") is followed by a macro name, there 710must be white space between them, otherwise this is parsed as a 711user-defined string literal in C++11: 712 713 https://en.cppreference.com/w/cpp/language/user_literal 714 https://stackoverflow.com/a/6402166/3782797 715 716In at least mpfr.h, use the underscore version of the attribute names 717(e.g. "__sentinel__" instead of "sentinel"), otherwise user code could 718fail to compile with GCC when it defines macros such as "sentinel" 719(before the #include's or via the -D command-line option). See 720 721 https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html 722 723 ===================================================================== 724 725Setting errno is safe to signal some error information (as in the 726formatted output functions), but errno must not be read (unless we 727have just modified it) as this may yield undefined behavior in some 728corner cases out of our control (ISO C99 / C11, 7.14.1.1p5, also 729mentioned in J.2). 730 731 ===================================================================== 732 733C-Reduce may be useful to try to identify whether a bug comes from the 734compiler. 735 736 ===================================================================== 737 738About type conversions: 739 740To do type punning (i.e. store a value of some type and reinterpret 741it as another type), use a union. This is valid in ISO C99 and above 742(in C99, see 6.5#7 and Note 82 of 6.5.2.3#3 for the clarification), 743but not in C++. So, users of a C++ compilers should make sure that 744their compiler supports type punning via a union. If some problem is 745reported, we should address it either by making the code compatible 746or by adding a configure test to reject the compiler. 747 748Some references: 749* https://en.wikipedia.org/wiki/Type_punning#Use_of_union 750* https://stackoverflow.com/questions/346622/opinions-on-type-punning-in-c 751 "Opinions on type-punning in C++?" 752 753Do not do conversions between function pointers and other kinds of 754pointers (including to void *). This yields undefined behavior and 755may not work in practice. Example: 756 757 https://stackoverflow.com/questions/5579835/c-function-pointer-casting-to-void-pointer 758 759Adding a level of indirection is OK, as suggested there, and on: 760 761 https://stackoverflow.com/questions/36645660/why-cant-i-cast-a-function-pointer-to-void 762 763 ===================================================================== 764 765For floating-point constants, do not use the non-standard and useless 766suffix "D". It seems to mean "double" for GCC[*], but for instance, 767ICC 15 regards 1.0D as 0 (though ICC claims compatibility with GCC) 768and for tcc 0.9.27, this is an error. The standard suffixes from TS 18661-2 769are: 770 771 f l F L df dd dl DF DD DL 772 773Moreover, avoid native floating-point if possible. Be careful that GCC 774does not conform to the C standard by default. References: 775 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 776 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85957 777 778[*] https://stackoverflow.com/questions/4331200/what-do-f-and-d-mean-at-the-end-of-numeric-literals 779 780=========================================================================== 781 782Avoid variable names "l", "I" and "O", which look like "1" and "0" with 783some fonts. 784 785=========================================================================== 786 787For identifiers defined in MPFR, do not use the GMP namespaces 788(gmp_..., GMP_...). 789 790=========================================================================== 791 792You are allowed to use the mpn and mpz classes of GMP functions (types 793and functions starting with "mpn_" and "mpz_"). However, except for some 794conversion functions where they may be needed, 795 * the mpq class and GMP's formatted output and input functions (i.e., 796 printf and scanf style) can only be used in an alternative method 797 by testing MPFR_USE_MINI_GMP (and only if there is a real benefit), 798 since they are not available in mini-gmp; 799 * the mpf class must not be used at all. 800 801=========================================================================== 802 803The headers <limits.h>, <stdio.h>, <stdlib.h> and <string.h> are always 804included in mpfr-impl.h; thus you need not (and should not) include them 805in usual source and test files. 806 807=========================================================================== 808 809For files that need intmax_t or similar, use: 810 811#if HAVE_INTTYPES_H 812# include <inttypes.h> 813#endif 814#if HAVE_STDINT_H 815# include <stdint.h> 816#endif 817 818Note that even though the ISO C99 standard requires that <inttypes.h> 819include <stdint.h>, in practice this is not true on all platforms, 820such as OSF/1 (Tru64) 5.1. This is consistent with autoconf, which 821has used this form since 2004-01-26 (in headers.m4). 822 823References: 824 https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=62ac9bbfebe879581dabeed78c6ac66b907dd51d 825 https://sympa.inria.fr/sympa/arc/mpfr/2010-08/msg00015.html 826 827=========================================================================== 828 829Use locale-dependent functions when the result needs to depend on the 830locales, e.g. the decimal-point character in mpfr_out_str. 831 832Conversely, do not use locale-dependent functions when the result must 833not depend on the locales. In particular, the alphanumeric characters 834used in number strings (as created by mpfr_get_str) must be those of 835the required characters from the basic character set (see ISO C99 836standard Section 5.2.1 "Character sets"). And tolower(letter) does 837not necessarily return the corresponding lowercase letter from these 838required characters. For instance, tolower('I') returns a dotless 'i' 839in Turkish tr_TR.iso88599 locales. 840 841=========================================================================== 842 843If you have to mix TMP_DECL and MPFR_SAVE_EXPO_DECL in the declaring 844section of your function, please declare MPFR_SAVE_EXPO_DECL before 845TMP_DECL, since TMP_DECL may be replace by nothing: 846 847Instead of: Usually preprocessed as: 848 unsigned long t unsigned long t; 849 TMP_DECL (marker); ; 850 MPFR_SAVE_EXPO_DECL (expo); mpfr_save_expo_t expo; 851use: 852 unsigned long t unsigned long t; 853 MPFR_SAVE_EXPO_DECL (expo); mpfr_save_expo_t expo; 854 TMP_DECL (marker); ; 855 856=========================================================================== 857 858Memory allocation 859----------------- 860 861Do not use TMP_DECL / TMP_ALLOC, ... but MPFR_TMP_DECL, MPFR_TMP_ALLOC, ... 862 863In the tests, use only tests_allocate, tests_reallocate and tests_free 864(there may be some rare exceptions, such as in tabort_defalloc*.c). 865 866Avoid code that would yield unnecessary reallocations, which can be very 867expensive. In particular, for code that is based on the mpz layer of GMP, 868do not use mpz_init, but mpz_init2 with the estimated maximum size; it is 869better to overestimate this size a bit than underestimating it. 870 871=========================================================================== 872 873Do not use C99-only features, such as empty macro arguments or C++-style 874comments. 875 876=========================================================================== 877 878When testing a "boolean" macro M (i.e. which is normally either equal 879to 1 or undefined), do not use #if M, but #ifdef M or #if defined(M). 880With icc, the form #if M triggers a warning ("remark #193: zero used 881for undefined preprocessing identifier"). 882 883=========================================================================== 884 885If you want to use the logging of MPFR, you need to enable it: 886 make distclean 887 ./configure --enable-logging 888 make 889Then link your program with this new build of MPFR. 890 891Warning! The logging code for functions sometimes output an "inexact" 892value, but in case of exception, this value may be meaningless. In 893fact, the output value is the value of some variable; please check 894the source code of the function to understand its real meaning. 895 896You can control what is logged using the environment variables: 897 898MPFR_LOG_FILE: Name of the LOG file (default: mpfr.log). 899MPFR_LOG_FLUSH: When this variable is set, flush the log stream after 900 each log output (useful to get the latest logs in case 901 of crash, but this makes logging slower). 902MPFR_LOG_PREC: Number of digits of the output (set the internal variable 903 mpfr_log_prec, default: 6). 904MPFR_LOG_LEVEL: Max recursive level (default: 7). 905 906MPFR_LOG_INPUT: Log the input 907MPFR_LOG_OUTPUT: Log the output 908MPFR_LOG_TIME: Log the time spent inside the function. 909MPFR_LOG_INTERNAL: Log the intermediary variables if any. 910MPFR_LOG_MSG: Log the messages sent by MPFR if any. 911MPFR_LOG_ZIV: Log what the Ziv Loops do. 912MPFR_LOG_STAT: Log how many times Ziv failed. 913MPFR_LOG_ALL: Log everything 914 915Define them. Run your program, and view `mpfr.log`. 916 917For example, just define MPFR_LOG_ALL, run you program, and view `mpfr.log`. 918 919Note: The running time may be much longer. If logging is used on the 920test suite with a default timeout, it may be necessary to increase the 921timeout time by setting the environment variable MPFR_TESTS_TIMEOUT 922to the new timeout value in seconds (or 0 to disable the timeout). 923 924=========================================================================== 925 926This feature is available only for gcc >= 3.0 and glibc >= 2.0. 927To achieve this, these macros have been added: 928 929+++ MPFR_LOG_VAR(y) 930 Log a MPFR variable if requested (INTERNAL). 931 Example: 932 mpfr_t y; 933 MPFR_LOG_VAR (y); 934 935+++ MPFR_LOG_MSG(x) 936 Log another message (a warning for example) 937Example: 938 MPFR_LOG_MSG (("WARNING: Unchecked code\n", 0)); 939The 0 is here a dummy value, because there must be at least an argument 940after the format string. 941 942+++ MPFR_LOG_BEGIN(x) 943 Add this macro at the beginning of a function. 944Example: 945 int dodo (mpfr_t x, mpfr_t op, int cnt, mpfr_rnd_t rnd) { 946 [decl] 947 MPFR_LOG_BEGIN (("op[%Pu]=%.*Rg rnd=%s", 948 mpfr_get_prec(op), mpfr_log_prec, op, RND2STR(rnd))); 949 950+++ MPFR_LOG_END(x) 951 Add this macro at the end of a function. 952Example: 953 MPFR_LOG_END (("x[%Pu]=%.*Rg i=%d", mpfr_get_prec (x), mpfr_log_prec, x, i)); 954 return i; 955} 956 957+++ MPFR_LOG_FUNC (begin,end) 958 Add this macro at the beginning of a function. It does 959the same job as MPFR_LOG_BEGIN and MPFR_LOG_END but it is smatter 960since it intercepts the return itself to put the end statement. 961Example 962 MPFR_LOG_FUNC ( 963 ("op[%Pu]=%.*Rg rnd=%d", op, mpfr_get_prec (op), mpfr_log_prec, op), 964 ("x[%Pu]=%.*Rg inexact=%d", mpfr_get_prec (x), mpfr_log_prec, x, i)); 965 966 967The double brackets "((" and "))" are needed since MPFR must still 968compile with non GNU compiler, so Macros with variable # of args 969are not allowed. 970 971It uses the extension of the mpfr_printf function: %Rf to display a mpfr_t. 972%Ru is used to display the precision of a mpfr_t. 973It uses some extended attributes of GCC (constructor, etc.) to achieve 974its goals too. 975 976=========================================================================== 977 978ZivLoop Controller 979 980Ziv strategy is quite used in MPFR. In order to factorize the code, you 981could use these macros: 982 983+++ MPFR_ZIV_DECL(_x) 984 Declare a ZivLoop controller 985 986+++ MPFR_ZIV_INIT(_x, _prec) 987 Init a ZivLoop controller according to the initial value of _prec. 988 989+++ MPFR_ZIV_NEXT(_x, _prec) 990 Increase the precision _prec according to the ZivLoop controller. 991 992+++ MPFR_ZIV_FREE(_x) 993 Free the ZivLoop controller. 994 995=========================================================================== 996 997If you plan to add a new function, you could follow this schema: 998 999int 1000mpfr_toto (mpfr_ptr rop, mpfr_srcptr op, mpfr_rnd_t rnd) 1001{ 1002 [Declare all used variables] 1003 int inexact; 1004 mpfr_prec_t prec; 1005 MPFR_ZIV_DECL (loop); 1006 MPFR_SAVE_EXPO_DECL (expo); 1007 1008 /* Log it if requested */ 1009 MPFR_LOG_BEGIN 1010 (("op[%Pu]=%.*Rg rnd=%d", mpfr_get_prec (op), mpfr_log_prec, op, rnd), 1011 ("rop[%Pu]=%.*Rg inexact=%d", 1012 mpfr_get_prec (rop), mpfr_log_prec, rop, inexact)); 1013 1014 /* First deal with particular cases */ 1015 if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (op))) 1016 { 1017 if (MPFR_IS_NAN (op)) 1018 { 1019 MPFR_SET_NAN (rop); 1020 MPFR_RET_NAN; 1021 } 1022 else if (MPFR_IS_INF (op)) 1023 { 1024 [Code to deal with Infinity] 1025 } 1026 else 1027 { 1028 MPFR_ASSERTD (MPFR_IS_ZERO (op)); 1029 [Code to deal with Zero] 1030 } 1031 } 1032 [Other particular case: For example, op<0 or op == 1] 1033 1034 [Compute the first estimation of the used precision `prec`] 1035 [Initialize the intermediate variables using mpfr_init2] 1036 MPFR_SAVE_EXPO_MARK (expo); /* Maximal range for exponent */ 1037 1038 MPFR_ZIV_INIT (loop, prec); /* Initialize the ZivLoop controller */ 1039 for (;;) /* Infinite loop */ 1040 { 1041 [Compute an estimation of the function and] 1042 [an estimate of the error.] 1043 if (MPFR_CAN_ROUND (...)) /* If we can round, quit the loop */ 1044 break; 1045 MPFR_ZIV_NEXT (loop, prec); /* Increase used precision */ 1046 [Use `mpfr_set_prec` to resize all needed intermediate variables] 1047 } 1048 MPFR_ZIV_FREE (loop); /* Free the ZivLoop Controller */ 1049 1050 inexact = mpfr_set (rop, temp, rnd); /* Set rop to the computed value */ 1051 [Clear all intermediate variables] 1052 1053 MPFR_SAVE_EXPO_FREE (expo); /* Restore exponent range */ 1054 return mpfr_check_range (rop, inexact, rnd); /* Check range and quit */ 1055} 1056 1057Make sure that Ziv loops cannot increase the precision forever because of 1058internal exception. Otherwise one gets either a segmentation fault (with 1059limited stack size) or an assertion failure (with unlimited stack size, 1060e.g. with "make check"). 1061 1062Do not use code with side effects inside MPFR_ASSERTD or MPFR_ASSERTN, 1063as assertion checking can be disabled. If a variable is set only to test 1064it in an MPFR_ASSERTD expression, the MPFR_DBGRES macro should be used 1065with the assignment as its argument, e.g. 1066 int inex; 1067 MPFR_DBGRES (inex = mpfr_set (y, x, rnd)); 1068 MPFR_ASSERTD (inex == 0); 1069 1070Exception handling (overflow/underflow in particular): 1071 * Warning: To detect exceptions and/or possible error loss due to 1072 internal exceptions, testing whether some variable is singular with 1073 MPFR_IS_SINGULAR is generally not sufficient! Indeed, in case of 1074 overflow (resp. underflow), the value may be rounded (in absolute 1075 value) to the largest finite number (resp. to the smallest non-zero 1076 number, possible even in round-to-nearest mode). 1077 * The MPFR_BLOCK* macros can be useful, e.g. 1078 { 1079 MPFR_BLOCK_DECL (flags); 1080 /* ... */ 1081 MPFR_BLOCK (flags, /* expression or statements */) 1082 /* ... */ 1083 if (MPFR_OVERFLOW (flags)) 1084 { /* case of overflow in expression or statements */ } 1085 /* ... */ 1086 } 1087 See mpfr-impl.h (search for MPFR_BLOCK) for more information. 1088 1089=========================================================================== 1090 1091If you plan to add a new threshold in MPFR which could be tuned, 1092you should add its default value in the file `mparam_h.in'. When the 1093script configure finishes, it creates the file `mparam.h' from `mparam_h.in'. 1094 1095Then you needs to modify the program `tuneup.c' to allow it to compute 1096the new threshold. If it is a classical threshold (not complex), you could 1097use this method (example of mpfr_exp): 1098 1099/* Define the threshold as a variable instead of a constant */ 1100mpfr_prec_t mpfr_exp_threshold; 1101#undef MPFR_EXP_THRESHOLD 1102#define MPFR_EXP_THRESHOLD mpfr_exp_threshold 1103/* Include the test function to threshold directly in the test 1104 program. It will override the mpfr_exp coming from libmpfr.a */ 1105#include "exp.c" 1106/* Define the speed function related to mpfr_exp */ 1107static double speed_mpfr_exp (struct speed_params *s) { 1108 SPEED_MPFR_FUNC (mpfr_exp); 1109} 1110 1111Then in the function `all', you will have to call the tune function, 1112and write the new THRESHOLD in the file `mparam.h': 1113 1114 /* Tune mpfr_exp */ 1115 if (verbose) 1116 printf ("Tuning mpfr_exp...\n"); 1117 tune_simple_func (&mpfr_exp_threshold, speed_mpfr_exp); 1118 fprintf (f, "#define MPFR_EXP_THRESHOLD %lu\n", 1119 (unsigned long) mpfr_exp_threshold); 1120 1121More complex tuning is possible but needs special attention. 1122 1123=========================================================================== 1124 1125MPFR uses many macros, thus finding where an error occurs exactly may 1126be difficult when it is in some macro expansion. For GCC users, a new 1127experimental -ftrack-macro-expansion option has been added in GCC 4.7. 1128"It allows the compiler to emit diagnostic about the current macro 1129expansion stack when a compilation error occurs in a macro expansion." 1130<https://gcc.gnu.org/gcc-4.7/changes.html> 1131 1132=========================================================================== 1133 1134Bit Twiddling Hacks - Sean Eron Anderson maintain a list of tricks to get 1135efficient code on <https://graphics.stanford.edu/~seander/bithacks.html>. 1136WARNING: some of those tricks may not take into account possible overflows, 1137and may not be portable. 1138 1139=========================================================================== 1140 1141MPFR manual (mpfr.texi): 1142 * Use "significand", not "mantissa". 1143 * Use "decimal-point character" (as in ISO C) when the meaning is 1144 the corresponding character ("." or ",", depending on the locale), 1145 not "decimal point", "decimal separator", "fractional point", or 1146 "radix point" (the latter is fine in certain contexts). This is 1147 just the name of this character (as initially defined for base 10) 1148 and does not imply a number written in decimal. 1149 * Use "@minus{}" for the minus character, not "-". 1150 * Warning! Texinfo is not like TeX. Whitespace is preserved in the 1151 info file. So, do not use additional space for .texi indentation. 1152 This also means that you need to care about the typography. Please 1153 read Section "Inserting Space" in the Texinfo manual. 1154 * Follow the English typography (no space before punctuation marks, 1155 double space after a period, etc.), not the French one. 1156 1157The MPFR manual in DVI/PS/PDF formats should have an a4 papersize, as 1158declared in mpfr.texi (@afourpaper command). The DVI file format (.dvi) 1159traditionally does not contain papersize information, which has two 1160consequences: 1161 * When viewing a .dvi file, one gets the papersize from global settings, 1162 which may differ from the papersize declared in the mpfr.texi file. 1163 In particular, a4 text on letter paper can be truncated, depending on 1164 the margins. 1165 * Since the .ps file is built from the .dvi file and makeinfo does not 1166 provide the papersize information to the dvips command, the .ps file 1167 can get a wrong papersize, depending on the settings on the machine 1168 where this file is generated. Papersize information should be checked 1169 before distributing the .ps file. 1170Nowadays, .dvi files can contain papersize information via "specials", 1171and texinfo.tex has been updated to include such information. However, 1172the interpretation of such data is based on a common agreement between 1173drivers rather on a standard. In short, the papersize issues should no 1174longer appear, but this should be checked manually. The bug report: 1175https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874632 1176 1177=========================================================================== 1178 1179Running "make" outputs a lot of information, and warnings are not very 1180visible. The following tool "eet" allows a copy of warning messages to 1181be output to a different window (e.g. xterm or zenity): 1182 1183 https://www.vinc17.net/unix/#eet 1184 1185Direct link to the tarball: https://www.vinc17.net/unix/eet.tar.xz 1186 1187=========================================================================== 1188 1189Be careful when avoiding "'var' may be used uninitialized in this function" 1190warnings from gcc. Initializing such variables to a dummy value has several 1191drawbacks: 1192 * this may prevent other tools (that do static or dynamic analysis) from 1193 detecting bugs; 1194 * this makes code maintenance more difficult (e.g. when modifying the 1195 code, one may more easily forget a real initialization); 1196 * this makes the compiler add useless code (though this should not be 1197 significant). 1198 1199The INITIALIZED macro can be used to avoid such warnings with gcc, e.g. 1200 1201 int INITIALIZED(i); 1202 1203It uses the "int i = i;" pseudo-initialization trick, disabled with other 1204compilers as this is undefined behavior. See: 1205 1206 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36296 1207 1208If a dummy initialization must be added, use preferably an "invalid" value 1209(e.g. NULL for pointers, or a value that can be checked with MPFR_ASSERTN 1210before using it) that could make the program abort instead of returning an 1211incorrect value in case of a bug in MPFR. 1212 1213=========================================================================== 1214 1215Avoid mixing signed and unsigned integer types, as this can lead signed 1216types to be automatically converted into unsigned types (usual arithmetic 1217conversions). If such a signed type contains a negative value, the result 1218may be incorrect on some platforms. With MPFR 2.x, this problem could 1219arise with mpfr_exp_t, which is signed, and mpfr_prec_t (mp_prec_t), 1220which was unsigned (it is now signed), meaning that in general, a cast 1221of a mpfr_prec_t to a mpfr_exp_t was needed. 1222 1223Note that such bugs are difficult to detect because they may depend on 1224the platform (e.g., on LP64, 32-bit unsigned int + 64-bit long will give 1225a signed type, but on ILP32, 32-bit int + 32-bit unsigned long will give 1226an unsigned type, which may not be what is expected), but also on the 1227input values. So, do not rely on tests very much. However, if a test 1228works on 32 bits but fails on 64 bits in the extended exponent range 1229(or conversely), the cause may be related to the integer types (e.g. a 1230signness problem or an integer overflow due to different type sizes). 1231 1232For instance, in MPFR, such issues were fixed in r1992 and r5588. 1233 1234An example that will fail with 32-bit int and long: 1235 1236 long long umd(void) 1237 { 1238 long a = 1; 1239 unsigned int b = 2; 1240 return a - b; 1241 } 1242 1243When creating a new variable that will always contain nonnegative values, 1244it is generally better to define it as a signed type if it may be used in 1245an arithmetic expression. The exceptions are when the value is seen as an 1246array of bits (e.g. for limbs) and to temporarily avoid integer overflow. 1247 1248=========================================================================== 1249 1250To use features related to types larger than type long, "mpfr-intmax.h" 1251must be included before "mpfr-impl.h". 1252 1253The intmax_t and uintmax_t types can be used only if _MPFR_H_HAVE_INTMAX_T 1254is defined. In this case, the printf / gmp_printf length specifier "j" can 1255be used only when NPRINTF_J is not defined. 1256 1257For internal use, mpfr-intmax.h also unconditionally defines mpfr_intmax_t, 1258mpfr_uintmax_t, MPFR_UINTMAX_MAX, MPFR_INTMAX_MAX, MPFR_INTMAX_MIN and 1259the corresponding length specifier MPFR_INTMAX_FSPEC. 1260 1261Warning! mpfr_intmax_t may be smaller than intmax_t if NPRINTF_J is defined. 1262 1263=========================================================================== 1264 1265Use mpfr_prec_t and mpfr_rnd_t instead of the old types mp_prec_t and 1266mp_rnd_t. Similarly, use mpfr_exp_t instead of GMP's mp_exp_t type 1267(unless you really want mp_exp_t, e.g. for conversions with mpf; but 1268you must not assume that mpfr_exp_t and mp_exp_t are identical). 1269 1270=========================================================================== 1271 1272How to specify (for reading) the minimum exponent or the maximum exponent 1273in the MPFR source depends on the context. 1274 12751. The most portable form is mpfr_get_emin() and mpfr_get_emax(). In 1276 the MPFR source, this is equivalent to __gmpfr_emin and __gmpfr_emax 1277 respectively (macros are defined in mpfr-impl.h; the only difference 1278 is that the macros do not evaluate to a lvalue). 1279 12802. If the exponent range has been extended, you can use the constants 1281 MPFR_EMIN_MIN and MPFR_EMAX_MAX instead. This will be faster if TLS 1282 is enabled. It also avoids a bug on some Linux/Sparc machines with 1283 some GCC versions and TLS, but this shouldn't be the primary concern, 1284 as this might be the other way round on some other machines. This is 1285 the most common context. 1286 12873. If you want the minimum and maximum possible exponent values supported 1288 by MPFR, use MPFR_EMIN_MIN and MPFR_EMAX_MAX respectively. 1289 12904. If you want the minimum and maximum values supported by the mpfr_exp_t 1291 type (i.e. the limits of this type), use MPFR_EXP_MIN and MPFR_EXP_MAX 1292 respectively. This may be useful for intermediate computations on the 1293 exponents. 1294 1295More on exponent handling: 1296 1297* The mpfr_exp_t type has at least 32 bits since it must contain the 1298 default exponent range. 1299 1300* The range of valid exponents is defined so that if a and b are two 1301 valid exponents (i.e. between MPFR_EMIN_MIN and MPFR_EMAX_MAX), then 1302 ± a ± b ± 1 fits in a mpfr_exp_t. 1303 1304* The unsigned type corresponding to mpfr_exp_t is mpfr_uexp_t. It may be 1305 useful if the considered values are nonnegative and don't necessarily 1306 fit in mpfr_exp_t. To convert a nonnegative mpfr_exp_t to mpfr_uexp_t, 1307 you should use the MPFR_UEXP macro, which is defined as: 1308 #define MPFR_UEXP(X) (MPFR_ASSERTD ((X) >= 0), (mpfr_uexp_t) (X)) 1309 1310* If a mpfr_exp_t appears in arithmetic expressions together with ISO C90 1311 types int and/or long, computations must be done with the largest type, 1312 which is provided by mpfr_eexp_t. 1313 1314* If a mpfr_exp_t needs to be converted from or to a MPFR number, the 1315 mpfr_set_exp_t or mpfr_get_exp_t macro should be used. 1316 1317* If a mpfr_exp_t needs to be converted into a character string with a 1318 formatted output function (fprintf, printf, sprintf), the mpfr_eexp_t 1319 type should be used, together with the MPFR_EXP_FSPEC specifier, e.g. 1320 1321 printf ("%" MPFR_EXP_FSPEC "d", (mpfr_eexp_t) exponent); 1322 1323For implementation details, see the mpfr.h and mpfr-impl.h files. 1324 1325=========================================================================== 1326 1327Be careful that the ternary value (a.k.a. "inexact") is not guaranteed 1328to be -1, 0, or 1, in general (for some functions, the exact value may 1329contain other information, such as midpoint cases with MPFR_EVEN_INEX), 1330and the exact behavior may change in the future. So, it is not correct 1331to multiply ternary values returned by arbitrary functions as this may 1332overflow. 1333 1334To work with ternary values, mpfr-impl.h provides the following macros: 1335 1336#define SIGN(I) ((I) < 0 ? -1 : (I) > 0) 1337#define SAME_SIGN(I1,I2) (SIGN (I1) == SIGN (I2)) 1338 1339=========================================================================== 1340 1341Because of a bug in the Mac OS X 10.5 linker, avoid tentative definitions 1342(C99, 6.9.2). Depending on the context, use either a simple declaration 1343(with the "extern" storage-class specifier) or an external definition. 1344This is also cleaner. 1345 1346=========================================================================== 1347 1348In case of detected internal error, do not use printf() and exit(). 1349Use assertions (MPFR_ASSERTN) instead. 1350 1351=========================================================================== 1352 1353When using GNU extensions (based on the value of the __GNUC_* macros), check 1354whether they work with ICC. The following paper can give useful information: 1355"Intel® Compilers for Linux*: Compatibility with GNU Compilers" at 1356<https://software.intel.com/articles/intel-compilers-for-linux-compatibility-with-gnu-compilers>. 1357 1358To detect compilers, see 1359 1360 https://sourceforge.net/p/predef/wiki/Compilers/ 1361 1362=========================================================================== 1363 1364For configure tests, use AC_LINK_IFELSE rather than AC_COMPILE_IFELSE, 1365which is broken by design. The reason is that some errors just produce 1366a warning (which is not a bug from the compiler: in ISO C terminology, 1367this corresponds to a diagnostic, and the compilation is allowed to 1368succeed), and this is unfixable in a portable way. 1369 1370=========================================================================== 1371 1372Shell portability 1373----------------- 1374 1375Shell commands (in /bin/sh scripts, in Makefile and autotools related 1376files...) need to be valid in POSIX shells, but also in Bourne shells 1377(for instance, /bin/sh under Solaris is a Bourne shell). 1378 1379In particular: 1380 1381* Do not use $(...) but `...` (backticks). 1382 1383* Be careful that quote nesting with backticks such as "`cmd "$foo"`" 1384 is not portable: 1385 1386 https://unix.stackexchange.com/q/387246/74516 1387 ("quotes inside backticks inside quotes in ksh") 1388 1389 But the external quotes are not needed when assigning to a variable: 1390 1391 out=`cmd "$foo"` 1392 1393 Otherwise one can write "`cmd \"$foo\"`". 1394 1395=========================================================================== 1396 1397For developers - Use of the svn:eol-style Subversion property 1398 1399The svn:eol-style Subversion property is traditionally set to "native" on 1400text files, but this has drawbacks: 1401 * On systems where the end-of-line (EOL) sequence is not LF, the obtained 1402 files are different from those from the tarballs. This makes maintenance 1403 harder. 1404 * Some tools under Windows (such as makeinfo of MinGW/MSYS) don't support 1405 the MS-Windows EOL sequence CRLF, and the MPFR build fails. 1406 1407For these reasons, the svn:eol-style Subversion property should never be set 1408to "native". 1409 1410=========================================================================== 1411 1412About the test suite 1413-------------------- 1414 1415When adding a test file for a new function (say mpfr_func), you can use 1416the following prototype tfunc.c (to put in the directory 'tests'). 1417This file performs random tests for values of x between -5 and 5, with 1418a precision varying from 2 to 100. 1419 1420You can add your own tests to this basic file. When adding the expected 1421result, do NOT use the one obtained from the MPFR function! Otherwise, 1422if this function is buggy, the test will be wrong and the function will 1423remain buggy. For random tests, avoid mpfr_urandomb as its values are 1424not truly random due to how it is specified (if the exponent is less 1425than 0, some of the trailing bits will necessarily be 0). 1426 1427Do not forget to add 'tfunc' in the variable check_PROGRAMS 1428of the tests/Makefile.am file. 1429 1430/* Test file for mpfr_func. 1431 1432Copyright 2020 Free Software Foundation, Inc. 1433Contributed by the AriC and Caramba projects, INRIA. 1434 1435This file is part of the GNU MPFR Library. 1436 1437The GNU MPFR Library is free software; you can redistribute it and/or modify 1438it under the terms of the GNU Lesser General Public License as published by 1439the Free Software Foundation; either version 3 of the License, or (at your 1440option) any later version. 1441 1442The GNU MPFR Library is distributed in the hope that it will be useful, but 1443WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 1444or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 1445License for more details. 1446 1447You should have received a copy of the GNU Lesser General Public License 1448along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 1449https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 145051 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 1451 1452#include "mpfr-test.h" 1453 1454#define TEST_FUNCTION mpfr_func 1455#define TEST_RANDOM_EMIN -5 1456#define TEST_RANDOM_EMAX 5 1457#include "tgeneric.c" 1458 1459int 1460main (int argc, char *argv[]) 1461{ 1462 tests_start_mpfr (); 1463 1464 test_generic (2, 100, 100); 1465 1466 tests_end_mpfr (); 1467 return 0; 1468} 1469 1470 --------------------------------------------------------------------- 1471 1472Here is how the test suite works since the full Automake 1.13 support 1473(merge of the vl-am113 branch in r8821). 1474 1475The tests_start_mpfr function, which should be called at the beginning 1476of each test program (unless nothing is tested and main() just contains 1477"return 77;"), starts by calling the test_version function, whose goal 1478is to do various header/library version checks of GMP and MPFR. In case 1479of mismatch between a header and a library, an error message is output 1480("make check" will redirect it to a log file). Then there are 3 cases: 1481 14821. An error in the MPFR version check is a fatal error: test_version() 1483 exits with an error (exit status = 1). The reason is that a different 1484 MPFR library (somewhere in some library search path) would probably 1485 be tested, so that the results of the test would be meaningless. 1486 14872. An error in the GMP version check is a non-fatal error: if there are 1488 no errors in MPFR version check, test_version() returns with value 1. 1489 However the tversion test program will regard this as a fatal error 1490 (thus "make check" will fail). The probable reason of the mismatch is 1491 that the GMP library has been upgraded while the MPFR test suite has 1492 not been rebuilt; otherwise there is probably something wrong in the 1493 GMP installation. 1494 14953. Otherwise test_version() returns with value 0 (everything is fine). 1496 1497Note: The tests_start_mpfr function does a setbuf on stdout to disable 1498buffering. As a consequence, no operations on stdout (such as printf) 1499must be done before this function is called. 1500 1501With Automake 1.13+, the tests are run in parallel if a -j make option 1502is used. In case of failure, information can be found in the log file 1503of each failed test program and in the global tests/test-suite.log file 1504(which is output automatically if the VERBOSE environment variable is 1505set to 1). If no tests fail, then the tests/tversion.log file is output 1506after the "testsuite summary"; it contains various useful information 1507about the MPFR build. 1508 1509To use a wrapper to run the tests, such as valgrind or wine, define 1510LOG_COMPILER, e.g.: 1511 LOG_COMPILER="valgrind -q --error-exitcode=1 --leak-check=full" make check 1512 LOG_COMPILER=wine make check 1513 1514More information about the parallel test harness: 1515https://www.gnu.org/software/automake/manual/automake.html#Parallel-Test-Harness 1516 1517 --------------------------------------------------------------------- 1518 1519In the tests, do not use `mpfr_set_d` (except when testing it), as the 1520result will depend on the floating-point arithmetic of the system; 1521this has shown many problems in the past and problems may still occur 1522with new systems. Use `mpfr_set_si` or `mpfr_set_str` instead. 1523 1524To check the result of some function, use mpfr_equal_p rather than 1525mpfr_cmp, as mpfr_cmp will return 0 (equality) if the result is NaN. 1526 1527Do not use functions that need optional features (except in a context 1528where such features are required). For instance, the mpfr_printf-like 1529functions need <stdarg.h> (HAVE_STDARG defined), thus should not be 1530used, except for testing them. 1531 1532For temporary result files created by test programs, choose a unique 1533filename to avoid conflicts in parallel tests. To ensure that, the 1534filename should start with the name of the test program (for instance, 1535"tfprintf_out.txt" for tfprintf.c). Add the filename to CLEANFILES in 1536the tests/Makefile.am file. 1537 1538Also, make sure that the tests run against previous MPFR versions, 1539possibly by disabling some tests with code like 1540 1541 #if MPFR_VERSION >= MPFR_VERSION_NUM(2,3,0) 1542 1543Indeed one can now easily run the trunk tests in a branch by executing 1544 1545 svn switch .../svn/mpfr/trunk/tests tests 1546 1547from the working copy. One can know when the tests directory has been 1548switched, thanks to 1549 1550 $ svn status 1551 S tests 1552 1553In case of failure, freeing the memory explicitly is not necessary. 1554We do this in case of success just to be able to detect memory leaks 1555in MPFR. 1556 1557 --------------------------------------------------------------------- 1558 1559To check the coverage of the test suite, you can use gcov. 1560To get accurate information, do not enable optimizations. 1561 1562 ./configure CFLAGS="--coverage" 1563 make clean 1564 make check 1565 find . -name '*.c' -exec gcov '{}' ';' | grep "lines executed" | sort 1566 1567For each source file, there is a .c.gcov file which contains much more 1568information. 1569 1570Another solution is to run the script 'coverage' within the 'tools' directory. 1571 1572 --------------------------------------------------------------------- 1573 1574To run the MPFR test suite under valgrind, you may need to do several 1575things. 1576 1577First, as the running time is much longer than usual, you should not use 1578the --enable-tests-timeout configure option, or set the timeout value to 1579a large value; this can be done at run time, e.g. with 1580 1581 export MPFR_TESTS_TIMEOUT=0 1582 1583to disable the timeout, so that you do not need to rebuild MPFR for 1584this purpose. 1585 1586Then just set the LOG_COMPILER environment variable to something like 1587 1588 valgrind -q --error-exitcode=1 --leak-check=full 1589 1590before running "make check", or type directly: 1591 1592 LOG_COMPILER="valgrind -q --error-exitcode=1 --leak-check=full" make check 1593 1594NOTE: with the new tests/Makefile.am file, the following is obsolete; 1595but it might still be useful under some occasions, e.g. if all the 1596valgrind output needs to be sent to a single file. 1597 1598Before running valgrind, you should run "make check" a first time so 1599that everything is compiled out of valgrind. 1600 1601Then you need the --trace-children=yes valgrind option (a possible 1602exception is when you run an individual test that has been built 1603statically). The reason is that libtool generates wrapper scripts 1604to link the tests against the right libraries. The drawback is that 1605you will get valgrind output for all the processes, including the 1606shell commands from the wrapper scripts (the --trace-children-skip 1607valgrind option will not allow you to filter every unwanted process). 1608But you can filter the output with: 1609 1610 sed -n '/= Command: [^ ]*\/\.libs\/lt-/,/= ERROR SUMMARY:/p' 1611 1612For readability, you should redirect the valgrind output to a file. 1613You can use --log-file, but due to --trace-children=yes, you need 1614the %p format specifier in the filename argument to generate a file 1615for each child; however many files will be generated, and it may be 1616better to use the following method to get a single file: 1617 1618 valgrind --trace-children=yes --log-fd=3 make check 3> vg.out 1619 1620then 1621 1622 sed -n '/= Command: [^ ]*\/\.libs\/lt-/,/= ERROR SUMMARY:/p' vg.out 1623 1624to get only the valgrind output corresponding to the MPFR tests. 1625 1626Or if your shell supports it, you can use a process substitution 1627to filter the valgrind output directly to a file, e.g. with bash 1628or zsh: 1629 1630 valgrind --trace-children=yes --log-fd=3 make check 3> >(sed -n \ 1631 '/= Command: [^ ]*\/\.libs\/lt-/,/= ERROR SUMMARY:/p' > vg.out) 1632 1633if you do not mind about the buffering delays. 1634 1635 --------------------------------------------------------------------- 1636 1637NOTE: with "AM_LDFLAGS = -no-install" in tests/Makefile.am, the following 1638is obsolete, as libtool no longer generates wrapper scripts; but it is left 1639here in case negative effects of "AM_LDFLAGS = -no-install" are seen or for 1640users with a special setup. 1641 1642To debug some test program, e.g. tadd, with gdb, you cannot run "gdb tadd" 1643since libtool has generated a wrapper script to link the program against 1644the correct MPFR library. Instead, run: 1645 1646 libtool --mode=execute gdb tadd 1647 1648Alternatively, something like 1649 1650 LD_PRELOAD=../src/.libs/libmpfr.so gdb .libs/tadd 1651 1652may also work (example for GNU/Linux). 1653 1654Note: for test programs not listed in Makefile.am (check_PROGRAMS), 1655libtool is not used (a static link against MPFR is done via LOADLIBES 1656in Makefile.am), so that gdb should be used in the conventional way. 1657You can use the following wrapper script to have a command that works 1658with both: 1659 1660------------------------------------------------------------ 1661#!/bin/sh 1662 1663unset cmd 1664case $1 in 1665 -*) ;; 1666 ?*) test "x$(head -c 2 "$1")" = 'x#!' && \ 1667 grep -q "^# Generated by libtool" "$1" && \ 1668 cmd="libtool --mode=execute" ;; 1669esac 1670 1671exec $cmd gdb "$@" 1672------------------------------------------------------------ 1673 1674and 1675 1676 alias gdb='/path/to/the/wrapper/script' 1677 1678=========================================================================== 1679 1680To cross-compile MPFR for i686-w64-mingw32 and test it under Wine: 1681 16820. Install wine (at least the 32-bit version). 1683 16841. Build and install GMP. 1685 1686In the GMP source directory: 1687$ ./configure --host=i686-w64-mingw32 --disable-shared --prefix=... 1688$ make 1689$ make check LOG_COMPILER=wine 1690$ make install 1691 1692Note: The -D__USE_MINGW_ANSI_STDIO option may be necessary in order to get 1693an ISO-compliant printf as mentioned in MPFR's INSTALL file. In this case, 1694add CC="i686-w64-mingw32-gcc -D__USE_MINGW_ANSI_STDIO" at the end of the 1695configure line. Otherwise MPFR needs to be configured with 1696 "CPPFLAGS=-DNPRINTF_J -DNPRINTF_L -DNPRINTF_T" 1697But with recent versions of the tools, printf now seems to be ISO-compliant 1698by default. The __USE_MINGW_ANSI_STDIO macro is now internal to MinGW and 1699should no longer be used. 1700 17012. Build and check MPFR. 1702 1703In the MPFR source directory: 1704$ ./configure --host=i686-w64-mingw32 --disable-shared --with-gmp=... 1705$ make 1706$ make check LOG_COMPILER=wine 1707 1708Note: Due to bugs in autoconf[1] and dash[2], the configure script 1709may create files with a binary filename or have any other arbitrary 1710behavior if /bin/sh is dash. The cause is that it tries to execute 1711a MS Windows executable, which is interpreted as a shell script by 1712dash (thus with random, meaningless commands). This will confuse 1713Subversion, and these files need to be removed manually. 1714 1715[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=850329 1716[2] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=816313 1717 1718=========================================================================== 1719 1720After a MPFR build, the list of GMP symbols used by this particular MPFR 1721build can be obtained as follows: 1722 1723 nm -u src/.libs/libmpfr.so | sed -n 's/^ *U \(__gmp.*\)/\1/p' 1724 1725at least under Linux, the library name and the "nm" behavior being 1726non-portable (adding the POSIX "-P" option may help, but there are 1727still differences between platforms). 1728 1729Note that this list may depend on various parameters, such as the 1730architecture and the compilation options. 1731 1732GMP internal symbols used by MPFR can be detected with the following 1733shell command (just replace /path/to/gmp.h by the actual pathname): 1734 1735nm -u src/.libs/libmpfr.so | sed -n 's/^ *U \(__gmp.*\)/\1/p' | \ 1736while read s 1737do 1738 case $s in 1739 __gmpn_*) regex="__MPN(${s#__gmpn_})" ;; 1740 *) regex="$s" ;; 1741 esac 1742 grep -q "^#define .* ${regex}$" /path/to/gmp.h || echo "Internal: $s" 1743done 1744 1745A similar check can be done with "make check-gmp-symbols". 1746 1747One can also check that MPFR does not define exported symbols with a 1748prefix outside "mpfr_" and "__gmpfr_" by using "nm -g" and filtering 1749at least the "U" lines. But this can only be a manual check to avoid 1750false positives. Checking that a GMP reserved prefix is not used can 1751be done automatically, as with "make check-exported-symbols". 1752 1753=========================================================================== 1754 1755To update the FAQ, checkout the misc directory of the repository root. 1756Modify the faq.xhtml file and run 1757 1758 xsltproc --nodtdattr faq-web.xsl faq.xhtml > www/faq.html 1759 1760Check with "svn diff" that this change has been done correctly (in case 1761of incorrect installation of XML tools), validate the files with 1762 1763 xmllint --noout --loaddtd --valid faq.xhtml www/faq.html 1764 1765and if everything is OK (no error messages), commit both files. 1766 1767Update the FAQ.html file with update-faq in the doc directory of the 1768MPFR trunk and supported branches. 1769 1770=========================================================================== 1771 1772Spelling: 1773 * Some suggestions: https://gcc.gnu.org/codingconventions.html#Spelling 1774 * Check with "codespell" (done by mpfrlint). 1775