A
almurph
Hi,
can you help me with the following anomaly please? I'm really at my
wits end. I need the help of some C people like you.
I am debugging some pre-99 C code. I have a logical contradiction as
follows (btw the printf stuff is my diagnostics):
float Sum=0.0;
float N
printf("Sum before: %.15f\n", Sum);
Sum += N * Log(N); <--- this is the original line of code
printf("N: %.15f\n", N);
printf("Log(N): %.15f\n", Log(N));
printf("Product of N and Log(N): %.15f\n", N * Log(N));
printf("Sum: %.15f\n", Sum)
The results are as follows:
Sum Before: 0.000000000000000
N: 4322.00000000000000
Log(N): 12.077483366859508
Product of N and Log(N): 52198.883068346796790
Sum: 52198.882812500000000
what confuses me is the value of Sum.
When I multiply N and Log(N) by hand calculator I get:
4322 * 12.077483366859508 = 52198.883068346793576
but this value does not tally with the valaue of Sum which starts to
differ in the 3rd decimal place i.e.
52198.882812500000000
^
starts to differ here for some reason.
For the life of me I do not understand why this is occuring? That is,
why the apparent contradiction between the RHS and the LHS of the
simple line of code:
Sum += N * Log(N);
it can't be the "+=" operator can it? I've heard about round-off
error but this just stumps me. Can anyone please help me. Would
greatly appreciate any comments/code-sampels/explanations/suggestions/
insight that you may be able to offer.
Thanking you,
Al.
The confused!
PS: Don't worry about Log(N) - just is just a macro and gets the
value: log(N) / log(2)
can you help me with the following anomaly please? I'm really at my
wits end. I need the help of some C people like you.
I am debugging some pre-99 C code. I have a logical contradiction as
follows (btw the printf stuff is my diagnostics):
float Sum=0.0;
float N
printf("Sum before: %.15f\n", Sum);
Sum += N * Log(N); <--- this is the original line of code
printf("N: %.15f\n", N);
printf("Log(N): %.15f\n", Log(N));
printf("Product of N and Log(N): %.15f\n", N * Log(N));
printf("Sum: %.15f\n", Sum)
The results are as follows:
Sum Before: 0.000000000000000
N: 4322.00000000000000
Log(N): 12.077483366859508
Product of N and Log(N): 52198.883068346796790
Sum: 52198.882812500000000
what confuses me is the value of Sum.
When I multiply N and Log(N) by hand calculator I get:
4322 * 12.077483366859508 = 52198.883068346793576
but this value does not tally with the valaue of Sum which starts to
differ in the 3rd decimal place i.e.
52198.882812500000000
^
starts to differ here for some reason.
For the life of me I do not understand why this is occuring? That is,
why the apparent contradiction between the RHS and the LHS of the
simple line of code:
Sum += N * Log(N);
it can't be the "+=" operator can it? I've heard about round-off
error but this just stumps me. Can anyone please help me. Would
greatly appreciate any comments/code-sampels/explanations/suggestions/
insight that you may be able to offer.
Thanking you,
Al.
The confused!
PS: Don't worry about Log(N) - just is just a macro and gets the
value: log(N) / log(2)