Spam (madbodger) wrote,
Spam
madbodger

  • Mood:
  • Music:

Geekiness

I'm writing a data normalizer, and among its other functions, it converts latitudes and longitudes. I realized it should accept these in decimal or degrees, minutes, and seconds. Then I had to convert the latter to decimal. No problem, just divide minutes by 60 and seconds by 3600 and add. Well, not really. If you had input like "-77 18 41.64", the minutes and seconds are implicitly negative (like the degrees). No problem, I modified the code to make the minutes and seconds the same sign as the degrees.

But this wasn't quite correct either! What if I get some input like "-0 54 12.047"? After converting the degrees, I get zero, not negative zero. So I had to add even more code to check the original unconverted string to see if I had to change the sign. Not too hard in concept, but since the code already supported both numeric forms, and directions either prefix or postfix ("N 54 19 17.554 W 77 32 8.333" as well as "54 19 17.554N77 32 8.333W"), it took a little finagling to get everything right.

I should have just used yacc.

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 13 comments