Problem Working With Double Numbers in C

Hi,

For some reason I am having trouble manipulating large double numbers in C. For example, with the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <math.h>

int main(){
	double x;

	x = pow(2,100);
	printf("%lf\n",x);

	x = x + 111111111111.00;
	printf("%lf\n",x);

	return 0;
}


The output is:

1267650600228229401496703205376.000000
1267650600228229401496703205376.000000

Which means "x" is not changing at all. The same problem happens when I try to divide "x" by 10. The division will be performed (and one digit will be removed), but the number itself will change.

Does anyone know what I am doing wrong?

Thanks




Floating point numbers have limited precision. See here:
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.16
and here:
http://en.wikipedia.org/wiki/IEEE_754-2008
Topic archived. No new replies allowed.