Powershell bigint output differ from declared valueHow to output something in PowerShellWhat is the difference in the way I launch powershell console?Powershell outputting an executable into a text filePowershell outputPassing connection variables from xml to powershellCan I override a Powershell native cmdlet but call it from my overrideWhy is the PowerShell prompt different when opened from a directory?How to run a batch command with parameters from PowerShellNo stdout/stdin when calling python script from powershellWhat's different between “$myvariable =” and Set-Variable in PowerShell?
Does Ubuntu reduce battery life?
Did Vladimir Lenin have a cat?
Raindrops in Python
What are these bugs on my milkweed?
Just how much information should you share with a former client?
Rampant sharing of authorship among colleagues in the name of "collaboration". Is not taking part in it a death knell for a future in academia?
Why did some Apollo missions carry a grenade launcher?
Move arrows along a contour
How do you deal with characters with multiple races?
Patio gate not at right angle to the house
Reading electrical clamp tester higher voltage/amp 400A
How close to the Sun would you have to be to hear it?
"DDoouubbllee ssppeeaakk!!"
How does multimeter AC measurement work?
Would it take any sort of amendment to make DC a state?
On the sensitivity conjecture?
Correct word for a little toy that always stands up?
When encrypting twice with two separate keys, can a single key decrypt both steps?
What is this kind of symbol meant to be?
Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?
Unknown indication below upper stave
Why would an invisible personal shield be necessary?
What language is Raven using for her attack in the new 52?
Would people understand me speaking German all over Europe?
Powershell bigint output differ from declared value
How to output something in PowerShellWhat is the difference in the way I launch powershell console?Powershell outputting an executable into a text filePowershell outputPassing connection variables from xml to powershellCan I override a Powershell native cmdlet but call it from my overrideWhy is the PowerShell prompt different when opened from a directory?How to run a batch command with parameters from PowerShellNo stdout/stdin when calling python script from powershellWhat's different between “$myvariable =” and Set-Variable in PowerShell?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm porting lesspass password manager to powershell, but I'm having trouble when implementing the _consume_entropy() method, especially the Python divmod
.
Reproduce
PS> [bigint]$EntropyAsInt = 99600400399777174105034830393873797761817714609490038944205586760025858632478
PS> Write-Host $EntropyAsInt
99600400399777173995117538344184441997741701018199539534149245151907290284032
Difference
99600400399777174105034830393873797761817714609490038944205586760025858632478
99600400399777173995117538344184441997741701018199539534149245151907290284032
^ start diverging he
Question
What's the matter here? Am I using the wrong type?
powershell .net-core biginteger powershell-v6.0
add a comment |
I'm porting lesspass password manager to powershell, but I'm having trouble when implementing the _consume_entropy() method, especially the Python divmod
.
Reproduce
PS> [bigint]$EntropyAsInt = 99600400399777174105034830393873797761817714609490038944205586760025858632478
PS> Write-Host $EntropyAsInt
99600400399777173995117538344184441997741701018199539534149245151907290284032
Difference
99600400399777174105034830393873797761817714609490038944205586760025858632478
99600400399777173995117538344184441997741701018199539534149245151907290284032
^ start diverging he
Question
What's the matter here? Am I using the wrong type?
powershell .net-core biginteger powershell-v6.0
add a comment |
I'm porting lesspass password manager to powershell, but I'm having trouble when implementing the _consume_entropy() method, especially the Python divmod
.
Reproduce
PS> [bigint]$EntropyAsInt = 99600400399777174105034830393873797761817714609490038944205586760025858632478
PS> Write-Host $EntropyAsInt
99600400399777173995117538344184441997741701018199539534149245151907290284032
Difference
99600400399777174105034830393873797761817714609490038944205586760025858632478
99600400399777173995117538344184441997741701018199539534149245151907290284032
^ start diverging he
Question
What's the matter here? Am I using the wrong type?
powershell .net-core biginteger powershell-v6.0
I'm porting lesspass password manager to powershell, but I'm having trouble when implementing the _consume_entropy() method, especially the Python divmod
.
Reproduce
PS> [bigint]$EntropyAsInt = 99600400399777174105034830393873797761817714609490038944205586760025858632478
PS> Write-Host $EntropyAsInt
99600400399777173995117538344184441997741701018199539534149245151907290284032
Difference
99600400399777174105034830393873797761817714609490038944205586760025858632478
99600400399777173995117538344184441997741701018199539534149245151907290284032
^ start diverging he
Question
What's the matter here? Am I using the wrong type?
powershell .net-core biginteger powershell-v6.0
powershell .net-core biginteger powershell-v6.0
asked Mar 26 at 21:20
Édouard LopezÉdouard Lopez
20.4k14 gold badges82 silver badges137 bronze badges
20.4k14 gold badges82 silver badges137 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
99600400399777174105034830393873797761817714609490038944205586760025858632478
is a [Double]
...
PS> 99600400399777174105034830393873797761817714609490038944205586760025858632478
9.96004003997772E+76
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).ToString("F0")
99600400399777200000000000000000000000000000000000000000000000000000000000000
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
By the time it gets cast to [BigInt]
the original value is already lost. Starting with a [String]
preserves it, though...
PS> [bigint]$EntropyAsInt = '99600400399777174105034830393873797761817714609490038944205586760025858632478'
PS> $EntropyAsInt
99600400399777174105034830393873797761817714609490038944205586760025858632478
See Instantiating a BigInteger Object for more information.
add a comment |
I can replicate the behavior, but cannot explain it. What I can do is offer you a work around. Define a variable as a [bigint]
, then parse your number as a string referencing the previously created variable.
[bigint]$EntropyAsInt=0
[bigint]::TryParse('99600400399777174105034830393873797761817714609490038944205586760025858632478',[ref]$EntropyAsInt)
You can then verify that $EntropyAsInt
contains the number you previously specified.
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
add a comment |
Thanks to 🌸Joel🌸 on Powershell slack:
The issue is that the bigint cast doesn't take effect until after the value is parsed. It will first be parsed as a double, which in where the imprecision occurs
If you want it to retain the exact number, you need to put your literal in quotes to make it a string and have the cast itself do the parsing
[bigint]$var = "12345342827266162738883736363"
Work fine
[bigint]$EntropyAsInt = "99600400399777174105034830393873797761817714609490038944205586760025858632478"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366362%2fpowershell-bigint-output-differ-from-declared-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
99600400399777174105034830393873797761817714609490038944205586760025858632478
is a [Double]
...
PS> 99600400399777174105034830393873797761817714609490038944205586760025858632478
9.96004003997772E+76
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).ToString("F0")
99600400399777200000000000000000000000000000000000000000000000000000000000000
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
By the time it gets cast to [BigInt]
the original value is already lost. Starting with a [String]
preserves it, though...
PS> [bigint]$EntropyAsInt = '99600400399777174105034830393873797761817714609490038944205586760025858632478'
PS> $EntropyAsInt
99600400399777174105034830393873797761817714609490038944205586760025858632478
See Instantiating a BigInteger Object for more information.
add a comment |
99600400399777174105034830393873797761817714609490038944205586760025858632478
is a [Double]
...
PS> 99600400399777174105034830393873797761817714609490038944205586760025858632478
9.96004003997772E+76
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).ToString("F0")
99600400399777200000000000000000000000000000000000000000000000000000000000000
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
By the time it gets cast to [BigInt]
the original value is already lost. Starting with a [String]
preserves it, though...
PS> [bigint]$EntropyAsInt = '99600400399777174105034830393873797761817714609490038944205586760025858632478'
PS> $EntropyAsInt
99600400399777174105034830393873797761817714609490038944205586760025858632478
See Instantiating a BigInteger Object for more information.
add a comment |
99600400399777174105034830393873797761817714609490038944205586760025858632478
is a [Double]
...
PS> 99600400399777174105034830393873797761817714609490038944205586760025858632478
9.96004003997772E+76
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).ToString("F0")
99600400399777200000000000000000000000000000000000000000000000000000000000000
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
By the time it gets cast to [BigInt]
the original value is already lost. Starting with a [String]
preserves it, though...
PS> [bigint]$EntropyAsInt = '99600400399777174105034830393873797761817714609490038944205586760025858632478'
PS> $EntropyAsInt
99600400399777174105034830393873797761817714609490038944205586760025858632478
See Instantiating a BigInteger Object for more information.
99600400399777174105034830393873797761817714609490038944205586760025858632478
is a [Double]
...
PS> 99600400399777174105034830393873797761817714609490038944205586760025858632478
9.96004003997772E+76
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).ToString("F0")
99600400399777200000000000000000000000000000000000000000000000000000000000000
PS> (99600400399777174105034830393873797761817714609490038944205586760025858632478).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
By the time it gets cast to [BigInt]
the original value is already lost. Starting with a [String]
preserves it, though...
PS> [bigint]$EntropyAsInt = '99600400399777174105034830393873797761817714609490038944205586760025858632478'
PS> $EntropyAsInt
99600400399777174105034830393873797761817714609490038944205586760025858632478
See Instantiating a BigInteger Object for more information.
edited Mar 26 at 21:48
answered Mar 26 at 21:42
BACONBACON
8,9355 gold badges28 silver badges52 bronze badges
8,9355 gold badges28 silver badges52 bronze badges
add a comment |
add a comment |
I can replicate the behavior, but cannot explain it. What I can do is offer you a work around. Define a variable as a [bigint]
, then parse your number as a string referencing the previously created variable.
[bigint]$EntropyAsInt=0
[bigint]::TryParse('99600400399777174105034830393873797761817714609490038944205586760025858632478',[ref]$EntropyAsInt)
You can then verify that $EntropyAsInt
contains the number you previously specified.
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
add a comment |
I can replicate the behavior, but cannot explain it. What I can do is offer you a work around. Define a variable as a [bigint]
, then parse your number as a string referencing the previously created variable.
[bigint]$EntropyAsInt=0
[bigint]::TryParse('99600400399777174105034830393873797761817714609490038944205586760025858632478',[ref]$EntropyAsInt)
You can then verify that $EntropyAsInt
contains the number you previously specified.
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
add a comment |
I can replicate the behavior, but cannot explain it. What I can do is offer you a work around. Define a variable as a [bigint]
, then parse your number as a string referencing the previously created variable.
[bigint]$EntropyAsInt=0
[bigint]::TryParse('99600400399777174105034830393873797761817714609490038944205586760025858632478',[ref]$EntropyAsInt)
You can then verify that $EntropyAsInt
contains the number you previously specified.
I can replicate the behavior, but cannot explain it. What I can do is offer you a work around. Define a variable as a [bigint]
, then parse your number as a string referencing the previously created variable.
[bigint]$EntropyAsInt=0
[bigint]::TryParse('99600400399777174105034830393873797761817714609490038944205586760025858632478',[ref]$EntropyAsInt)
You can then verify that $EntropyAsInt
contains the number you previously specified.
answered Mar 26 at 21:38
TheMadTechnicianTheMadTechnician
27k2 gold badges21 silver badges33 bronze badges
27k2 gold badges21 silver badges33 bronze badges
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
add a comment |
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
sees the answer I got on slack
– Édouard Lopez
Mar 26 at 21:41
add a comment |
Thanks to 🌸Joel🌸 on Powershell slack:
The issue is that the bigint cast doesn't take effect until after the value is parsed. It will first be parsed as a double, which in where the imprecision occurs
If you want it to retain the exact number, you need to put your literal in quotes to make it a string and have the cast itself do the parsing
[bigint]$var = "12345342827266162738883736363"
Work fine
[bigint]$EntropyAsInt = "99600400399777174105034830393873797761817714609490038944205586760025858632478"
add a comment |
Thanks to 🌸Joel🌸 on Powershell slack:
The issue is that the bigint cast doesn't take effect until after the value is parsed. It will first be parsed as a double, which in where the imprecision occurs
If you want it to retain the exact number, you need to put your literal in quotes to make it a string and have the cast itself do the parsing
[bigint]$var = "12345342827266162738883736363"
Work fine
[bigint]$EntropyAsInt = "99600400399777174105034830393873797761817714609490038944205586760025858632478"
add a comment |
Thanks to 🌸Joel🌸 on Powershell slack:
The issue is that the bigint cast doesn't take effect until after the value is parsed. It will first be parsed as a double, which in where the imprecision occurs
If you want it to retain the exact number, you need to put your literal in quotes to make it a string and have the cast itself do the parsing
[bigint]$var = "12345342827266162738883736363"
Work fine
[bigint]$EntropyAsInt = "99600400399777174105034830393873797761817714609490038944205586760025858632478"
Thanks to 🌸Joel🌸 on Powershell slack:
The issue is that the bigint cast doesn't take effect until after the value is parsed. It will first be parsed as a double, which in where the imprecision occurs
If you want it to retain the exact number, you need to put your literal in quotes to make it a string and have the cast itself do the parsing
[bigint]$var = "12345342827266162738883736363"
Work fine
[bigint]$EntropyAsInt = "99600400399777174105034830393873797761817714609490038944205586760025858632478"
answered Mar 26 at 21:40
Édouard LopezÉdouard Lopez
20.4k14 gold badges82 silver badges137 bronze badges
20.4k14 gold badges82 silver badges137 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366362%2fpowershell-bigint-output-differ-from-declared-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown