FAQ.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <!--
  4. Copyright 2000-2016 Free Software Foundation, Inc.
  5. Contributed by the AriC and Caramba projects, INRIA.
  6. This file is part of the GNU MPFR Library.
  7. The GNU MPFR Library is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or (at your
  10. option) any later version.
  11. The GNU MPFR Library is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  14. License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
  17. http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
  18. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  19. -->
  20. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  21. <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  22. <title>Frequently Asked Questions about GNU MPFR</title>
  23. <style type="text/css">/*<![CDATA[*/
  24. /* Global stylesheet for visual media */
  25. html, body
  26. {
  27. background: white;
  28. color: black;
  29. }
  30. div.logo { float: right }
  31. div.logo img { border: 0 }
  32. div.footer img { border: 0 }
  33. dt
  34. {
  35. margin-top: 2ex;
  36. margin-bottom: 1ex;
  37. font-weight: bolder;
  38. }
  39. /* For testing: dd { background: #ddddff } */
  40. table { margin: 0.5ex auto }
  41. li { margin-top: 0.5ex; margin-bottom: 0.5ex }
  42. dd + dd
  43. {
  44. margin-top: 0;
  45. margin-bottom: 0;
  46. padding-top: 0.5ex;
  47. padding-bottom: 0;
  48. }
  49. li > p, dd > p
  50. {
  51. margin-top: 0;
  52. margin-bottom: 0;
  53. padding-top: 0.5ex;
  54. padding-bottom: 0.5ex;
  55. }
  56. .block-code code, code.block-code,
  57. .block-code samp, samp.block-code
  58. {
  59. display: block;
  60. padding: 0.5ex 0;
  61. margin-left: 2em;
  62. }
  63. .nowrap { white-space: nowrap }
  64. /*
  65. dl.faq { counter-reset: faq }
  66. dl.faq dt:before
  67. {
  68. counter-increment: faq;
  69. content: counter(faq) ". ";
  70. }
  71. */
  72. dl.faq dt { background: #dddddd }
  73. dl.faq dd
  74. {
  75. border-left: 4px solid;
  76. border-color: transparent;
  77. margin-left: 0em;
  78. padding-left: 1.5em;
  79. }
  80. dl.faq dt:target + dd
  81. {
  82. border-left-color: #aaaaaa;
  83. }
  84. var.env { font-style: normal }
  85. /*]]>*/</style>
  86. </head>
  87. <body>
  88. <h1>Frequently Asked Questions about <cite><acronym>GNU</acronym> <acronym>MPFR</acronym></cite></h1>
  89. <p><strong>Important notice: Problems with a particular version of
  90. <cite><acronym>MPFR</acronym></cite> are discussed in the corresponding
  91. bugs page.</strong></p>
  92. <p>The latest version of this <acronym>FAQ</acronym> is available at
  93. <a href="http://www.mpfr.org/faq.html">http://www.mpfr.org/faq.html</a>.
  94. Please look at this version if possible.</p>
  95. <ol>
  96. <li><a href="#mpfr_vs_mpf">What are the differences between
  97. <cite><acronym>MPF</acronym></cite> from <cite><acronym>GMP</acronym></cite>
  98. and <cite><acronym>MPFR</acronym></cite>?</a></li>
  99. <li><a href="#mpf2mpfr">How to convert my program written using
  100. <cite><acronym>MPF</acronym></cite> to
  101. <cite><acronym>MPFR</acronym></cite>?</a></li>
  102. <li><a href="#no_libgmp">At configure time, I get the error: <q>libgmp not found or uses a different ABI.</q></a></li>
  103. <li><a href="#undef_ref1">I get undefined reference to <code>__gmp_get_memory_functions</code>.</a></li>
  104. <li><a href="#undef_ref2">When I link my program with
  105. <cite><acronym>MPFR</acronym></cite>, I get undefined reference
  106. to <code>__gmpXXXX</code>.</a></li>
  107. <li><a href="#crash_high_prec">My program crashes with high precisions.</a></li>
  108. <li><a href="#accuracy">Though I have increased the precision, the results
  109. are not more accurate.</a></li>
  110. <li><a href="#detect_mpfr">How can I detect <cite><acronym>MPFR</acronym></cite>
  111. installation using <cite>autoconf</cite> or <cite>pkg-config</cite>?</a></li>
  112. <li><a href="#cite">How to cite <cite><acronym>MPFR</acronym></cite> in a
  113. scientific publication?</a></li>
  114. <li><a href="#fpic">When I build <cite><acronym>MPFR</acronym></cite>, I get
  115. an error asking me to recompile with <samp>-fPIC</samp>.</a></li>
  116. </ol>
  117. <dl class="faq">
  118. <dt id="mpfr_vs_mpf">1. What are the differences between
  119. <cite><acronym>MPF</acronym></cite> from <cite><acronym>GMP</acronym></cite>
  120. and <cite><acronym>MPFR</acronym></cite>?</dt>
  121. <dd><p>The main differences are:</p>
  122. <ul>
  123. <li><p>The precision of a <cite><acronym>MPFR</acronym></cite> variable
  124. is the <em>exact</em> number of bits used for its mantissa, whereas in
  125. <cite><acronym>MPF</acronym></cite>, the precision requested by the user
  126. is a minimum value (<cite><acronym>MPF</acronym></cite> generally uses a
  127. higher precision). With the additional difference below, this implies that
  128. the <cite><acronym>MPFR</acronym></cite> results do not depend on the
  129. number of bits (16, 32, 64 or more) of the underlying architecture.</p></li>
  130. <li><p>As a consequence, <cite><acronym>MPFR</acronym></cite> uses a
  131. base-2 exponent, whereas in <cite><acronym>MPF</acronym></cite>, this
  132. is a base-2<sup>32</sup> or base-2<sup>64</sup> exponent, depending on
  133. the limb size. For this reason (and other internal ones), the maximum
  134. exponent range in <cite><acronym>MPFR</acronym></cite> is different
  135. (and smaller, if the exponent is represented by the same type as in
  136. <cite><acronym>MPF</acronym></cite>).</p></li>
  137. <li><p><cite><acronym>MPFR</acronym></cite> provides an additional rounding
  138. mode argument to its functions; furthermore, it is guaranteed that the
  139. result of any operation is the nearest possible floating-point value from
  140. the exact result (considering the input variables as exact values), taking
  141. into account the precision of the destination variable and the rounding
  142. mode. <cite><acronym>MPFR</acronym></cite> also says whether the rounded
  143. result is above or below the exact result.</p></li>
  144. <li><p><cite><acronym>MPFR</acronym></cite> supports much more functions
  145. (in particular transcendental functions such as exponentials, logarithms,
  146. trigonometric functions and so on) and special values: signed zeros,
  147. infinities, not-a-number (NaN).</p></li>
  148. </ul></dd>
  149. <dt id="mpf2mpfr">2. How to convert my program written using
  150. <cite><acronym>MPF</acronym></cite> to
  151. <cite><acronym>MPFR</acronym></cite>?</dt>
  152. <dd><p>You need to add <q><code>r</code></q> to the function names, and to
  153. specify the rounding mode (<code>MPFR_RNDN</code> for rounding to nearest,
  154. <code>MPFR_RNDZ</code> for rounding toward zero, <code>MPFR_RNDU</code>
  155. for rounding toward plus infinity, <code>MPFR_RNDD</code> for rounding
  156. toward minus infinity). You can also define macros as follows:
  157. <code class="block-code">#define mpf_add(a, b, c) mpfr_add(a, b, c, MPFR_RNDN)</code></p>
  158. <p>The header file <samp>mpf2mpfr.h</samp> from the
  159. <cite><acronym>MPFR</acronym></cite> distribution automatically
  160. redefines all <cite><acronym>MPF</acronym></cite> functions in this
  161. way, using the default <cite><acronym>MPFR</acronym></cite> rounding
  162. mode. Thus you simply need to add the following line in all your files
  163. using <cite><acronym>MPF</acronym></cite> functions:
  164. <code class="block-code">#include &lt;mpf2mpfr.h&gt;</code>
  165. just after the <samp>gmp.h</samp> and <samp>mpfr.h</samp>
  166. header files. If the program uses <cite><acronym>MPF</acronym></cite>
  167. internals (such as direct access to <code>__mpf_struct</code> members),
  168. additional changes will be needed.</p></dd>
  169. <dt id="no_libgmp">3. At configure time, I get the error: <q>libgmp not found or uses a different ABI.</q></dt>
  170. <dd><p>This test (<samp>checking for __gmpz_init in -lgmp</samp>) comes
  171. after the <samp>gmp.h</samp> detection. The failure occurs either because
  172. the <cite><acronym>GMP</acronym></cite> library could not be found
  173. (as it is not in the provided library search paths) or because the
  174. <cite><acronym>GMP</acronym></cite> library that was found does not have
  175. the expected <acronym title="Application Binary Interface">ABI</acronym>
  176. (<abbr>e.g.</abbr> 32-bit <abbr>vs</abbr> 64-bit). The former problem can be
  177. due to the fact that a static build of <cite><acronym>MPFR</acronym></cite>
  178. was requested while only a shared <cite><acronym>GMP</acronym></cite> library
  179. is installed (or the opposite, but another error can also show up in this
  180. case, see the <a href="#fpic">question about <samp>-fPIC</samp></a>). The
  181. latter problem can have several causes:</p>
  182. <ul>
  183. <li>A wrong libgmp library has been picked up. This can occur if you have
  184. several <cite><acronym>GMP</acronym></cite> versions installed on the
  185. machine and something is wrong with the provided library search paths.</li>
  186. <li>Wrong compiler options (<samp>CFLAGS</samp>) were given. In general, the
  187. presence or absence of the <samp>-m64</samp> compiler option must match the
  188. library <acronym title="Application Binary Interface">ABI</acronym>.</li>
  189. <li>A wrong <samp>gmp.h</samp> file has been picked up (if you have several
  190. <cite><acronym>GMP</acronym></cite> versions installed). Indeed, by default,
  191. <cite><acronym>MPFR</acronym></cite> gets the compiler options from the
  192. <samp>gmp.h</samp> file (with <cite><acronym>GMP</acronym></cite> 4.2.3
  193. or later); this is needed because <cite><acronym>GMP</acronym></cite> does
  194. not necessarily use the default <acronym>ABI</acronym>. The consequence is
  195. that if the <samp>gmp.h</samp> file is associated with a library using a
  196. different <acronym>ABI</acronym>, the <acronym>ABI</acronym>-related options
  197. will be incorrect. Hence the failure.</li>
  198. </ul>
  199. <p>Note: The <samp>config.log</samp> output gives more information
  200. than the error message. In particular, see the output of the test:
  201. <samp>checking for CC and CFLAGS in gmp.h</samp>; it should give you
  202. the default compiler options (from <samp>gmp.h</samp>).</p>
  203. <p>See also the answer to the <a href="#undef_ref1">next question</a>.</p></dd>
  204. <dt id="undef_ref1">4. I get undefined reference to <code>__gmp_get_memory_functions</code>.</dt>
  205. <dd><p>Note: this was mainly a problem when upgrading from
  206. <cite><acronym>GMP</acronym></cite> 4.1.4 to a later version,
  207. but information given below may still be useful in other cases,
  208. when several <cite><acronym>GMP</acronym></cite> libraries are
  209. installed on the same machine.</p>
  210. <p>If you get such an error, in particular when running
  211. <samp>make check</samp>, then this probably means that you are using
  212. the header file from <cite><acronym>GMP</acronym></cite> 4.2.x but the
  213. <cite><acronym>GMP</acronym></cite> 4.1.4 library. This can happen if
  214. several <cite><acronym>GMP</acronym></cite> versions are installed on
  215. your machine (<abbr>e.g.</abbr>, one provided by the system in
  216. <samp>/usr/{include,lib}</samp> and a new one installed by the owner or
  217. administrator of the machine in <samp>/usr/local/{include,lib}</samp>)
  218. and your include and library search paths are inconsistent. On various
  219. <acronym>GNU</acronym>/Linux machines, this is unfortunately the case
  220. by default (<samp>/usr/local/include</samp> is in the default include
  221. search path, but <samp>/usr/local/lib</samp> is <em>not</em> in the
  222. default library search path). Typical errors are:
  223. <samp class="block-code">undefined reference to `__gmp_get_memory_functions'</samp>
  224. in <samp>make check</samp>. The best solution is to add
  225. <samp>/usr/local/include</samp> to your <var class="env">C_INCLUDE_PATH</var>
  226. environment variable and to add <samp>/usr/local/lib</samp> to your
  227. <var class="env">LIBRARY_PATH</var> and <var class="env">LD_LIBRARY_PATH</var>
  228. environment variables (and/or <var class="env">LD_RUN_PATH</var>).
  229. Alternatively, you can use <samp>--with-gmp*</samp> configure options,
  230. <abbr>e.g.</abbr> <samp>--with-gmp=/usr/local</samp>, but <strong>this is
  231. not guaranteed to work</strong> (in particular with <samp>gcc</samp> and
  232. system directories such as <samp>/usr</samp> or <samp>/usr/local</samp>),
  233. and other software that uses <cite><acronym>GMP</acronym></cite> and/or
  234. <cite><acronym>MPFR</acronym></cite> will need correct paths too;
  235. environment variables allow you to set them in a global way.</p>
  236. <p>Other information can be given in the <samp>INSTALL</samp> file and
  237. <samp>ld</samp> manual. Please look at them for more details. See also
  238. the <a href="#undef_ref2">next question</a>.</p></dd>
  239. <dt id="undef_ref2">5. When I link my program with
  240. <cite><acronym>MPFR</acronym></cite>, I get undefined reference
  241. to <code>__gmpXXXX</code>.</dt>
  242. <dd><p>Link your program with <cite><acronym>GMP</acronym></cite>. Assuming
  243. that your program is <samp>foo.c</samp>, you should link it using:
  244. <samp class="block-code">cc link.c -lmpfr -lgmp</samp>
  245. <cite><acronym>MPFR</acronym></cite> library reference (<samp>-lmpfr</samp>)
  246. should be before <cite><acronym>GMP</acronym></cite>'s one
  247. (<samp>-lgmp</samp>). Another solution is, with <acronym>GNU</acronym>
  248. <samp>ld</samp>, to give all the libraries inside a group:
  249. <samp class="block-code">gcc link.c -Wl,--start-group libgmp.a libmpfr.a -Wl,--end-group</samp>
  250. See <samp>INSTALL</samp> file and <samp>ld</samp> manual for more
  251. details.</p>
  252. <p>If you used correct link options, but still get an error, this may mean
  253. that your include and library search paths are inconsistent. Please see the
  254. <a href="#undef_ref1">previous question</a>.</p></dd>
  255. <dt id="crash_high_prec">6. My program crashes with high precisions.</dt>
  256. <dd><p>Your stack size limit may be too small; indeed, by default,
  257. <cite><acronym>GMP</acronym></cite> 4.1.4 and below allocates all
  258. temporary results on the stack, and in very high precisions, this
  259. limit may be reached. You can solve this problem in different ways:</p>
  260. <ul>
  261. <li><p>You can upgrade to <cite><acronym>GMP</acronym></cite> 4.2 (or above),
  262. which now makes temporary allocations on the stack only when they are
  263. small.</p></li>
  264. <li><p>You can increase the stack size limit with the <samp>limit</samp>,
  265. <samp>unlimit</samp> or <samp>ulimit</samp> command, depending on your
  266. shell. This may fail on some systems, where the maximum stack size cannot
  267. be increased above some value.</p></li>
  268. <li><p>You can rebuild both <cite><acronym>GMP</acronym></cite> and
  269. <cite><acronym>MPFR</acronym></cite> to use another allocation method.</p></li>
  270. </ul></dd>
  271. <dt id="accuracy">7. Though I have increased the precision, the results
  272. are not more accurate.</dt>
  273. <dd><p>The reason may be the use of C floating-point numbers. If you want
  274. to store a floating-point constant to a <code>mpfr_t</code>, you should use
  275. <code>mpfr_set_str</code> (or one of the <cite><acronym>MPFR</acronym></cite>
  276. constant functions, such as <code>mpfr_const_pi</code> for &#960;) instead
  277. of <code>mpfr_set_d</code> or <code>mpfr_set_ld</code>. Otherwise the
  278. floating-point constant will be first converted into a reduced-precision
  279. (<abbr>e.g.</abbr>, 53-bit) binary number before
  280. <cite><acronym>MPFR</acronym></cite> can work with it. This is the case
  281. in particular for most exact decimal numbers, such as 0.17, which are
  282. not exactly representable in binary.</p>
  283. <p>Also remember that <cite><acronym>MPFR</acronym></cite> does not track
  284. the accuracy of the results: copying a value <var>x</var> to <var>y</var>
  285. with <code>mpfr_set (y, x, MPFR_RNDN)</code> where the variable <var>y</var>
  286. is more precise than the variable <var>x</var> will not make it more
  287. accurate; the (binary) value will remain unchanged.</p></dd>
  288. <dt id="detect_mpfr">8. How can I detect <cite><acronym>MPFR</acronym></cite>
  289. installation using <cite>autoconf</cite> or <cite>pkg-config</cite>?</dt>
  290. <dd><p>The <cite><acronym>MPFR</acronym></cite> team does not currently
  291. recommend any <cite>autoconf</cite> code, but a section will later
  292. be added to the <cite><acronym>MPFR</acronym></cite> manual. The
  293. <cite><acronym>MPFR</acronym></cite> team does not wish to support
  294. <cite>pkg-config</cite> yet.</p></dd>
  295. <dt id="cite">9. How to cite <cite><acronym>MPFR</acronym></cite> in a
  296. scientific publication?</dt>
  297. <dd><p>To properly cite <cite><acronym>MPFR</acronym></cite> in a scientific
  298. publication, please cite the
  299. <a href="http://doi.acm.org/10.1145/1236463.1236468"><acronym title="Association for Computing Machinery">ACM</acronym>
  300. <acronym title="Transactions on Mathematical Software">TOMS</acronym>
  301. paper</a>
  302. (<a href="http://toms.acm.org/cgi/TOMSbibget.cgi?Fousse:2007:MMP">BibTeX</a>)
  303. and/or the library web page
  304. <a href="http://www.mpfr.org/">http://www.mpfr.org</a>. If your publication
  305. is related to a particular release of <cite><acronym>MPFR</acronym></cite>,
  306. for example if you report timings, please also indicate the release number
  307. for future reference.</p></dd>
  308. <dt id="fpic">10. When I build <cite><acronym>MPFR</acronym></cite>, I get
  309. an error asking me to recompile with <samp>-fPIC</samp>.</dt>
  310. <dd><p>A typical error looks like:</p>
  311. <p><tt>/usr/bin/ld: <em>/path/to/</em>libgmp.a(realloc.o): relocation
  312. R_X86_64_32 against `.rodata.str1.1' can not be used when making a
  313. shared object; recompile with -fPIC<br />
  314. <em>/path/to/</em>libgmp.a: could not read symbols: Bad value<br />
  315. collect2: ld returned 1 exit status</tt></p>
  316. <p>The probable reason is that you tried to build
  317. <cite><acronym>MPFR</acronym></cite> with the shared library enabled (this
  318. is the default), while only a static <cite><acronym>GMP</acronym></cite>
  319. library could be found. To solve this problem, either rebuild and reinstall
  320. <cite><acronym>GMP</acronym></cite> without the <samp>--disable-shared</samp>
  321. configure option, or configure <cite><acronym>MPFR</acronym></cite> with
  322. <samp>--disable-shared</samp>. If you did this and still get the above
  323. error, the cause may be conflicting <cite><acronym>GMP</acronym></cite>
  324. versions installed on your system; please check that your search path
  325. settings are correct.</p>
  326. <p>Additional note about the last sentence: Under <acronym>GNU</acronym>/Linux
  327. (for instance), the linker takes the first library found in the library search
  328. path, whether it is dynamic or static. The default behavior under darwin is
  329. different, but <cite><acronym>MPFR</acronym></cite> will change it.</p></dd>
  330. <!-- Reference concerning darwin: see MPFR_LD_SEARCH_PATHS_FIRST
  331. in MPFR's configure.{ac,in} and acinclude.m4 -->
  332. </dl>
  333. </body>
  334. </html>