At 11:05 AM 11/11/2002 -0600, you wrote:
Indeed, if lon1_deg and lon2_deg are floats instead of doubles, that could easily account for this discrepancy, particularly if they're large compared to the difference between them.At 16:37 2002-11-11 +0000, you wrote:First, be sure to declare your factors as double values; than ensures that all math will be done using floating point.Hi,In my PDA application, I am supposed to find the distance b/n lat and lon co-ordinates. While debugging the function which does the above job, I noticed that trignometric functions like tan()(I haven't tried other functions since I was stuck here) gives me different values when using CW compiler than from the standard calculator. I am using MathLib library for trignometric functions. Part of my code where I am getting different values is enclosed below. //All variables are of type double. long_diff = fabs(lon1_deg - lon2_deg)/2.0; //Absolute value cot1 = 1/(tan((long_diff)/90 * pi/2)); //cot1 value when I compile thro CW - 1206.226660616226 with long_diff value 0.04749999999999943 //Calculator gives me 69111.712627 which is correct b'cos I get the correct distance using this value. Does anybody have any clue on this behaviour.
Second, try adding parenthesis to better group your expressions. You may be misunderstanding C's precedence rules.The way these expressions are written is a bit odd, but they're perfectly correct. The way one usually sees that last computation written is
Third, try dividing up your expression into subexpressions, then step through your code with the debugger and see how each step of the equation is computed. It will probably help you reform your expression in a way that more clearly expresses what you want to do, and gives you the expected result.
cot1 = 1 / tan(long_diff * pi / 180);
--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
