Math.Gmp.Native/docs/html/053b54b6-f646-f0aa-ddaf-00c...

78 lines
98 KiB
HTML
Raw Normal View History

<html><head><meta http-equiv="X-UA-Compatible" content="IE=edge" /><link rel="shortcut icon" href="../icons/favicon.ico" /><link rel="stylesheet" type="text/css" href="../styles/branding.css" /><link rel="stylesheet" type="text/css" href="../styles/branding-en-US.css" /><script type="text/javascript" src="../scripts/branding.js"> </script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>gmp_lib.mpz_out_raw Method </title><meta name="Language" content="en-us" /><meta name="System.Keywords" content="mpz_out_raw method" /><meta name="System.Keywords" content="gmp_lib.mpz_out_raw method" /><meta name="Microsoft.Help.F1" content="Math.Gmp.Native.gmp_lib.mpz_out_raw" /><meta name="Microsoft.Help.Id" content="M:Math.Gmp.Native.gmp_lib.mpz_out_raw(Math.Gmp.Native.ptr{Math.Gmp.Native.FILE},Math.Gmp.Native.mpz_t)" /><meta name="Description" content="Output on stdio stream , in raw binary format." /><meta name="Microsoft.Help.ContentType" content="Reference" /><meta name="BrandingAware" content="true" /><meta name="container" content="Math.Gmp.Native" /><meta name="file" content="053b54b6-f646-f0aa-ddaf-00c494a6d5ef" /><meta name="guid" content="053b54b6-f646-f0aa-ddaf-00c494a6d5ef" /><link type="text/css" rel="stylesheet" href="../styles/highlight.css" /><script type="text/javascript" src="../scripts/highlight.js"> </script><link rel="stylesheet" type="text/css" href="../styles/branding-Website.css" /><script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script><script type="text/javascript" src="../scripts/branding-Website.js"></script><script type="text/javascript" src="../scripts/clipboard.min.js"></script></head><body onload="OnLoad('cs')"><input type="hidden" id="userDataCache" class="userDataStyle" /><div class="pageHeader" id="PageHeader">GMP Native Interface for .NET<form id="SearchForm" method="get" action="#" onsubmit="javascript:TransferToSearchPage(); return false;"><input id="SearchTextBox" type="text" maxlength="200" /><button id="SearchButton" type="submit"></button></form></div><div class="pageBody"><div class="leftNav" id="leftNav"><div id="tocNav"><div class="toclevel0" data-toclevel="0"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="846f5c8a-6cba-433e-9f18-cde2ff5695cd.htm" title="GMP Native Interface for .NET" tocid="roottoc">GMP Native Interface for .NET</a></div><div class="toclevel0" data-toclevel="0"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="d9c51b9f-0c54-770b-28ea-6eebd8fef368.htm" title="Math.Gmp.Native" tocid="d9c51b9f-0c54-770b-28ea-6eebd8fef368">Math.Gmp.Native</a></div><div class="toclevel0" data-toclevel="0"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm" title="gmp_lib Class" tocid="3af6b34c-3242-2b75-e7c7-ab79af8a4b0f">gmp_lib Class</a></div><div class="toclevel1" data-toclevel="1" data-childrenloaded="true"><a class="tocExpanded" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="0fa7cbf3-e8f4-6b14-d829-8aa663e77c74.htm" title="gmp_lib Methods" tocid="0fa7cbf3-e8f4-6b14-d829-8aa663e77c74">gmp_lib Methods</a></div><div class="toclevel2" data-toclevel="2"><a data-tochassubtree="false" href="c9cb6a67-59b8-5c03-f31d-f252441c53f6.htm" title="_mpz_realloc Method " tocid="c9cb6a67-59b8-5c03-f31d-f252441c53f6">_mpz_realloc Method </a></div><div class="toclevel2" data-toclevel="2"><a data-tochassubtree="false" href="2c68671c-cd5c-e2ec-52a2-65b0ca31c3d1.htm" title="allocate Method " tocid="2c68671c-cd5c-e2ec-52a2-65b0ca31c3d1">allocate Method </a></div><div class="toclevel2" data-toclevel="2"><a class="tocCollapsed" onclick="javascript: Toggle(this);" href="#!" /><a data-tochassubtree="true" href="92160da3-b1af-e005-cb05-e3fb4dd524d8.htm" title="free Method " tocid="92160da3-b1af-e005-cb05-e3fb4dd524d8">free Method </a></div><div class="toclevel2" data-toclevel="2"><a data-tochassubtree="false" href="fe6e46
2017-11-04 16:02:37 +01:00
Output <span class="parameter">op</span> on stdio stream <span class="parameter">stream</span>, in raw binary format.
</div><p> </p>
<strong>Namespace:</strong>
 <a href="d9c51b9f-0c54-770b-28ea-6eebd8fef368.htm">Math.Gmp.Native</a><br />
