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;








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?










share|improve this question






























    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?










    share|improve this question


























      0












      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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

























          3 Answers
          3






          active

          oldest

          votes


















          1














          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.






          share|improve this answer


































            0














            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.






            share|improve this answer

























            • sees the answer I got on slack

              – Édouard Lopez
              Mar 26 at 21:41


















            0














            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"





            share|improve this answer



























              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
              );



              );













              draft saved

              draft discarded


















              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









              1














              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.






              share|improve this answer































                1














                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.






                share|improve this answer





























                  1












                  1








                  1







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  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


























                      0














                      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.






                      share|improve this answer

























                      • sees the answer I got on slack

                        – Édouard Lopez
                        Mar 26 at 21:41















                      0














                      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.






                      share|improve this answer

























                      • sees the answer I got on slack

                        – Édouard Lopez
                        Mar 26 at 21:41













                      0












                      0








                      0







                      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.






                      share|improve this answer













                      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.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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

















                      • 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











                      0














                      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"





                      share|improve this answer





























                        0














                        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"





                        share|improve this answer



























                          0












                          0








                          0







                          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"





                          share|improve this answer













                          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"






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          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






























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript