c# - BigInteger.Pow(BigInteger, BigInteger)? -
i'm trying calculate large number, requires biginteger.pow()
, need exponent biginteger
, not int
.
i.e.
biginteger.pow(biginteger)
how can achieve this?
edit: came answer. user dog helped me achieve this.
public biginteger pow(biginteger value, biginteger exponent) { biginteger originalvalue = value; while (exponent-- > 1) value = biginteger.multiply(value, originalvalue); return value; }
just aspect of general maths, doesn't make sense. that's why it's not implemented.
think of example: biginteger
number 2 , need potentiate 1024. means result 1 kb number (2^1024). imagine take int.maxvalue
: then, number consume 2 gb of memory already. using biginteger
exponent yield number beyond memory capacity!
if application requires numbers in scale, number large memory, want solution stores number , exponent separately, that's can speculate since it's not part of question.
if your issue exponent variable biginteger
, can cast int:
biginteger.pow(biginteger, (int)exponent); // exponent biginteger
Comments
Post a Comment