<strong>Assembly:</strong>
 Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)<div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID1RB')" onkeypress="SectionExpandCollapse_CheckKey('ID1RB', event)" tabindex="0"><img id="ID1RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Syntax</span></div><div id="ID1RBSection" class="collapsibleSection"><div class="codeSnippetContainer"><div class="codeSnippetContainerTabs"><div id="ID0EDCA_tab1" class="codeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','cs','1','4');return false;">C#</a></div><div id="ID0EDCA_tab2" class="codeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','vb','2','4');return false;">VB</a></div><div id="ID0EDCA_tab3" class="codeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','cpp','3','4');return false;">C++</a></div><div id="ID0EDCA_tab4" class="codeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDCA','fs','4','4');return false;">F#</a></div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID0EDCA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID0EDCA');return false;" title="Copy">Copy</a></div></div><div id="ID0EDCA_code_Div1" class="codeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="keyword">public</span> <span class="keyword">static</span> <span class="identifier">size_t</span> <span class="identifier">mpz_out_raw</span>(
<span class="identifier">ptr</span>&lt;<span class="identifier">FILE</span>&gt; <span class="parameter">stream</span>,
<span class="identifier">mpz_t</span> <span class="parameter">op</span>
)</pre></div><div id="ID0EDCA_code_Div2" class="codeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="keyword">Public</span> <span class="keyword">Shared</span> <span class="keyword">Function</span> <span class="identifier">mpz_out_raw</span> (
<span class="parameter">stream</span> <span class="keyword">As</span> <span class="identifier">ptr</span>(<span class="keyword">Of</span> <span class="identifier">FILE</span>),
<span class="parameter">op</span> <span class="keyword">As</span> <span class="identifier">mpz_t</span>
) <span class="keyword">As</span> <span class="identifier">size_t</span></pre></div><div id="ID0EDCA_code_Div3" class="codeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="keyword">public</span>:
<span class="keyword">static</span> <span class="identifier">size_t</span> <span class="identifier">mpz_out_raw</span>(
<span class="identifier">ptr</span>&lt;<span class="identifier">FILE</span>&gt;^ <span class="parameter">stream</span>,
<span class="identifier">mpz_t</span>^ <span class="parameter">op</span>
)</pre></div><div id="ID0EDCA_code_Div4" class="codeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="keyword">static</span> <span class="keyword">member</span> <span class="identifier">mpz_out_raw</span> :
<span class="parameter">stream</span> : <span class="identifier">ptr</span>&lt;<span class="identifier">FILE</span>&gt; *
<span class="parameter">op</span> : <span class="identifier">mpz_t</span> <span class="keyword">-&gt;</span> <span class="identifier">size_t</span>
2017-11-08 01:29:10 +01:00
</pre></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EDCA");</script><h4 class="subHeading">Parameters</h4><dl><dt><span class="parameter">stream</span></dt><dd>Type: <a href="542faa00-d28a-72a2-2dd8-6c6021e683ce.htm">Math.Gmp.Native<span id="LSTF0530466_1"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTF0530466_1?cs=.|vb=.|cpp=::|nu=.|fs=.");</script>ptr</a><span id="LSTF0530466_2"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTF0530466_2?cs=&lt;|vb=(Of |cpp=&lt;|fs=&lt;'|nu=(");</script><a href="1bcc07bd-8fee-1107-844c-a5ff10e7660c.htm">FILE</a><span id="LSTF0530466_3"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTF0530466_3?cs=&gt;|vb=)|cpp=&gt;|fs=&gt;|nu=)");</script><br />Pointer to file streama.</dd><dt><span class="parameter">op</span></dt><dd>Type: <a href="8beda7fb-bbc4-b56f-fd1f-1459377ecb3b.htm">Math.Gmp.Native<span id="LSTF0530466_4"></span><script type="text/javascript">AddLanguageSpecificTextSet("LSTF0530466_4?cs=.|vb=.|cpp=::|nu=.|fs=.");</script>mpz_t</a><br />The operand integer.</dd></dl><h4 class="subHeading">Return Value</h4>Type: <a href="d9761bfb-1882-59d2-e89b-c6460141f9a6.htm">size_t</a><br />Return the number of bytes written, or if an error occurred, return 0.</div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID2RB')" onkeypress="SectionExpandCollapse_CheckKey('ID2RB', event)" tabindex="0"><img id="ID2RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Remarks</span></div><div id="ID2RBSection" class="collapsibleSection"><p>
2017-11-04 16:02:37 +01:00
The integer is written in a portable format, with 4 bytes of size information, and that many bytes of limbs.
Both the size and the limbs are written in decreasing significance order (i.e., in big-endian).
</p><p>
2017-12-15 02:18:55 +01:00
The output can be read with <a href="44097b06-123a-4c00-b17f-ab0c70ad78bb.htm">mpz_inp_raw</a>.
2017-11-04 16:02:37 +01:00
</p><p>
The output of this can not be read by <span class="code">mpz_inp_raw</span> from GMP 1,
because of changes necessary for compatibility between 32-bit and 64-bit machines.
</p></div><div class="collapsibleAreaRegion"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID3RB')" onkeypress="SectionExpandCollapse_CheckKey('ID3RB', event)" tabindex="0"><img id="ID3RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />Examples</span></div><div id="ID3RBSection" class="collapsibleSection"><div class="codeSnippetContainer"><div class="codeSnippetContainerTabs"><div id="ID0EDAABA_tab1" class="codeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDAABA','cs','1','4');return false;">C#</a></div><div id="ID0EDAABA_tab2" class="codeSnippetContainerTab"><a href="#" onclick="javascript:ChangeTab('ID0EDAABA','vb','2','4');return false;">VB</a></div><div id="ID0EDAABA_tab3" class="codeSnippetContainerTabPhantom"><a href="#" onclick="javascript:ChangeTab('ID0EDAABA','cpp','3','4');return false;">C++</a></div><div id="ID0EDAABA_tab4" class="codeSnippetContainerTabPhantom"><a href="#" onclick="javascript:ChangeTab('ID0EDAABA','fs','4','4');return false;">F#</a></div></div><div class="codeSnippetContainerCodeContainer"><div class="codeSnippetToolBar"><div class="codeSnippetToolBarText"><a id="ID0EDAABA_copyCode" href="#" class="copyCodeSnippet" onclick="javascript:CopyToClipboard('ID0EDAABA');return false;" title="Copy">Copy</a></div></div><div id="ID0EDAABA_code_Div1" class="codeSnippetContainerCode" style="display: block"><pre xml:space="preserve"><span class="highlight-comment">// Create, initialize, and set the value of op to 123456 (0x1E240).</span>
mpz_t op = <span class="highlight-keyword">new</span> mpz_t();
gmp_lib.mpz_init_set_ui(op, <span class="highlight-number">0x1E240</span>);
<span class="highlight-comment">// Get a temporary file.</span>
<span class="highlight-keyword">string</span> pathname = System.IO.Path.GetTempFileName();
<span class="highlight-comment">// Open temporary file for writing.</span>
ptr&lt;FILE&gt; stream = <span class="highlight-keyword">new</span> ptr&lt;FILE&gt;();
_wfopen_s(<span class="highlight-keyword">out</span> stream.Value.Value, pathname, <span class="highlight-literal">"w"</span>);
<span class="highlight-comment">// Write op to temporary file, and assert that the number of bytes written is 7.</span>
Assert.IsTrue(gmp_lib.mpz_out_raw(stream, op) == <span class="highlight-number">7</span>);
<span class="highlight-comment">// Close temporary file.</span>
fclose(stream.Value.Value);
<span class="highlight-comment">// Assert that the content of the temporary file.</span>
<span class="highlight-keyword">byte</span>[] r = System.IO.File.ReadAllBytes(pathname);
Assert.IsTrue(r[<span class="highlight-number">0</span>] == <span class="highlight-number">0</span> &amp;&amp; r[<span class="highlight-number">1</span>] == <span class="highlight-number">0</span> &amp;&amp; r[<span class="highlight-number">2</span>] == <span class="highlight-number">0</span> &amp;&amp; r[<span class="highlight-number">3</span>] == <span class="highlight-number">3</span> &amp;&amp; r[<span class="highlight-number">4</span>] == <span class="highlight-number">0x01</span> &amp;&amp; r[<span class="highlight-number">5</span>] == <span class="highlight-number">0xE2</span> &amp;&amp; r[<span class="highlight-number">6</span>] == <span class="highlight-number">0x40</span>);
<span class="highlight-comment">// Delete temporary file.</span>
System.IO.File.Delete(pathname);
<span class="highlight-comment">// Release unmanaged memory allocated for op.</span>
gmp_lib.mpz_clear(op);</pre></div><div id="ID0EDAABA_code_Div2" class="codeSnippetContainerCode" style="display: none"><pre xml:space="preserve"><span class="highlight-comment">' Create, initialize, and set the value of op to 123456 (0x1E240).</span>
<span class="highlight-keyword">Dim</span> op <span class="highlight-keyword">As</span> <span class="highlight-keyword">New</span> mpz_t()
gmp_lib.mpz_init_set_ui(op, <span class="highlight-number">&amp;H1e240</span>)
<span class="highlight-comment">' Get a temporary file.</span>
<span class="highlight-keyword">Dim</span> pathname <span class="highlight-keyword">As</span> <span class="highlight-keyword">String</span> = System.IO.Path.GetTempFileName()
<span class="highlight-comment">' Open temporary file for writing.</span>
<span class="highlight-keyword">Dim</span> stream <span class="highlight-keyword">As</span> <span class="highlight-keyword">New</span> ptr(<span class="highlight-keyword">Of</span> FILE)()
_wfopen_s(stream.Value.Value, pathname, <span class="highlight-literal">"w"</span>)
<span class="highlight-comment">' Write op to temporary file, and assert that the number of bytes written is 7.</span>
Assert.IsTrue(gmp_lib.mpz_out_raw(stream, op) = <span class="highlight-number">7</span>)
<span class="highlight-comment">' Close temporary file.</span>
fclose(stream.Value.Value)
<span class="highlight-comment">' Assert that the content of the temporary file.</span>
<span class="highlight-keyword">Dim</span> r <span class="highlight-keyword">As</span> <span class="highlight-keyword">Byte</span>() = System.IO.File.ReadAllBytes(pathname)
Assert.IsTrue(r(<span class="highlight-number">0</span>) = <span class="highlight-number">0</span> <span class="highlight-keyword">AndAlso</span> r(<span class="highlight-number">1</span>) = <span class="highlight-number">0</span> <span class="highlight-keyword">AndAlso</span> r(<span class="highlight-number">2</span>) = <span class="highlight-number">0</span> <span class="highlight-keyword">AndAlso</span> r(<span class="highlight-number">3</span>) = <span class="highlight-number">3</span> <span class="highlight-keyword">AndAlso</span> r(<span class="highlight-number">4</span>) = <span class="highlight-number">&amp;H1</span> <span class="highlight-keyword">AndAlso</span> r(<span class="highlight-number">5</span>) = <span class="highlight-number">&amp;He2</span> <span class="highlight-keyword">AndAlso</span> r(<span class="highlight-number">6</span>) = <span class="highlight-number">&amp;H40</span>)
<span class="highlight-comment">' Delete temporary file.</span>
System.IO.File.Delete(pathname)
<span class="highlight-comment">' Release unmanaged memory allocated for op.</span>
2018-01-06 17:23:30 +01:00
gmp_lib.mpz_clear(op)</pre></div><div id="ID0EDAABA_code_Div3" class="codeSnippetContainerCode" style="display: none"><p>No code example is currently available or this language may not be supported.</p></div><div id="ID0EDAABA_code_Div4" class="codeSnippetContainerCode" style="display: none"><p>No code example is currently available or this language may not be supported.</p></div></div></div><script type="text/javascript">AddLanguageTabSet("ID0EDAABA");</script></div><div class="collapsibleAreaRegion" id="seeAlsoSection"><span class="collapsibleRegionTitle" onclick="SectionExpandCollapse('ID4RB')" onkeypress="SectionExpandCollapse_CheckKey('ID4RB', event)" tabindex="0"><img id="ID4RBToggle" class="collapseToggle" src="../icons/SectionExpanded.png" />See Also</span></div><div id="ID4RBSection" class="collapsibleSection"><h4 class="subHeading">Reference</h4><div class="seeAlsoStyle"><a href="3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm">gmp_lib Class</a></div><div class="seeAlsoStyle"><a href="d9c51b9f-0c54-770b-28ea-6eebd8fef368.htm">Math.Gmp.Native Namespace</a></div><div class="seeAlsoStyle"><a href="6f85986d-b6a0-435d-3675-c025ef70413d.htm">mpz_out_str</a></div><div class="seeAlsoStyle"><a href="8b8d6ec1-3ae5-e6f3-f030-289abe5002d0.htm">mpz_inp_str</a></div><div class="seeAlsoStyle"><a href="44097b06-123a-4c00-b17f-ab0c70ad78bb.htm">mpz_inp_raw</a></div><div class="seeAlsoStyle"><a href="3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm"><a href="/Math.Gmp.Native/html/3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm#IO_of_Integers">I/O of Integers</a></a></div><div class="seeAlsoStyle"><a href="3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm"><a href="https://gmplib.org/manual/I_002fO-of-Integers.html#I_002fO-of-Integers">GNU MP - I/O of Integers</a></a></div></div></div></div><div id="pageFooter" class="pageFooter"> </div></body></html>