Last day I was working on a formula to calculate the bearing(and finally direction from point 1 to point 2). I was using the formula described here. I was running same formula in java as well as DB2. But getting different result. After much analysis I found the problem with the atan2 API in DB2 and Java.
Java API accept y and x as first and second argument where as DB2 API accepts in reverse order. I also found that java script also accept y argument first. This is quite bad. I don’t know which one is right but everyone should follow same pattern. This difference in API was the source of the bug.
During this analysis I also found that Db2 client(squirrel) was not returning the precise value where as Db2 client was returning.