0

While solving a euler's problem ,I came across this..

BigInteger temp = (BigInteger)Math.Pow(99, 95); Console.WriteLine(temp.ToString());

It outputs the following number. 3848960788934848488282452569509484590776195611314554049114673132510910096787679715604422673797115451807631980373077374162416714994207463122539142978709403811688831410945323915071533162168320

But when I tried to find the power using this link it shows..

3848960788934848611927795802824596789608451156087366034658627953530148126008534258032267383768627487094610968554286692697374726725853195657679460590239636893953692985541958490801973870359499

The two values are different. My question is there a limit on finding powers using Math functions or Is the conversion from double to BignInteger is wrong?

Chris Degnen
  • 8,443
  • 2
  • 23
  • 40
Naren
  • 2,231
  • 1
  • 25
  • 45

1 Answers1

3

You must use BigInteger.Pow, not Math.Pow.

With Math.Pow, the returned value is a double-precision floating point type whose precision is equivalent to roughly 15-17 significant decimal figures. Therefore only the first 15-17 figures will be correct.

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181