You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
9.4 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual describes how to install and use the GNU multiple precision
arithmetic library, version 6.1.0.
Copyright 1991, 1993-2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under
the terms of the GNU Free Documentation License, Version 1.3 or any later
version published by the Free Software Foundation; with no Invariant Sections,
with the Front-Cover Texts being "A GNU Manual", and with the Back-Cover
Texts being "You have freedom to copy and modify this GNU Manual, like GNU
software". A copy of the license is included in
GNU Free Documentation License. -->
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Integer Special Functions (GNU MP 6.1.0)</title>
<meta name="description" content="How to install and use the GNU multiple precision arithmetic library, version 6.1.0.">
<meta name="keywords" content="Integer Special Functions (GNU MP 6.1.0)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="Integer-Functions.html#Integer-Functions" rel="up" title="Integer Functions">
<link href="Rational-Number-Functions.html#Rational-Number-Functions" rel="next" title="Rational Number Functions">
<link href="Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions" rel="prev" title="Miscellaneous Integer Functions">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Integer-Special-Functions"></a>
<div class="header">
<p>
Previous: <a href="Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions" accesskey="p" rel="prev">Miscellaneous Integer Functions</a>, Up: <a href="Integer-Functions.html#Integer-Functions" accesskey="u" rel="up">Integer Functions</a> &nbsp; [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Special-Functions"></a>
<h3 class="section">5.16 Special Functions</h3>
<a name="index-Special-integer-functions"></a>
<a name="index-Integer-special-functions"></a>
<p>The functions in this section are for various special purposes. Most
applications will not need them.
</p>
<dl>
<dt><a name="index-mpz_005farray_005finit"></a>Function: <em>void</em> <strong>mpz_array_init</strong> <em>(mpz_t <var>integer_array</var>, mp_size_t <var>array_size</var>, <span class="nolinebreak">mp_size_t</span>&nbsp;<var><span class="nolinebreak">fixed_num_bits</span></var><!-- /@w -->)</em></dt>
<dd><p><strong>This is an obsolete function. Do not use it.</strong>
</p></dd></dl>
<dl>
<dt><a name="index-_005fmpz_005frealloc"></a>Function: <em>void *</em> <strong>_mpz_realloc</strong> <em>(mpz_t <var>integer</var>, mp_size_t <var>new_alloc</var>)</em></dt>
<dd><p>Change the space for <var>integer</var> to <var>new_alloc</var> limbs. The value in
<var>integer</var> is preserved if it fits, or is set to 0 if not. The return
value is not useful to applications and should be ignored.
</p>
<p><code>mpz_realloc2</code> is the preferred way to accomplish allocation changes like
this. <code>mpz_realloc2</code> and <code>_mpz_realloc</code> are the same except that
<code>_mpz_realloc</code> takes its size in limbs.
</p></dd></dl>
<dl>
<dt><a name="index-mpz_005fgetlimbn"></a>Function: <em>mp_limb_t</em> <strong>mpz_getlimbn</strong> <em>(const mpz_t <var>op</var>, mp_size_t <var>n</var>)</em></dt>
<dd><p>Return limb number <var>n</var> from <var>op</var>. The sign of <var>op</var> is ignored,
just the absolute value is used. The least significant limb is number 0.
</p>
<p><code>mpz_size</code> can be used to find how many limbs make up <var>op</var>.
<code>mpz_getlimbn</code> returns zero if <var>n</var> is outside the range 0 to
<code>mpz_size(<var>op</var>)-1</code>.
</p></dd></dl>
<dl>
<dt><a name="index-mpz_005fsize"></a>Function: <em>size_t</em> <strong>mpz_size</strong> <em>(const mpz_t <var>op</var>)</em></dt>
<dd><p>Return the size of <var>op</var> measured in number of limbs. If <var>op</var> is zero,
the returned value will be zero.
</p></dd></dl>
<dl>
<dt><a name="index-mpz_005flimbs_005fread"></a>Function: <em>const mp_limb_t *</em> <strong>mpz_limbs_read</strong> <em>(const mpz_t <var>x</var>)</em></dt>
<dd><p>Return a pointer to the limb array representing the absolute value of <var>x</var>.
The size of the array is <code>mpz_size(<var>x</var>)</code>. Intended for read access
only.
</p></dd></dl>
<dl>
<dt><a name="index-mpz_005flimbs_005fwrite"></a>Function: <em>mp_limb_t *</em> <strong>mpz_limbs_write</strong> <em>(mpz_t <var>x</var>, mp_size_t <var>n</var>)</em></dt>
<dt><a name="index-mpz_005flimbs_005fmodify"></a>Function: <em>mp_limb_t *</em> <strong>mpz_limbs_modify</strong> <em>(mpz_t <var>x</var>, mp_size_t <var>n</var>)</em></dt>
<dd><p>Return a pointer to the limb array, intended for write access. The array is
reallocated as needed, to make room for <var>n</var> limbs. Requires <em><var>n</var>
&gt; 0</em>. The <code>mpz_limbs_modify</code> function returns an array that holds the old
absolute value of <var>x</var>, while <code>mpz_limbs_write</code> may destroy the old
value and return an array with unspecified contents.
</p></dd></dl>
<dl>
<dt><a name="index-mpz_005flimbs_005ffinish"></a>Function: <em>void</em> <strong>mpz_limbs_finish</strong> <em>(mpz_t <var>x</var>, mp_size_t <var>s</var>)</em></dt>
<dd><p>Updates the internal size field of <var>x</var>. Used after writing to the limb
array pointer returned by <code>mpz_limbs_write</code> or <code>mpz_limbs_modify</code> is
completed. The array should contain <em>abs(<var>s</var>)</em> valid limbs,
representing the new absolute value for <var>x</var>, and the sign of <var>x</var> is
taken from the sign of <var>s</var>. This function never reallocates <var>x</var>, so
the limb pointer remains valid.
</p></dd></dl>
<div class="example">
<pre class="example">void foo (mpz_t x)
{
mp_size_t n, i;
mp_limb_t *xp;
n = mpz_size (x);
xp = mpz_limbs_modify (x, 2*n);
for (i = 0; i &lt; n; i++)
xp[n+i] = xp[n-1-i];
mpz_limbs_finish (x, mpz_sgn (x) &lt; 0 ? - 2*n : 2*n);
}
</pre></div>
<dl>
<dt><a name="index-mpz_005froinit_005fn"></a>Function: <em>mpz_srcptr</em> <strong>mpz_roinit_n</strong> <em>(mpz_t <var>x</var>, const mp_limb_t *<var>xp</var>, mp_size_t <var>xs</var>)</em></dt>
<dd><p>Special initialization of <var>x</var>, using the given limb array and size.
<var>x</var> should be treated as read-only: it can be passed safely as input to
any mpz function, but not as an output. The array <var>xp</var> must point to at
least a readable limb, its size is
<em>abs(<var>xs</var>)</em>, and the sign of <var>x</var> is the sign of <var>xs</var>. For
convenience, the function returns <var>x</var>, but cast to a const pointer type.
</p></dd></dl>
<div class="example">
<pre class="example">void foo (mpz_t x)
{
static const mp_limb_t y[3] = { 0x1, 0x2, 0x3 };
mpz_t tmp;
mpz_add (x, x, mpz_roinit_n (tmp, y, 3));
}
</pre></div>
<dl>
<dt><a name="index-MPZ_005fROINIT_005fN"></a>Macro: <em>mpz_t</em> <strong>MPZ_ROINIT_N</strong> <em>(mp_limb_t *<var>xp</var>, mp_size_t <var>xs</var>)</em></dt>
<dd><p>This macro expands to an initializer which can be assigned to an mpz_t
variable. The limb array <var>xp</var> must point to at least a readable limb,
moreover, unlike the <code>mpz_roinit_n</code> function, the array must be
normalized: if <var>xs</var> is non-zero, then
<code><var>xp</var>[<em>abs(<var>xs</var>)-1</em>]</code> must be non-zero. Intended
primarily for constant values. Using it for non-constant values requires a C
compiler supporting C99.
</p></dd></dl>
<div class="example">
<pre class="example">void foo (mpz_t x)
{
static const mp_limb_t ya[3] = { 0x1, 0x2, 0x3 };
static const mpz_t y = MPZ_ROINIT_N ((mp_limb_t *) ya, 3);
mpz_add (x, x, y);
}
</pre></div>
<hr>
<div class="header">
<p>
Previous: <a href="Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions" accesskey="p" rel="prev">Miscellaneous Integer Functions</a>, Up: <a href="Integer-Functions.html#Integer-Functions" accesskey="u" rel="up">Integer Functions</a> &nbsp; [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>