Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Math.Pow

Math.Pow

Scheduled Pinned Locked Moved C#
tutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    computerpublic
    wrote on last edited by
    #1

    Hello, I am trying to code the expression 9*10^18 which evaluates to 9000000000000000000. I am using a 64 bit machine, so I am within limits. Math.Pow only allows for Math.Pow(9,18) and that gives me the wrong number. Can someone please show me how to implement the whole expression using the Math.Pow. Thank You. New Guy

    M B 3 Replies Last reply
    0
    • C computerpublic

      Hello, I am trying to code the expression 9*10^18 which evaluates to 9000000000000000000. I am using a 64 bit machine, so I am within limits. Math.Pow only allows for Math.Pow(9,18) and that gives me the wrong number. Can someone please show me how to implement the whole expression using the Math.Pow. Thank You. New Guy

      M Offline
      M Offline
      Matt T Heffron
      wrote on last edited by
      #2

      Math.Pow(9,18) is 9^18, not 9*10^18. if you have the general case of: A*B^P then you want A * Math.Pow(B, P)

      1 Reply Last reply
      0
      • C computerpublic

        Hello, I am trying to code the expression 9*10^18 which evaluates to 9000000000000000000. I am using a 64 bit machine, so I am within limits. Math.Pow only allows for Math.Pow(9,18) and that gives me the wrong number. Can someone please show me how to implement the whole expression using the Math.Pow. Thank You. New Guy

        M Offline
        M Offline
        Matt T Heffron
        wrote on last edited by
        #3

        In addition to my answer above, if you really just have constants of the form A*10^P (e.g., 9*10^18) then the compiler is totally fine with exponential notation: AeP (e.g., 9e18)

        1 Reply Last reply
        0
        • C computerpublic

          Hello, I am trying to code the expression 9*10^18 which evaluates to 9000000000000000000. I am using a 64 bit machine, so I am within limits. Math.Pow only allows for Math.Pow(9,18) and that gives me the wrong number. Can someone please show me how to implement the whole expression using the Math.Pow. Thank You. New Guy

          B Offline
          B Offline
          BillWoodruff
          wrote on last edited by
          #4

          If you really want #90 raised to the 18th. power, you are going to need to use a "big integer:" 1. assuming you are using .NET >= 4.0 2. add a reference to your project to the System.Numerics library.

          using System.Numerics;

          public BigInteger ToBigPower(BigInteger value, int power)
          {
          return BigInteger.Pow(value, power);
          }

          // sample use in a method
          BigInteger x = ToBigPower(9*10, 18);

          If you inspect the value of 'x above in the Command window of Visual Studio: > ? x {150094635296999121000000000000000000} IsEven: true IsOne: false IsPowerOfTwo: false IsZero: false Sign: 1 If you are using .NET < 4.0, see this for links to alternate strategies: [^]

          “Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments.” Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940

          Richard DeemingR 1 Reply Last reply
          0
          • B BillWoodruff

            If you really want #90 raised to the 18th. power, you are going to need to use a "big integer:" 1. assuming you are using .NET >= 4.0 2. add a reference to your project to the System.Numerics library.

            using System.Numerics;

            public BigInteger ToBigPower(BigInteger value, int power)
            {
            return BigInteger.Pow(value, power);
            }

            // sample use in a method
            BigInteger x = ToBigPower(9*10, 18);

            If you inspect the value of 'x above in the Command window of Visual Studio: > ? x {150094635296999121000000000000000000} IsEven: true IsOne: false IsPowerOfTwo: false IsZero: false Sign: 1 If you are using .NET < 4.0, see this for links to alternate strategies: [^]

            “Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments.” Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            BillWoodruff wrote:

            If you really want #90 raised to the 18th. power,

            I think he wants 9 × (1018), not (9 × 10)18.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups