From: Dave H. <ha...@dp...> - 2003-10-31 15:40:39
|
On Thu, Oct 30, 2003 at 08:27:36AM -0600, Nate Bargmann wrote: > Happy Halloween! > > I hope this is not too spooky! ;-) > > I've worked on the "zero bug" in locator.c sometime back and thought I > had found an elegant solution by using type float for the degrees > variable in the dms2dec() and dec2dms() functions. After more research > it appears this "fix" may not be portable beyond a GNU C or C99 based > system. > > So I am left with one alternative for a portable solution--that being > adding a flag to the affected functions. This adds complexity to the > API as conversion is not as automatic. I also propose simplifying the > types of the variables back to type int except for seconds which should > be at least of type float. I hate bouncing the API all the time, but > this is CVS and I have no plans to change things after this. This > should allow applications using these functions to have minimal > re-writes from 1.1.4 to 1.1.5. > > Here are the new function declarations: > > double dms2dec(int degrees, int minutes, float seconds, int sw); > > int dec2dms(double dec, int *degrees, int *minutes, float *seconds, > int *sw); > > double dmmm2dec(int degrees, double minutes, int sw); > > int dec2dmmm(double dec, int *degrees, double *minutes, int *sw); > > In each case the sw variable stands for "south west". In the dms/dmm2dec > functions, if it holds a value of 1 then the returned decimal value will > be negative (-0.000000000000001 should be usable ;-). For north and > east values sw should be 0. > > In the dec2* functions, if the passed decimal angle is negative then sw > will be set to 1 and if the passed decimal angle is positive then sw > will be set to 0. > > Comments? > > 73, de Nate >> This sounds pretty good, though I'd like to make some minor suggestions... You have not mentioned whether any of the degrees, minutes or seconds values returned by dec2dms will ever be negative, or is they will always be positive even when the sw flag is set. I think this should be explicitly documented. I'd prefer to see all floating values as doubles, for two reasons: 1) It's easier to remember when using the routines, I see that dec2dms() has both float & double arguments - more to remember. Using doubles would also be consistent with the C math library which used doubles for just about everything. 2) Older (pre-ansi) C compilers, & current ansi compilers when function prototypes are not given, use doubles to pass floating values. Thus using doubles is compatible with older pre-ansi C compilers, & will also allow programmes to work if the header files containing the prototypes have not been correctly included. Cheers -- Dave. |