question

HighSky46-0681 avatar image
0 Votes"
HighSky46-0681 asked HighSky46-0681 answered

I would like to know how to execute the Pow method with two BigInteger types in C#.

First of all, I used a translator because I am not good at English, so I would appreciate it if you could understand that English can be weird.
It's a question.
I'm making a game out of Unity, and the type of money in the game is made out of Big Integer.
However, since only the value of the BigInteger's Power method is set to BigInteger and the component is set to Int32, OverFlow occurred during implementation.
Can you tell me how to solve this problem?

dotnet-csharp
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Why do you need such large exponents?


0 Votes 0 ·

Because the concept of the game is to have a lot of money.

0 Votes 0 ·

I would like to use Python if it is impossible to solve with C#, but I would like to use C# if possible.

0 Votes 0 ·

1 Answer

HighSky46-0681 avatar image
0 Votes"
HighSky46-0681 answered

I solved it like this.
I don't know if this solution is efficient.


public static BigInteger Pow(BigInteger Base, BigInteger exp)
{
BigInteger Result = BigInteger.One;
while(exp > 0)
{
if(!exp.IsEven)
{
Result = BigInteger.Multiply(Result, Base);
}
Base *= Base;
exp /= 2;
}
return Result;
}








5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.