Math.Pow
-
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
-
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
Math.Pow(9,18)
is 9^18, not 9*10^18. if you have the general case of: A*B^P then you wantA * Math.Pow(B, P)
-
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
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)
-
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
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
-
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
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