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.
157 lines
7.9 KiB
HTML
157 lines
7.9 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>Converting 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="Converting 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="Integer-Arithmetic.html#Integer-Arithmetic" rel="next" title="Integer Arithmetic">
|
|
<link href="Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign" rel="prev" title="Simultaneous Integer Init & Assign">
|
|
<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="Converting-Integers"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Integer-Arithmetic.html#Integer-Arithmetic" accesskey="n" rel="next">Integer Arithmetic</a>, Previous: <a href="Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign" accesskey="p" rel="prev">Simultaneous Integer Init & Assign</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="Conversion-Functions"></a>
|
|
<h3 class="section">5.4 Conversion Functions</h3>
|
|
<a name="index-Integer-conversion-functions"></a>
|
|
<a name="index-Conversion-functions"></a>
|
|
|
|
<p>This section describes functions for converting GMP integers to standard C
|
|
types. Functions for converting <em>to</em> GMP integers are described in
|
|
<a href="Assigning-Integers.html#Assigning-Integers">Assigning Integers</a> and <a href="I_002fO-of-Integers.html#I_002fO-of-Integers">I/O of Integers</a>.
|
|
</p>
|
|
<dl>
|
|
<dt><a name="index-mpz_005fget_005fui"></a>Function: <em>unsigned long int</em> <strong>mpz_get_ui</strong> <em>(const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>Return the value of <var>op</var> as an <code>unsigned long</code>.
|
|
</p>
|
|
<p>If <var>op</var> is too big to fit an <code>unsigned long</code> then just the least
|
|
significant bits that do fit are returned. The sign of <var>op</var> is ignored,
|
|
only the absolute value is used.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fget_005fsi"></a>Function: <em>signed long int</em> <strong>mpz_get_si</strong> <em>(const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>If <var>op</var> fits into a <code>signed long int</code> return the value of <var>op</var>.
|
|
Otherwise return the least significant part of <var>op</var>, with the same sign
|
|
as <var>op</var>.
|
|
</p>
|
|
<p>If <var>op</var> is too big to fit in a <code>signed long int</code>, the returned
|
|
result is probably not very useful. To find out if the value will fit, use
|
|
the function <code>mpz_fits_slong_p</code>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fget_005fd"></a>Function: <em>double</em> <strong>mpz_get_d</strong> <em>(const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>Convert <var>op</var> to a <code>double</code>, truncating if necessary (i.e. rounding
|
|
towards zero).
|
|
</p>
|
|
<p>If the exponent from the conversion is too big, the result is system
|
|
dependent. An infinity is returned where available. A hardware overflow trap
|
|
may or may not occur.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fget_005fd_005f2exp"></a>Function: <em>double</em> <strong>mpz_get_d_2exp</strong> <em>(signed long int *<var>exp</var>, const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>Convert <var>op</var> to a <code>double</code>, truncating if necessary (i.e. rounding
|
|
towards zero), and returning the exponent separately.
|
|
</p>
|
|
<p>The return value is in the range <em>0.5<=abs(<var>d</var>)<1</em> and the
|
|
exponent is stored to <code>*<var>exp</var></code>. <em><var>d</var> *
|
|
2^<var>exp</var></em> is the (truncated) <var>op</var> value. If <var>op</var> is zero, the
|
|
return is <em>0.0</em> and 0 is stored to <code>*<var>exp</var></code>.
|
|
</p>
|
|
<a name="index-frexp"></a>
|
|
<p>This is similar to the standard C <code>frexp</code> function (see <a href="http://www.gnu.org/software/libc/manual/html_node/Normalization-Functions.html#Normalization-Functions">Normalization
|
|
Functions</a> in <cite>The GNU C Library Reference Manual</cite>).
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fget_005fstr"></a>Function: <em>char *</em> <strong>mpz_get_str</strong> <em>(char *<var>str</var>, int <var>base</var>, const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>Convert <var>op</var> to a string of digits in base <var>base</var>. The base argument
|
|
may vary from 2 to 62 or from -2 to -36.
|
|
</p>
|
|
<p>For <var>base</var> in the range 2..36, digits and lower-case letters are used; for
|
|
-2..-36, digits and upper-case letters are used; for 37..62,
|
|
digits, upper-case letters, and lower-case letters (in that significance order)
|
|
are used.
|
|
</p>
|
|
<p>If <var>str</var> is <code>NULL</code>, the result string is allocated using the current
|
|
allocation function (see <a href="Custom-Allocation.html#Custom-Allocation">Custom Allocation</a>). The block will be
|
|
<code>strlen(str)+1</code> bytes, that being exactly enough for the string and
|
|
null-terminator.
|
|
</p>
|
|
<p>If <var>str</var> is not <code>NULL</code>, it should point to a block of storage large
|
|
enough for the result, that being <code>mpz_sizeinbase (<var>op</var>, <var>base</var>)
|
|
+ 2</code>. The two extra bytes are for a possible minus sign, and the
|
|
null-terminator.
|
|
</p>
|
|
<p>A pointer to the result string is returned, being either the allocated block,
|
|
or the given <var>str</var>.
|
|
</p></dd></dl>
|
|
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Integer-Arithmetic.html#Integer-Arithmetic" accesskey="n" rel="next">Integer Arithmetic</a>, Previous: <a href="Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign" accesskey="p" rel="prev">Simultaneous Integer Init & Assign</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>
|