((lat2-lat1)*BETA*(lat2-lat1)*BETA + (long2-long1)*delta*(long2-long1)*delta)
I'm writing some C code and I am getting some screwy results. Basically lat1, lat2, long1, long2 are all latitudes and longitudes in radians, delta is another precalculated parameter. BETA is a defined constant.
As far as I can tell this code always results in an answer equal to BETA regardless of changing inputs. Additionally when I brake out the two addition terms: (lat2-lat1)*BETA*(lat2-lat1)*BETA and (long2-long1)*delta*(long2-long1)*delta), and compute them separately I get a result of "0". I have been trying to wrap my head around what is wrong without success for a day now. Any suggestions for things to try would be appreciated.
Thanks in advance.
Without knowing the exact differences in mehods between the two compilers I can't say for sure.
You can't really know "the methods" as such. What you can know is what code the compilers actually generated for this task. It will take quite some guessing of what vendor library function does what, and possibly you'll have to decode intermediate results into human-readable numbers. In the end you'll probably know more than you ever really wanted to, but it can be done.
The real question then is how can I force the compiler to execute each operation in an order that minimizes the relative differences?
Break up the computation into individual steps. Simplify it (computing stuff twice is wasteful). Turn down optimization, optionally by using "volatile" qualifiers. Print out intermediate results for inspection.