-2

Consider the following code:

#include <math.h>
#include <stdio.h>
int main()
{
    printf("%f\n", pow(43,10));
}

This outputs: 21611482313284248.000000

See http://codepad.org/eSa4ASF2 for playground.

But if I run the operation with Windows Calculator (x^y function) I get this result: 21611482313284249

What's happening??

ABCplus
  • 3,981
  • 3
  • 27
  • 43

2 Answers2

4

In IEEE-754, double (binary-64) can represent all integers exactly up to 9007199254740992 (that is 2 power 53). After that not all integer numbers can be represented exactly in a double. Your number 21611482313284249 is greater than 9007199254740992 and cannot be represented exactly in a double.

ouah
  • 142,963
  • 15
  • 272
  • 331
3

The result is so large, the significand of a double-precision float does not contain enough precision to represent every integer.

kusma
  • 6,516
  • 2
  • 22
  • 26