Question

I have the following code:

double e = 36858.767828375385;
double c = 2;
double d = 67.877433500000009;

e = sqrt(e / (c * (c - 1))) / d;

The resulting value of e is 2, according to the debugger, but it should be 2.8284271. What am I doing wrong?

Was it helpful?

Solution

The reason e takes the value 2 is because that's the actual answer:

sqrt(e / (c * (c-1))) / d;

= sqrt(e / (2 * (2 - 1))) / d

= sqrt(e / 2) / d

= sqrt(36858.767828375385 / 2) / d

= sqrt(18429.383914188) / d

= 135.754867 / d

= 135.754867 / 67.877433500000009

= 2

Perhaps you have the wrong formula?

Hope this helps!

OTHER TIPS

Sample code:

c = 2;
c = c * (c - 1);

Evaluation will be 2 * (2 - 1) => 2 CORRECT (Actual result of 2);

It will not be 1 * (2 - 1) => 1 WRONG (your expectation of 2.8284271);

This is what your confusion, I guess.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top