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.
153 lines
6.7 KiB
HTML
153 lines
6.7 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>Initializing Integers (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="Initializing Integers (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="Assigning-Integers.html#Assigning-Integers" rel="next" title="Assigning Integers">
|
|
<link href="Integer-Functions.html#Integer-Functions" rel="prev" title="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="Initializing-Integers"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Assigning-Integers.html#Assigning-Integers" accesskey="n" rel="next">Assigning Integers</a>, Previous: <a href="Integer-Functions.html#Integer-Functions" accesskey="p" rel="prev">Integer Functions</a>, Up: <a href="Integer-Functions.html#Integer-Functions" accesskey="u" rel="up">Integer Functions</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<a name="Initialization-Functions"></a>
|
|
<h3 class="section">5.1 Initialization Functions</h3>
|
|
<a name="index-Integer-initialization-functions"></a>
|
|
<a name="index-Initialization-functions"></a>
|
|
|
|
<p>The functions for integer arithmetic assume that all integer objects are
|
|
initialized. You do that by calling the function <code>mpz_init</code>. For
|
|
example,
|
|
</p>
|
|
<div class="example">
|
|
<pre class="example">{
|
|
mpz_t integ;
|
|
mpz_init (integ);
|
|
…
|
|
mpz_add (integ, …);
|
|
…
|
|
mpz_sub (integ, …);
|
|
|
|
/* Unless the program is about to exit, do ... */
|
|
mpz_clear (integ);
|
|
}
|
|
</pre></div>
|
|
|
|
<p>As you can see, you can store new values any number of times, once an
|
|
object is initialized.
|
|
</p>
|
|
<dl>
|
|
<dt><a name="index-mpz_005finit"></a>Function: <em>void</em> <strong>mpz_init</strong> <em>(mpz_t <var>x</var>)</em></dt>
|
|
<dd><p>Initialize <var>x</var>, and set its value to 0.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005finits"></a>Function: <em>void</em> <strong>mpz_inits</strong> <em>(mpz_t <var>x</var>, ...)</em></dt>
|
|
<dd><p>Initialize a NULL-terminated list of <code>mpz_t</code> variables, and set their
|
|
values to 0.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005finit2"></a>Function: <em>void</em> <strong>mpz_init2</strong> <em>(mpz_t <var>x</var>, mp_bitcnt_t <var>n</var>)</em></dt>
|
|
<dd><p>Initialize <var>x</var>, with space for <var>n</var>-bit numbers, and set its value to 0.
|
|
Calling this function instead of <code>mpz_init</code> or <code>mpz_inits</code> is never
|
|
necessary; reallocation is handled automatically by GMP when needed.
|
|
</p>
|
|
<p>While <var>n</var> defines the initial space, <var>x</var> will grow automatically in the
|
|
normal way, if necessary, for subsequent values stored. <code>mpz_init2</code> makes
|
|
it possible to avoid such reallocations if a maximum size is known in advance.
|
|
</p>
|
|
<p>In preparation for an operation, GMP often allocates one limb more than
|
|
ultimately needed. To make sure GMP will not perform reallocation for
|
|
<var>x</var>, you need to add the number of bits in <code>mp_limb_t</code> to <var>n</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fclear"></a>Function: <em>void</em> <strong>mpz_clear</strong> <em>(mpz_t <var>x</var>)</em></dt>
|
|
<dd><p>Free the space occupied by <var>x</var>. Call this function for all <code>mpz_t</code>
|
|
variables when you are done with them.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fclears"></a>Function: <em>void</em> <strong>mpz_clears</strong> <em>(mpz_t <var>x</var>, ...)</em></dt>
|
|
<dd><p>Free the space occupied by a NULL-terminated list of <code>mpz_t</code> variables.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005frealloc2"></a>Function: <em>void</em> <strong>mpz_realloc2</strong> <em>(mpz_t <var>x</var>, mp_bitcnt_t <var>n</var>)</em></dt>
|
|
<dd><p>Change the space allocated for <var>x</var> to <var>n</var> bits. The value in <var>x</var>
|
|
is preserved if it fits, or is set to 0 if not.
|
|
</p>
|
|
<p>Calling this function is never necessary; reallocation is handled automatically
|
|
by GMP when needed. But this function can be used to increase the space for a
|
|
variable in order to avoid repeated automatic reallocations, or to decrease it
|
|
to give memory back to the heap.
|
|
</p></dd></dl>
|
|
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Assigning-Integers.html#Assigning-Integers" accesskey="n" rel="next">Assigning Integers</a>, Previous: <a href="Integer-Functions.html#Integer-Functions" accesskey="p" rel="prev">Integer Functions</a>, Up: <a href="Integer-Functions.html#Integer-Functions" accesskey="u" rel="up">Integer Functions</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|