2017-12-03 23:32:51 +01:00
< 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_roinit_n Method < / title > < meta name = "Language" content = "en-us" / > < meta name = "System.Keywords" content = "mpz_roinit_n method" / > < meta name = "System.Keywords" content = "gmp_lib.mpz_roinit_n method" / > < meta name = "Microsoft.Help.F1" content = "Math.Gmp.Native.gmp_lib.mpz_roinit_n" / > < meta name = "Microsoft.Help.Id" content = "M:Math.Gmp.Native.gmp_lib.mpz_roinit_n(Math.Gmp.Native.mpz_t,Math.Gmp.Native.mp_ptr,Math.Gmp.Native.mp_size_t)" / > < meta name = "Description" content = "Special initialization of , using the given limb array and size." / > < meta name = "Microsoft.Help.ContentType" content = "Reference" / > < meta name = "BrandingAware" content = "true" / > < meta name = "container" content = "Math.Gmp.Native" / > < meta name = "file" content = "5786e0c6-2dde-406f-b86d-3df6757c80c0" / > < meta name = "guid" content = "5786e0c6-2dde-406f-b86d-3df6757c80c0" / > < 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-toch
2017-11-04 16:02:37 +01:00
Special initialization of < span class = "parameter" > x< / span > , using the given limb array and size.
< / 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" > mpz_t< / span > < span class = "identifier" > mpz_roinit_n< / span > (
< span class = "identifier" > mpz_t< / span > < span class = "parameter" > x< / span > ,
< span class = "identifier" > mp_ptr< / span > < span class = "parameter" > xp< / span > ,
< span class = "identifier" > mp_size_t< / span > < span class = "parameter" > xs< / 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_roinit_n< / span > (
< span class = "parameter" > x< / span > < span class = "keyword" > As< / span > < span class = "identifier" > mpz_t< / span > ,
< span class = "parameter" > xp< / span > < span class = "keyword" > As< / span > < span class = "identifier" > mp_ptr< / span > ,
< span class = "parameter" > xs< / span > < span class = "keyword" > As< / span > < span class = "identifier" > mp_size_t< / span >
) < span class = "keyword" > As< / span > < span class = "identifier" > mpz_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" > mpz_t< / span > ^ < span class = "identifier" > mpz_roinit_n< / span > (
< span class = "identifier" > mpz_t< / span > ^ < span class = "parameter" > x< / span > ,
< span class = "identifier" > mp_ptr< / span > ^ < span class = "parameter" > xp< / span > ,
< span class = "identifier" > mp_size_t< / span > < span class = "parameter" > xs< / 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_roinit_n< / span > :
< span class = "parameter" > x< / span > : < span class = "identifier" > mpz_t< / span > *
< span class = "parameter" > xp< / span > : < span class = "identifier" > mp_ptr< / span > *
< span class = "parameter" > xs< / span > : < span class = "identifier" > mp_size_t< / span > < span class = "keyword" > -> < / span > < span class = "identifier" > mpz_t< / span >
< / pre > < / div > < / div > < / div > < script type = "text/javascript" > AddLanguageTabSet ( "ID0EDCA" ) ; < / script > < h4 class = "subHeading" > Parameters< / h4 > < dl > < dt > < span class = "parameter" > x< / span > < / dt > < dd > Type: < a href = "8beda7fb-bbc4-b56f-fd1f-1459377ecb3b.htm" > Math.Gmp.Native< span id = "LSTC7F77250_1" > < / span > < script type = "text/javascript" > AddLanguageSpecificTextSet ( "LSTC7F77250_1?cs=.|vb=.|cpp=::|nu=.|fs=." ) ; < / script > mpz_t< / a > < br / > The operand integer.< / dd > < dt > < span class = "parameter" > xp< / span > < / dt > < dd > Type: < a href = "4609ac5e-5cf9-cd20-2fa9-8040101c165c.htm" > Math.Gmp.Native< span id = "LSTC7F77250_2" > < / span > < script type = "text/javascript" > AddLanguageSpecificTextSet ( "LSTC7F77250_2?cs=.|vb=.|cpp=::|nu=.|fs=." ) ; < / script > mp_ptr< / a > < br / > The limbs array.< / dd > < dt > < span class = "parameter" > xs< / span > < / dt > < dd > Type: < a href = "4b58a584-7a0e-b600-18fa-ebd493861eb3.htm" > Math.Gmp.Native< span id = "LSTC7F77250_3" > < / span > < script type = "text/javascript" > AddLanguageSpecificTextSet ( "LSTC7F77250_3?cs=.|vb=.|cpp=::|nu=.|fs=." ) ; < / script > mp_size_t< / a > < br / > The number of limbs and the sign.< / dd > < / dl > < h4 class = "subHeading" > Return Value< / h4 > Type: < a href = "8beda7fb-bbc4-b56f-fd1f-1459377ecb3b.htm" > mpz_t< / a > < br / > For convenience, the function returns < span class = "parameter" > x< / span > , but cast to a const pointer type.< / 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 > < span class = "parameter" > x< / span > should be treated as readonly: it can be passed safely as input to any mpz function, but not as an output.
2017-11-08 01:29:10 +01:00
The array < span class = "parameter" > xp< / span > must point to at least a readable limb, its size is | < span class = "parameter" > xs< / span > |, and the
2017-11-04 16:02:37 +01:00
sign of < span class = "parameter" > x< / span > is the sign of < span class = "parameter" > xs< / span > .
2017-12-15 02:18:55 +01:00
< / p > < div class = "codeSnippetContainer" > < div class = "codeSnippetContainerTabs" > < div id = "ID0EAAKBA_tab1" class = "codeSnippetContainerTabSingle" > C++< / div > < / div > < div class = "codeSnippetContainerCodeContainer" > < div class = "codeSnippetToolBar" > < div class = "codeSnippetToolBarText" > < a id = "ID0EAAKBA_copyCode" href = "#" class = "copyCodeSnippet" onclick = "javascript:CopyToClipboard('ID0EAAKBA');return false;" title = "Copy" > Copy< / a > < / div > < / div > < div id = "ID0EAAKBA_code_Div1" class = "codeSnippetContainerCode" style = "display: block" > < pre xml:space = "preserve" > < span class = "highlight-keyword" > void< / span > foo (mpz_t x)
2017-11-04 16:02:37 +01:00
{
< span class = "highlight-keyword" > static< / span > < span class = "highlight-keyword" > const< / span > mp_limb_t y[< span class = "highlight-number" > 3< / span > ] = { < span class = "highlight-number" > 0x1< / span > , < span class = "highlight-number" > 0x2< / span > , < span class = "highlight-number" > 0x3< / span > };
mpz_t tmp;
mpz_add(x, x, mpz_roinit_n(tmp, y, < span class = "highlight-number" > 3< / span > ));
2017-12-15 02:18:55 +01:00
}< / pre > < / div > < / div > < / div > < script type = "text/javascript" > AddLanguageTabSet ( "ID0EAAKBA" ) ; < / script > < / 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 and initialize new integer x.< / span >
2017-11-04 16:02:37 +01:00
mpz_t x = < span class = "highlight-keyword" > new< / span > mpz_t();
gmp_lib.mpz_init(x);
< span class = "highlight-comment" > // Prepare new limbs for x.< / span >
mp_ptr limbs;
< span class = "highlight-keyword" > if< / span > (gmp_lib.mp_bytes_per_limb == < span class = "highlight-number" > 4< / span > )
limbs = < span class = "highlight-keyword" > new< / span > mp_ptr(< span class = "highlight-keyword" > new< / span > < span class = "highlight-keyword" > uint< / span > [] { < span class = "highlight-number" > 0< / span > U, < span class = "highlight-number" > 0< / span > U, < span class = "highlight-number" > 2< / span > U });
< span class = "highlight-keyword" > else< / span >
limbs = < span class = "highlight-keyword" > new< / span > mp_ptr(< span class = "highlight-keyword" > new< / span > < span class = "highlight-keyword" > ulong< / span > [] { < span class = "highlight-number" > 0< / span > UL, < span class = "highlight-number" > 0< / span > UL, < span class = "highlight-number" > 4< / span > UL });
< span class = "highlight-comment" > // Assign new limbs to x, and make x negative.< / span >
x = gmp_lib.mpz_roinit_n(x, limbs, < span class = "highlight-number" > -3< / span > );
< span class = "highlight-comment" > // Assert new value of x.< / span >
char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, gmp_lib.mp_bytes_per_limb == < span class = "highlight-number" > 4< / span > ? < span class = "highlight-number" > 2< / span > : < span class = "highlight-number" > 4< / span > , x);
Assert.IsTrue(s.ToString() == < span class = "highlight-literal" > "-10 00000000000000000000000000000000 00000000000000000000000000000000"< / span > .Replace(< span class = "highlight-literal" > " "< / span > , < span class = "highlight-literal" > ""< / span > ));
< span class = "highlight-comment" > // Release unmanaged memory allocated for x and s.< / span >
gmp_lib.mpz_clear(x);
gmp_lib.free(s);< / pre > < / div > < div id = "ID0EDAABA_code_Div2" class = "codeSnippetContainerCode" style = "display: none" > < pre xml:space = "preserve" > < span class = "highlight-comment" > ' Create and initialize new integer x.< / span >
< span class = "highlight-keyword" > Dim< / span > x < span class = "highlight-keyword" > As< / span > < span class = "highlight-keyword" > New< / span > mpz_t()
gmp_lib.mpz_init(x)
< span class = "highlight-comment" > ' Prepare new limbs for x.< / span >
< span class = "highlight-keyword" > Dim< / span > limbs < span class = "highlight-keyword" > As< / span > mp_ptr
< span class = "highlight-keyword" > If< / span > gmp_lib.mp_bytes_per_limb = < span class = "highlight-number" > 4< / span > < span class = "highlight-keyword" > Then< / span >
limbs = < span class = "highlight-keyword" > New< / span > mp_ptr(< span class = "highlight-keyword" > New< / span > < span class = "highlight-keyword" > UInteger< / span > () { < span class = "highlight-number" > 0< / span > UI, < span class = "highlight-number" > 0< / span > UI, < span class = "highlight-number" > 2< / span > UI})
< span class = "highlight-keyword" > Else< / span >
limbs = < span class = "highlight-keyword" > New< / span > mp_ptr(< span class = "highlight-keyword" > New< / span > < span class = "highlight-keyword" > ULong< / span > () { < span class = "highlight-number" > 0< / span > UL, < span class = "highlight-number" > 0< / span > UL, < span class = "highlight-number" > 4< / span > UL})
< span class = "highlight-keyword" > End< / span > < span class = "highlight-keyword" > If< / span >
< span class = "highlight-comment" > ' Assign new limbs to x, and make x negative.< / span >
x = gmp_lib.mpz_roinit_n(x, limbs, < span class = "highlight-number" > -3< / span > )
< span class = "highlight-comment" > ' Assert new value of x.< / span >
< span class = "highlight-keyword" > Dim< / span > s < span class = "highlight-keyword" > As< / span > char_ptr = gmp_lib.mpz_get_str(char_ptr.Zero, < span class = "highlight-keyword" > If< / span > (gmp_lib.mp_bytes_per_limb = < span class = "highlight-number" > 4< / span > , < span class = "highlight-number" > 2< / span > , < span class = "highlight-number" > 4< / span > ), x)
Assert.IsTrue(s.ToString() = < span class = "highlight-literal" > "-10 00000000000000000000000000000000 00000000000000000000000000000000"< / span > .Replace(< span class = "highlight-literal" > " "< / span > , < span class = "highlight-literal" > ""< / span > ))
< span class = "highlight-comment" > ' Release unmanaged memory allocated for x and s.< / span >
gmp_lib.mpz_clear(x)
2017-12-15 02:18:55 +01:00
gmp_lib.free(s)< / 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 = "c9cb6a67-59b8-5c03-f31d-f252441c53f6.htm" > _mpz_realloc< / a > < / div > < div class = "seeAlsoStyle" > < a href = "1dfbf5da-f4c2-bbab-5708-3b31d40e4f16.htm" > mpz_getlimbn< / a > < / div > < div class = "seeAlsoStyle" > < a href = "9a169dd9-42b0-ea59-abbe-4efc6b870c75.htm" > mpz_size< / a > < / div > < div class = "seeAlsoStyle" > < a href = "4b08344c-f506-a717-4e1d-112cd19f5286.htm" > mpz_limbs_read< / a > < / div > < div class = "seeAlsoStyle" > < a href = "86ddbf69-57f6-af58-bd13-3eca06123b29.htm" > mpz_limbs_write< / a > < / div > < div class = "seeAlsoStyle" > < a href = "87f5432d-aacb-57b6-b4a7-e4dc803684a4.htm" > mpz_limbs_modify< / a > < / div > < div class = "seeAlsoStyle" > < a href = "398e3eb8-0f55-086f-a765-0a8b3c9307e0.htm" > mpz_limbs_finish< / a > < / div > < div class = "seeAlsoStyle" > < a href = "3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm" > < a href = "/html/3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm#Integer_Special_Functions" > Integer Special Functions< / a > < / a > < / div > < div class = "seeAlsoStyle" > < a href = "3af6b34c-3242-2b75-e7c7-ab79af8a4b0f.htm" > < a href = "https://gmplib.org/manual/Integer-Special-Functions.html#Integer-Special-Functions" > GNU MP - Integer Special Functions< / a > < / a > < / div > < / div > < / div > < / div > < div id = "pageFooter" class = "pageFooter" > < / div > < / body > < / html >